From 84a90cefaa90257792ca948ffba39822f230fc60 Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Fri, 1 Nov 2024 22:25:15 +0100 Subject: [PATCH] Updated copyright info, added separators and missing exports --- conf/pcp-e3s.conf.sh | 46 ++++++++++++++++++++++++++++ lib/aaa_errors.sh | 14 ++++++++- lib/chroot.sh | 4 ++- lib/command_line.sh | 4 ++- lib/diskman.sh | 12 +++++++- lib/display.sh | 5 ++- lib/filefct.sh | 14 ++++++++- lib/loaders.sh | 5 ++- lib/net.sh | 11 ++++++- lib/pkgman.sh | 14 ++++++++- lib/services.sh | 7 ++++- lib/support.sh | 4 ++- lib/users.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++ lib/utils.sh | 8 ++++- lib/version.sh | 4 ++- 15 files changed, 211 insertions(+), 13 deletions(-) create mode 100644 conf/pcp-e3s.conf.sh create mode 100644 lib/users.sh diff --git a/conf/pcp-e3s.conf.sh b/conf/pcp-e3s.conf.sh new file mode 100644 index 0000000..26b8d63 --- /dev/null +++ b/conf/pcp-e3s.conf.sh @@ -0,0 +1,46 @@ +# Fichier de configuration principal + +# ------------------------------------------------------------------------------ +# -------------------- Importation de paramêtres globaux ----------------------- +# ------------------------------------------------------------------------------ + +# Importe les paramètres pour le lan E-3S +. $MYPATH/conf/includes/e3s.conf.sh + +# Importe la sélection de paquets par défaut +. $MYPATH/conf/includes/pkgsel.base.conf.sh + +# Les paramètres précédemment importés sont surchargeable après cette ligne + +# ------------------------------------------------------------------------------ +# ------------------------------ General Section ------------------------------- +# ------------------------------------------------------------------------------ + +# User of the machine (must exists) +MAINUSER=root + +# Authentication: use LDAP+Kerberos ? +WITH_LDAP_KERB=no + +# Network +IPV4_IFACES="ens192" + +NET4_MODE_ens192="dhcp" + +IPV6_IFACES="" + +# Mode d'installation : +# * dev : installe les paquets un par un avec apt (lent) +# * full : envoie d'un seul coup la liste de tous les paquets à apt (rapide) +INTALL_MODE=full + +# Paquets additionnels +PKGSEL="$PKGSEL" + +# ------------------------------------------------------------------------------ +# -------------------------- Section modules d'init ---------------------------- +# ------------------------------------------------------------------------------ + +# Liste des modules à executer (surchargeable en ligne de commande) +MODULE_LIST="conf_ntp upgrade_dist conf_locale conf_ssh \ + install_pkg install_profile" diff --git a/lib/aaa_errors.sh b/lib/aaa_errors.sh index c11aeb2..1f6b572 100644 --- a/lib/aaa_errors.sh +++ b/lib/aaa_errors.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Error management functions # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -33,6 +33,7 @@ function die() trap 'error ${LINENO}' ERR } export -f die +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -42,8 +43,10 @@ function terminate() prnt E "$1 recieved, exiting at once." die 128 --force } +export -f terminate trap "terminate 'Ctrl + C'" SIGINT trap "terminate 'SIGTERM'" SIGTERM +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -65,8 +68,10 @@ function error() fi unset parent_lineno message code } +export -f error # Trigger error function on error trap "error ${LINENO}; backtrace; err_exit" ERR +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -80,6 +85,8 @@ function err_exit exit 255 fi } +export -f err_exit +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -100,6 +107,9 @@ function backtrace unset func i echo "==============================" } +export -f backtrace +# ------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------ @@ -125,6 +135,7 @@ noerror() set -o errexit } export -f noerror +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -140,5 +151,6 @@ check_root() fi } export -f check_root +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/chroot.sh b/lib/chroot.sh index 681b267..9068ae0 100644 --- a/lib/chroot.sh +++ b/lib/chroot.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Chroot system functions # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -45,5 +45,7 @@ chroot_bootstrap() prnt I "Back to host system and clean up." rm -rf "$tmpdir" } +export -f chroot_bootstrap +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/command_line.sh b/lib/command_line.sh index 02002d2..e69e262 100644 --- a/lib/command_line.sh +++ b/lib/command_line.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Main program functions # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -128,6 +128,7 @@ read_commandline() unset opt } export -f read_commandline +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -188,5 +189,6 @@ process_commandline_and_vars() fi } export -f process_commandline_and_vars +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/diskman.sh b/lib/diskman.sh index e3e022d..c1ee21e 100644 --- a/lib/diskman.sh +++ b/lib/diskman.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Disks and partitions manipulation function # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -35,6 +35,7 @@ blank_disk() fi } export -f blank_disk +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -58,6 +59,7 @@ is_blank() fi } export -f is_blank +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -107,6 +109,7 @@ mkparts() unset device parttype } export -f mkparts +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -122,6 +125,8 @@ mkfs_gen() fi done } +export -f mkfs_gen +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -133,6 +138,7 @@ mkext4() unset mkfstool } export -f mkext4 +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -144,6 +150,7 @@ mkxfs() unset mkfstool } export -f mkxfs +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -155,6 +162,7 @@ mkntfs() unset mkfstool } export -f mkntfs +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -166,6 +174,7 @@ mkfat32() unset mkfstool } export -f mkfat32 +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -177,6 +186,7 @@ mkbtrfs() unset mkfstool } export -f mkbtrfs +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/display.sh b/lib/display.sh index 88b4e63..e2528ca 100644 --- a/lib/display.sh +++ b/lib/display.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Some display functions and defines color codes # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -123,6 +123,7 @@ prnt() unset heads echoopt } export -f prnt +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -142,6 +143,7 @@ separator() unset i length } export -f separator +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -161,6 +163,7 @@ dsleep() echo } export -f dsleep +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/filefct.sh b/lib/filefct.sh index b12380b..4cc39df 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # File manipulation function # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -58,6 +58,7 @@ backup_dist() unset file } export -f backup_dist +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -93,6 +94,7 @@ select_file() unset source } export -f select_file +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -121,6 +123,7 @@ select_directory() unset source } export -f select_directory +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -170,6 +173,7 @@ install_file() fi } export -f install_file +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -200,6 +204,7 @@ append_file() fi } export -f append_file +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -223,6 +228,7 @@ is_dir_empty() return 1 } export -f is_dir_empty +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -268,6 +274,7 @@ patch_file() unset rights dstfile } export -f patch_file +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -285,6 +292,7 @@ tag_file() done } export -f tag_file +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -300,6 +308,7 @@ file_exists() return 0 } export -f file_exists +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -315,6 +324,7 @@ file_must_exists() unset mf } export -f file_must_exists +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -330,6 +340,7 @@ directory_exists() return 0 } export -f directory_exists +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -345,6 +356,7 @@ directory_must_exists() unset md } export -f directory_must_exists +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/loaders.sh b/lib/loaders.sh index 24d79d2..6251447 100644 --- a/lib/loaders.sh +++ b/lib/loaders.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Loaders for conf and prepost functions # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -49,6 +49,7 @@ load_autoconf() unset prefix } export -f load_autoconf +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -129,6 +130,7 @@ load_configuration() fi } export -f load_configuration +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -143,5 +145,6 @@ load_prepost_actions() unset prepost } export -f load_prepost_actions +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/net.sh b/lib/net.sh index afbe719..0fcf9af 100644 --- a/lib/net.sh +++ b/lib/net.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Network functions # This file is part of the init.sh project -# Copyright (c) 2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -34,6 +34,7 @@ set_system_proxy() fi } export -f set_system_proxy +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -47,6 +48,7 @@ mask2cidr4() echo $(( $2 + (${#x}/4) )) } export -f mask2cidr4 +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -59,6 +61,7 @@ cidr2mask4() echo ${1-0}.${2-0}.${3-0}.${4-0} } export -f cidr2mask4 +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -82,6 +85,7 @@ isipv4 () return 1 } export -f isipv4 +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -96,6 +100,7 @@ isipv6 () return 1 } export -f isipv6 +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -135,6 +140,7 @@ get_network_info() done } export -f get_network_info +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -176,3 +182,6 @@ check_network() esac } export -f check_network +# ------------------------------------------------------------------------------ + +# EOF diff --git a/lib/pkgman.sh b/lib/pkgman.sh index 72e58b6..60a0b32 100644 --- a/lib/pkgman.sh +++ b/lib/pkgman.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Package manager integration # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -18,6 +18,7 @@ pkgupdt() $PKG_MAN $COM_UPDATE } export -f pkgupdt +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -56,6 +57,7 @@ pkgupgd() exec_postupgd } export -f pkgupgd +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -82,6 +84,7 @@ pkgrm() fi } export -f pkgrm +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -94,6 +97,7 @@ pkgautorm() exec_postautorm } export -f pkgautorm +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -111,6 +115,7 @@ exec_preinst() unset pkglist } export -f exec_preinst +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -129,6 +134,7 @@ exec_postinst() unset POSTINSTLIST } export -f exec_postinst +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -147,6 +153,7 @@ exec_prerm() unset pkglist } export -f exec_prerm +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -165,6 +172,7 @@ exec_postrm() unset POSTRMLIST } export -f exec_postrm +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -182,6 +190,7 @@ exec_preupgd() unset pkglist } export -f exec_preupgd +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -200,6 +209,7 @@ exec_postupgd() unset POSTUPGDLIST } export -f exec_postupgd +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -217,6 +227,7 @@ exec_preautorm() unset pkglist } export -f exec_preautorm +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -226,6 +237,7 @@ exec_postautorm() exec_postrm } export -f exec_postautorm +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/services.sh b/lib/services.sh index 49f6800..3c7f363 100644 --- a/lib/services.sh +++ b/lib/services.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Services manipulation functions # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -34,6 +34,7 @@ exec_serv() unset lineexec } export exec_serv +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -47,6 +48,7 @@ svc_start() unset svc } export -f svc_start +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -58,6 +60,7 @@ svc_reload() done } export -f svc_reload +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -71,6 +74,7 @@ svc_restart() unset svc } export -f svc_restart +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -84,5 +88,6 @@ svc_stop() unset svc } export -f svc_stop +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/support.sh b/lib/support.sh index 3b079d3..d5f8dbb 100644 --- a/lib/support.sh +++ b/lib/support.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Base support function # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -73,6 +73,7 @@ Fichiers de configuration : EOF } export -f disp_help +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -103,5 +104,6 @@ show_version() fi } export -f show_version +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/users.sh b/lib/users.sh new file mode 100644 index 0000000..bed1c4f --- /dev/null +++ b/lib/users.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# ------------------------------------------------------------------------------ +# Users related functions +# This file is part of the init.sh project +# Copyright (c) 2019-2024 Geoffray Levasseur +# ------------------------------------------------------------------------------ +# This file is distributed under 3-clause BSD license. +# The complete license agreement can be obtained at: +# https://opensource.org/licenses/BSD-3-Clause +# ------------------------------------------------------------------------------ + + +# ------------------------------------------------------------------------------ +# Users (from Ldap) +add_remote_user() +{ + if [[ -n $(grep "^$1:" /etc/passwd) ]]; then + prnt W "A local user with name $1 already exists, adding anyway!" + fi + if [[ -n $(grep "^+$1:" /etc/passwd) ]]; then + prnt W "The remote user $1 is already declared, nothing to do in passwd." + else + echo "+$1::::::" >> /etc/passwd + prnt I "User $1 added to passwd..." + fi + if [[ -n $(grep "^+$1:" /etc/shadow) ]]; then + prnt W "The remote user $1 is already connectable, nothing to do in shadow." + else + echo "+$1::::::::" >> /etc/shadow + prnt I "User $1 added to shadow..." + fi +} +export -f add_remote_user +# ------------------------------------------------------------------------------ + + +# ------------------------------------------------------------------------------ +# Remove users +remove_user() +{ + if [[ -n $(grep "^$1:" /etc/{passwd,shadow,group,gshadow}) ]]; then + # Using sed is more universal than any distro commands - local case + sed -i -e "/^$1:/d" /etc/{passwd,shadow,group,gshadow} + elif [[ -n $(grep "^+$1:" /etc/{passwd,shadow,group,gshadow}) ]]; then + # remote case + sed -i -e "/^+$1:/d" /etc/{passwd,shadow,group,gshadow} + else + prnt W "User $1 don't exists in auth files, nothing to do." + fi +} +# ------------------------------------------------------------------------------ + + +# ------------------------------------------------------------------------------ +# Create a local user +create_local_user() +{ + if [[ $(noerror --noout id $1) != 0 ]]; then + prnt I "Creating user $1..." + if [[ $(directory_exists home_skell) ]]; then + useradd --create-home --shell $DEFAULT_SHELL --user-group $1 \ + --skell $(select_directory home_skell) + else + useradd --create-home --shell $DEFAULT_SHELL --user-group $1 + fi + else + prnt W "The user $1 already exists. Nothing to do..." + fi +} +# ------------------------------------------------------------------------------ + +# EOF diff --git a/lib/utils.sh b/lib/utils.sh index 015f8b7..3508086 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Various utilitary functions # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -16,6 +16,7 @@ stdtime() date --rfc-3339=seconds | sed -e 's/ /-/' -e 's/://g' | cut -d'+' -f1 } export -f stdtime +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -33,6 +34,7 @@ function_exists() { fi } export -f function_exists +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -46,6 +48,7 @@ get_mod_name() basename $1 | cut -f 1 -d '.' } export -f get_mod_name +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -57,6 +60,8 @@ trim() unset string } export -f trim +# ------------------------------------------------------------------------------ + # ------------------------------------------------------------------------------ # Dump the keyboard's buffer @@ -67,6 +72,7 @@ dump_key_buffer() done } export -f dump_key_buffer +# ------------------------------------------------------------------------------ # EOF diff --git a/lib/version.sh b/lib/version.sh index f8ed0f6..e0c11ad 100644 --- a/lib/version.sh +++ b/lib/version.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------------------------------ # Version determination function # This file is part of the init.sh project -# Copyright (c) 2019-2022 Geoffray Levasseur +# Copyright (c) 2019-2024 Geoffray Levasseur # ------------------------------------------------------------------------------ # This file is distributed under 3-clause BSD license. # The complete license agreement can be obtained at: @@ -45,6 +45,7 @@ get_os_version() ) } export read_os_release +# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------ @@ -67,5 +68,6 @@ set_sys_vars() fi } export -f get_os_version +# ------------------------------------------------------------------------------ # EOF