From dc53b749f168c40959f9c147b5ddee9ab77b2421 Mon Sep 17 00:00:00 2001 From: levasseur Date: Wed, 29 Sep 2021 17:29:39 +0200 Subject: [PATCH 01/13] introduced distro version detection and automatic system dependent configuration loading --- README.md | 1 + conf/{includes => auto}/debian.conf.sh | 0 conf/auto/devuan.conf.sh | 23 ++++++++ conf/auto/ubuntu.conf.sh | 23 ++++++++ conf/init.conf.sh | 3 - conf/lell213893.conf.sh | 3 - init.sh | 13 ++++- lib/version.sh | 56 +++++++++++++++++++ lib/zzz_main_fct.sh | 39 +++++++++++++ modules/upgrade_dist.sh | 4 +- .../{debian_buster.list => debian_10.list} | 0 .../{debian_bulleyes.list => debian_11.list} | 0 .../{ubuntu_focal.list => ubuntu_20.04.list} | 0 13 files changed, 155 insertions(+), 10 deletions(-) rename conf/{includes => auto}/debian.conf.sh (100%) create mode 100644 conf/auto/devuan.conf.sh create mode 100644 conf/auto/ubuntu.conf.sh create mode 100644 lib/version.sh rename repo/common/{debian_buster.list => debian_10.list} (100%) rename repo/common/{debian_bulleyes.list => debian_11.list} (100%) rename repo/common/{ubuntu_focal.list => ubuntu_20.04.list} (100%) diff --git a/README.md b/README.md index 38d1c8c..5e45504 100644 --- a/README.md +++ b/README.md @@ -229,6 +229,7 @@ The following table is giving a list of error code with explanation: | 5 | Malformed module list | | 6 | Unable to find configuration | | 7 | Misuse of script internal function | +| 8 | Can't determine OS version | | 11 | Bad function call | | 12 | Error copying files | | 13 | Bad target file system | diff --git a/conf/includes/debian.conf.sh b/conf/auto/debian.conf.sh similarity index 100% rename from conf/includes/debian.conf.sh rename to conf/auto/debian.conf.sh diff --git a/conf/auto/devuan.conf.sh b/conf/auto/devuan.conf.sh new file mode 100644 index 0000000..524b2fa --- /dev/null +++ b/conf/auto/devuan.conf.sh @@ -0,0 +1,23 @@ +# Configuration propre à Debian + +# Conf gestionnaire de paquet +export PKG_MAN="apt-get" +export COM_INSTALL="install -y" +export COM_UPDATE="update" +export COM_UPGRADE="full-upgrade -y" +export COM_REMOVE="remove --purge -y" +export COM_AUTOREM="autoremove --purge -y" + +# Special variable for apt tools to disable any interactive behaviour +export DEBIAN_FRONTEND=noninteractive + +# Conf chemin +export RC_SCRIPTS_PATH="/etc/init.d" + +# Conf init +# Init SystemV ou OpenRC: +export INIT_COM="$RC_SCRIPTS_PATH/%srv% %comm%" +# Init Systemd: +#export INIT_COM="systemctl %comm% %srv%" +# Init Upstart (plus ou moins universel) +#export INIT_COM="service %srv% %com%" diff --git a/conf/auto/ubuntu.conf.sh b/conf/auto/ubuntu.conf.sh new file mode 100644 index 0000000..e142590 --- /dev/null +++ b/conf/auto/ubuntu.conf.sh @@ -0,0 +1,23 @@ +# Configuration propre à Debian + +# Conf gestionnaire de paquet +export PKG_MAN="apt-get" +export COM_INSTALL="install -y" +export COM_UPDATE="update" +export COM_UPGRADE="full-upgrade -y" +export COM_REMOVE="remove --purge -y" +export COM_AUTOREM="autoremove --purge -y" + +# Special variable for apt tools to disable any interactive behaviour +export DEBIAN_FRONTEND=noninteractive + +# Conf chemin +export RC_SCRIPTS_PATH="/etc/init.d" + +# Conf init +# Init SystemV ou OpenRC: +#export INIT_COM="$RC_SCRIPTS_PATH/%srv% %comm%" +# Init Systemd: +#export INIT_COM="systemctl %comm% %srv%" +# Init Upstart (plus ou moins universel) +export INIT_COM="service %srv% %com%" diff --git a/conf/init.conf.sh b/conf/init.conf.sh index 887c6b0..d1da515 100644 --- a/conf/init.conf.sh +++ b/conf/init.conf.sh @@ -7,9 +7,6 @@ # Importe les paramètres spécifiques LEGOS . $MYPATH/conf/includes/legos.conf.sh -# Importe les paramètres pour Debian et Ubuntu -. $MYPATH/conf/includes/debian.conf.sh - # Importe la sélection de paquets par défaut . $MYPATH/conf/includes/pkgsel.full.conf.sh diff --git a/conf/lell213893.conf.sh b/conf/lell213893.conf.sh index 741fd89..e10df97 100644 --- a/conf/lell213893.conf.sh +++ b/conf/lell213893.conf.sh @@ -7,9 +7,6 @@ # Importe les paramètres spécifiques LEGOS . $MYPATH/conf/includes/legos-bas.conf.sh -# Importe les paramètres pour Debian et Ubuntu -. $MYPATH/conf/includes/debian.conf.sh - # Importe la sélection de paquets par défaut . $MYPATH/conf/includes/pkgsel.full.conf.sh diff --git a/init.sh b/init.sh index e6ea213..3fa34e0 100755 --- a/init.sh +++ b/init.sh @@ -44,6 +44,9 @@ export MYPATH=$(dirname $0) # Get hostname export HOSTNAME=$(hostname) +# System architecture +export SYS_ARCH=$(uname -m) + # Load libraries for lib in $MYPATH/lib/*.sh; do . $lib @@ -65,6 +68,9 @@ function_exists prnt || ( exit 3 ) +# Set system dependent vars +get_os_version $(read_os_release) + # ====================== # ==== Main Program ==== # ====================== @@ -102,9 +108,12 @@ exec > >(tee -a $LOGFILE) exec 2> >(tee -a $LOGFILE >&2) prnt I "Démarrage d'init version $VERSION." prnt I "Le fichier de log est $LOGFILE." +prnt I "Lancé sur $SYS_DIST version $SYS_VER ($SYS_CODE) architecture $SYS_ARCH" # -- Cannot be a function ends here +load_auto_conf + load_configuration process_commandline_and_vars @@ -127,7 +136,7 @@ done if [[ $RUN_SHELL == true ]]; then prnt I "Lancement d'un shell intéractif..." - bash -i --rcfile $MYPATH/bash.rc + bash --rcfile $MYPATH/bash.rc -i prnt I "Sortie du script après exécution du shell." exit 0 fi @@ -185,3 +194,5 @@ fi prnt I "That's all folks !" rm -f $STAGEFILE + +# EOF diff --git a/lib/version.sh b/lib/version.sh new file mode 100644 index 0000000..afd5c0d --- /dev/null +++ b/lib/version.sh @@ -0,0 +1,56 @@ +# ------------------------------------------------------------------------------ +# Version determination function +# This file is part of the init.sh project +# Copyright (c) 2019-2021 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 +# ------------------------------------------------------------------------------ + +# ------------------------------------------------------------------------------ +# Return on stdout $distro $version $codename +read_os_release() +{ + if [[ ! -f /etc/os-release ]]; then + prnt E "Your distribution doesn't have the needed os-release file." + die 8 --force + fi + + # Create a sub-shell to avoid polluting the environnement + ( + # Iniitalise version codename in case the var don't exists + VERSION_CODENAME="NULL" + + # Import the file in the environment + source /etc/os-release + + if [[ -z $ID || -z $VERSION_ID ]]; then + prnt E "Your /etc/os-release file mises some vital information." + die --force 8 + fi + + # Return values on standard stdout + echo ${ID,,} ${VERSION_ID} ${VERSION_CODENAME,,} + #prnt I "OS is: ${ID,,} ${VERSION_ID} ${VERSION_CODENAME,,}" + ) +} +export read_os_release + + +# ------------------------------------------------------------------------------ +# Create system related variables +# ------------------------------------------------------------------------------ +get_os_version() +{ + if [[ $# -ne 3 ]]; then + prnt E "get_os_version(): incorect number of parameters ($@)." + die 7 --force + fi + + export SYS_DIST=$1 + export SYS_VER=$2 + if [[ $3 != "null" ]]; then + export SYS_CODE=$3 + fi +} diff --git a/lib/zzz_main_fct.sh b/lib/zzz_main_fct.sh index 1936d11..7cb41de 100644 --- a/lib/zzz_main_fct.sh +++ b/lib/zzz_main_fct.sh @@ -115,6 +115,45 @@ read_commandline() export -f read_commandline +# ------------------------------------------------------------------------------ +# Automatically load system specific configuration if file exist in the +# following order: +# 1) auto/arch.conf.sh +# 2) auto/distro.conf.sh +# 3) auto/distro-arch.conf.sh +# 4) auto/distro-version.conf.sh +# 5) auto/distro-codename.conf.sh (if sys_code defined) +# 6) auto/distro-version-arch.conf.sh +# 7) auto/distro-codename-arch.conf.sh (if sys_code defined) +load_autoconf() +{ + local prefix="$MYPATH/conf/auto" + + if [[ -e $prefix/$SYS_ARCH.conf.sh ]]; then + . $prefix/$SYS_ARCH.conf.sh + fi + if [[ -e $prefix/$SYS_DIST.conf.sh ]]; then + . $prefix/$SYS_DIST.conf.sh + fi + if [[ -e $prefix/$SYS_DIST-$SYS_ARCH.conf.sh ]]; then + . $prefix/$SYS_DIST-$SYS_ARCH.conf.sh + fi + if [[ -e $prefix/$SYS_DIST-$SYS_VER.conf.sh ]]; then + . $prefix/$SYS_DIST-$SYS_VER.conf.sh + fi + if [[ -n $SYS_CODE && -e $prefix/$SYS_DIST-$SYS_CODE.conf.sh ]]; then + . $prefix/$SYS_DIST-$SYS_CODE.conf.sh + fi + if [[ -e $prefix/$SYS_DIST-$SYS_VER-$SYS_ARCH.conf.sh ]]; then + . $prefix/$SYS_DIST-$SYS_VER-$SYS_ARCH.conf.sh + fi + if [[ -n $SYS_CODE && -e $prefix/$SYS_DIST-$SYS_CODE-$SYS_ARCH.conf.sh ]]; then + . $prefix/$SYS_DIST-$SYS_CODE-$SYS_ARCH.conf.sh + fi +} +export -f load_autoconf + + # ------------------------------------------------------------------------------ # Load configuration with the following priorities: # 1) Those given on command line, if any diff --git a/modules/upgrade_dist.sh b/modules/upgrade_dist.sh index d4147bb..95977b9 100644 --- a/modules/upgrade_dist.sh +++ b/modules/upgrade_dist.sh @@ -40,9 +40,7 @@ upgrade_dist() fi # Remplace source.list from dist with ours (be smarter) - if [[ -n $APT_LIST_FILE ]]; then - installfile $APT_LIST_FILE /etc/apt/sources.list - fi + installfile "${SYS_DIST}_${SYS_VER}" /etc/apt/sources.list prnt I "Mise à jour de la liste des paquets..." pkgupdt diff --git a/repo/common/debian_buster.list b/repo/common/debian_10.list similarity index 100% rename from repo/common/debian_buster.list rename to repo/common/debian_10.list diff --git a/repo/common/debian_bulleyes.list b/repo/common/debian_11.list similarity index 100% rename from repo/common/debian_bulleyes.list rename to repo/common/debian_11.list diff --git a/repo/common/ubuntu_focal.list b/repo/common/ubuntu_20.04.list similarity index 100% rename from repo/common/ubuntu_focal.list rename to repo/common/ubuntu_20.04.list From 4ff4c155f19217cb578753cc9d60fd1cb2fbf215 Mon Sep 17 00:00:00 2001 From: levasseur Date: Wed, 29 Sep 2021 17:31:54 +0200 Subject: [PATCH 02/13] version bump --- init.sh | 2 +- modules/upgrade_dist.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/init.sh b/init.sh index 3fa34e0..ffde188 100755 --- a/init.sh +++ b/init.sh @@ -36,7 +36,7 @@ export LC_ALL=C export LANG=C # Version of init -export VERSION="0.99.7" +export VERSION="0.99.8" # Store script's path export MYPATH=$(dirname $0) diff --git a/modules/upgrade_dist.sh b/modules/upgrade_dist.sh index 95977b9..e1bbab5 100644 --- a/modules/upgrade_dist.sh +++ b/modules/upgrade_dist.sh @@ -13,7 +13,7 @@ # * PROXYAPTPORT: Working port for APT proxy # ------------------------------------------------------------------------------ -export VER_upgrade_dist="0.0.10" +export VER_upgrade_dist="0.0.11" # The following var must stay empty export DEP_upgrade_dist="" From de8b774ca49118578851934401b9810743e33cb6 Mon Sep 17 00:00:00 2001 From: levasseur Date: Wed, 29 Sep 2021 17:39:38 +0200 Subject: [PATCH 03/13] added proper haeders to distro specific files --- conf/auto/debian.conf.sh | 9 ++++++++- conf/auto/devuan.conf.sh | 11 +++++++++-- conf/auto/ubuntu.conf.sh | 9 ++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/conf/auto/debian.conf.sh b/conf/auto/debian.conf.sh index e142590..bbf4680 100644 --- a/conf/auto/debian.conf.sh +++ b/conf/auto/debian.conf.sh @@ -1,4 +1,11 @@ -# Configuration propre à Debian +# ------------------------------------------------------------------------------ +# Declaration specific to Debian GNU/Linux +# Copyright (c) 2019-2021 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 +# ------------------------------------------------------------------------------ # Conf gestionnaire de paquet export PKG_MAN="apt-get" diff --git a/conf/auto/devuan.conf.sh b/conf/auto/devuan.conf.sh index 524b2fa..ab226d7 100644 --- a/conf/auto/devuan.conf.sh +++ b/conf/auto/devuan.conf.sh @@ -1,4 +1,11 @@ -# Configuration propre à Debian +# ------------------------------------------------------------------------------ +# Declaration specific to Devuan +# Copyright (c) 2019-2021 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 +# ------------------------------------------------------------------------------ # Conf gestionnaire de paquet export PKG_MAN="apt-get" @@ -16,7 +23,7 @@ export RC_SCRIPTS_PATH="/etc/init.d" # Conf init # Init SystemV ou OpenRC: -export INIT_COM="$RC_SCRIPTS_PATH/%srv% %comm%" +export INIT_COM="$RC_SCRIPTS_PATH/%srv% %com%" # Init Systemd: #export INIT_COM="systemctl %comm% %srv%" # Init Upstart (plus ou moins universel) diff --git a/conf/auto/ubuntu.conf.sh b/conf/auto/ubuntu.conf.sh index e142590..cb31e2f 100644 --- a/conf/auto/ubuntu.conf.sh +++ b/conf/auto/ubuntu.conf.sh @@ -1,4 +1,11 @@ -# Configuration propre à Debian +# ------------------------------------------------------------------------------ +# Declaration specific to Ubuntu and derivate (eg. Kubuntu) +# Copyright (c) 2019-2021 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 +# ------------------------------------------------------------------------------ # Conf gestionnaire de paquet export PKG_MAN="apt-get" From e7a9b416e14d91c3235628c6f236054dd6822c72 Mon Sep 17 00:00:00 2001 From: levasseur Date: Wed, 29 Sep 2021 18:04:45 +0200 Subject: [PATCH 04/13] some typos --- init.sh | 2 +- modules/upgrade_dist.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/init.sh b/init.sh index ffde188..c7f3d55 100755 --- a/init.sh +++ b/init.sh @@ -112,7 +112,7 @@ prnt I "Lancé sur $SYS_DIST version $SYS_VER ($SYS_CODE) architecture $SYS_ARCH # -- Cannot be a function ends here -load_auto_conf +load_autoconf load_configuration diff --git a/modules/upgrade_dist.sh b/modules/upgrade_dist.sh index e1bbab5..91537c1 100644 --- a/modules/upgrade_dist.sh +++ b/modules/upgrade_dist.sh @@ -40,7 +40,7 @@ upgrade_dist() fi # Remplace source.list from dist with ours (be smarter) - installfile "${SYS_DIST}_${SYS_VER}" /etc/apt/sources.list + installfile "${SYS_DIST}_${SYS_VER}.list" /etc/apt/sources.list prnt I "Mise à jour de la liste des paquets..." pkgupdt From 08d9724f99160413b8caf62671d48d43781706fb Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Fri, 1 Oct 2021 11:24:47 +0200 Subject: [PATCH 05/13] dev.md: corrected some titles --- doc/dev.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/dev.md b/doc/dev.md index 00a3392..cc046e2 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -169,7 +169,7 @@ accomplish that function. That function takes no parameters and any given parameters will be ignored. -#### 5.2.2. pkginst +#### 5.2.2. pkginst \ That function installs using the package manager the packages given in parameters. The list of parameters are all considered as package names. @@ -188,7 +188,7 @@ accomplish that function. That function takes no parameters and any given parameters will be ignored. -#### 5.2.4. pkgrem +#### 5.2.4. pkgrem \ That function uninstalls using the package manager the packages given in parameters. The list of parameters are all considered as package names. @@ -222,5 +222,5 @@ the originally UpStart "service" program tend to be available on many systems and is privileged. ### 6.2. Functions -#### 6.2.1. exec_serv +#### 6.2.1. exec_serv \ \ From cc04f61e145eae22808694e4c99887262109e7e2 Mon Sep 17 00:00:00 2001 From: levasseur Date: Mon, 4 Oct 2021 12:00:31 +0200 Subject: [PATCH 06/13] backupdist: added support for symbolic links --- lib/filefct.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/filefct.sh b/lib/filefct.sh index 3df9b70..effefb8 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -30,7 +30,10 @@ backupdist() for file in $@; do local tmstmp=$(stdtime) - if [[ -f ${file} ]]; then + if [[ - L ${file} ]]; then + # With symbolik links we call again backupdist to treat target + backupdist $(readlink -f ${file}) + elif [[ -f ${file} ]]; then prnt I "Création d'une sauvegarde de ${file} du $tmstmp..." cp -av $file ${file}.dist.${tmstmp} if [[ $? -ne 0 ]]; then @@ -80,12 +83,12 @@ installfile() fi done - # Empty for just to obtain the target which is the last element of the list + # Empty to just obtain the target which is the last element of the list for i in $filelist; do : done if [[ ! $i == /* ]]; then - prnt E "installfile(): Target must be on the root filesystem and fuul path must be provided." + prnt E "installfile(): Target must be on the root filesystem and full path must be provided." die 13 fi if [[ -d $(dirname $i) ]]; then From 4e3e14dc30bffe4926ddf2e434573c8319f64512 Mon Sep 17 00:00:00 2001 From: levasseur Date: Mon, 4 Oct 2021 12:02:03 +0200 Subject: [PATCH 07/13] prnt: HEAD var renamed head and made local --- lib/display.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/display.sh b/lib/display.sh index 96f74f3..b7a8a88 100644 --- a/lib/display.sh +++ b/lib/display.sh @@ -93,23 +93,23 @@ export On_IWhite='\e[0;107m' prnt() { case $1 in "I") - HEADS="[ ${IGreen}info${DEFAULTFG} ]" + local heads="[ ${IGreen}info${DEFAULTFG} ]" shift ## ;; "W") - HEADS="[${IYellow}Attention${DEFAULTFG}]" + local heads="[${IYellow}Attention${DEFAULTFG}]" shift ;; "E") - HEADS="[ ${IRed}ERREUR${DEFAULTFG} ]" + local heads="[ ${IRed}ERREUR${DEFAULTFG} ]" shift ;; "m") - HEADS=" " + local heads=" " shift ;; esac - echo -e "${IWhite}$(date $DATEFORMAT)${DEFAULTFG} ${HEADS} $@" + echo -e "${IWhite}$(date $DATEFORMAT)${DEFAULTFG} ${heads} $@" } export -f prnt From b48cc4cc5154fe1778845efb160cfc088f9f203e Mon Sep 17 00:00:00 2001 From: levasseur Date: Mon, 4 Oct 2021 15:10:48 +0200 Subject: [PATCH 08/13] updated default legos-bas conf --- conf/includes/legos-bas.conf.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/includes/legos-bas.conf.sh b/conf/includes/legos-bas.conf.sh index f660435..7243bd3 100644 --- a/conf/includes/legos-bas.conf.sh +++ b/conf/includes/legos-bas.conf.sh @@ -16,4 +16,4 @@ export SYSLOCALE="fr_FR.UTF-8" #export CALCMOUNTPOINT="/calcul/$HOSTNAME" # Liste des serveurs NTP -export NTPSERVERS="ntp1.$MAINDOM ntp2.$MAINDOM" +#export NTPSERVERS="ntp1.$MAINDOM ntp2.$MAINDOM" From ce76c1ce265bc89d41dc4e2f65773cdf7d92edd1 Mon Sep 17 00:00:00 2001 From: levasseur Date: Mon, 4 Oct 2021 15:11:22 +0200 Subject: [PATCH 09/13] dev.md: updated and improved --- doc/dev.md | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/doc/dev.md b/doc/dev.md index cc046e2..ad48c1c 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -1,25 +1,37 @@ # init.sh developer's reference ## Table of content - * [1. Getting started](#1-getting-started) - * [2. The aaa_error.sh file](#2-the-aaa_errorsh-file) - + [2.1. Functions](#21-functions) +- [init.sh developer's reference](#initsh-developers-reference) + - [1. Getting started](#1-getting-started) + - [2. The aaa_error.sh file](#2-the-aaa_errorsh-file) + - [2.1. Functions](#21-functions) - [2.1.1. check_root](#211-check_root) - [2.1.2. die [--force] \](#212-die---force-exitcode) - [2.1.3. noerror [--noout] \](#213-noerror---noout-command) - + [2.2. Other functionalities](#22-other-functionalities) - * [3. The display.sh file](#3-the-displaysh-file) - + [3.1. Functions](#31-functions) + - [2.2. Other functionalities](#22-other-functionalities) + - [3. The display.sh file](#3-the-displaysh-file) + - [3.1. Functions](#31-functions) - [3.1.1. prnt [I|W|E|m] \](#311-prnt-iwem-message) - + [3.2. Other functionalities](#32-other-functionalities) - * [4. The filefct.sh file](#4-the-filefctsh-file) - + [4.1. Functions](#41-functions) + - [3.2. Other functionalities](#32-other-functionalities) + - [4. The filefct.sh file](#4-the-filefctsh-file) + - [4.1. Functions](#41-functions) - [4.1.1. stdtime](#411-stdtime) - [4.1.2. backupdist \](#412-backupdist-list_of_files_or_dirs) - [4.1.3. installfile \ \](#413-installfile-sources-destination) - + [4.2. Other functionalities](#42-other-functionalities) - * [5. The pkgman.sh file](#5-the-pkgmansh-file) - + - [4.2. Other functionnalities](#42-other-functionnalities) + - [5. The pkgman.sh file](#5-the-pkgmansh-file) + - [5.1. Global dependencies](#51-global-dependencies) + - [5.2. Functions](#52-functions) + - [5.2.1. pkgupdt](#521-pkgupdt) + - [5.2.2. pkginst \](#522-pkginst-package_list) + - [5.2.3. pkgupgd](#523-pkgupgd) + - [5.2.4. pkgrem \](#524-pkgrem-package_list) + - [5.2.3. pkgupgd](#523-pkgupgd) + - [5.3. Other functionnalities](#53-other-functionnalities) + - [6. The services.sh files](#6-the-servicessh-files) + - [6.1. Global dependencies](#61-global-dependencies) + - [6.2. Functions](#62-functions) + - [6.2.1. exec_serv \ \](#621-exec_serv-service-command) ## 1. Getting started This is a developer's reference. It's not intended to be a manual, but a @@ -118,7 +130,8 @@ echo -e "${IRed}${On_IYellow}ATTENTION:${DEFAULTBG} this is a warning!${DEFAULTC ### 4.1. Functions #### 4.1.1. stdtime Display date and time based on RFC 3339 standard but slightly modified so it can -be used in filename. +be used in filename. Thus spaces are replaced by dash, and comas between hours, +minutes and seconds are removed. That function takes no parameters and return its result on standard output. From 169f2f520a4a56b462a2e873e06c8f3db59fd723 Mon Sep 17 00:00:00 2001 From: levasseur Date: Mon, 4 Oct 2021 17:14:53 +0200 Subject: [PATCH 10/13] dev.md: improve information on color codes --- doc/dev.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/doc/dev.md b/doc/dev.md index ad48c1c..41025af 100644 --- a/doc/dev.md +++ b/doc/dev.md @@ -102,7 +102,7 @@ The first parameter is the header type, having those possible values: - Anything else will be treated as the message and will lose alignment. The second parameter is the message to display. - + ### 3.2. Other functionalities Using that script will declare some easy to remember variables containing Bash color codes: @@ -110,12 +110,14 @@ color codes: - Standard codes depending on your environment: DEFAULTFG, DEFAULTBG, DEFAULTCOL=*${DEFAULTBG}${DEFAULTFG}* - Regular colors: Black, Red, Green, Yellow, Blue, Purple, Cyan, White - - Bold: BBlack, BRed, BGreen, BYellow, BBlue, BPurple, BCyan, BWhite + - Bold (only available in graphical console or some non standard console + fonts): BBlack, BRed, BGreen, BYellow, BBlue, BPurple, BCyan, BWhite - Underline: UBlack, URed, UGreen, UYellow, UBlue, UPurple, UCyan, UWhite - Background: On_Black, On_Red, On_Green, On_Yellow, On_Blue, On_Purple, On_Cyan, On_White - High intensity: IBlack, IRed, IGreen, IYellow, IBlue, IPurple, ICyan, IWhite - - Bold high intensity: BIBlack, BIRed, BIGreen, BIYellow, BIBlue, BIPurple, + - Bold high intensity (only available in graphical console or some non standard + console fonts): BIBlack, BIRed, BIGreen, BIYellow, BIBlue, BIPurple, BICyan, BIWhite - High intensity backgrounds: On_IBlack, On_IRed, On_IGreen, On_IYellow, On_IBlue, On_IPurple, On_ICyan, On_IWhite From 5a36c277ba5eb96a963c71295339dc11df734ac9 Mon Sep 17 00:00:00 2001 From: levasseur Date: Mon, 4 Oct 2021 17:52:57 +0200 Subject: [PATCH 11/13] added isdirempty and embrio of patchfile --- lib/filefct.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/filefct.sh b/lib/filefct.sh index effefb8..ce8e9a3 100644 --- a/lib/filefct.sh +++ b/lib/filefct.sh @@ -108,4 +108,30 @@ installfile() } export -f installfile + +# ------------------------------------------------------------------------------ +# determine if a directory is empty +isdirempty() +{ + dir=$1 + + if [[ ! -d $dir ]]; then + return 0 + fi + + nbfiles=$(ls -a1 $dir | egrep -v '^.$|^..$' | wc -l) + if [[ $nbfiles -eq 0 ]]; then + return 0 + fi + return 1 +} + + +# ------------------------------------------------------------------------------ +# patch a file replacing all @var@ by the corresponding value in environment +patchfile() +{ + : # todo +} + # EOF From 976b0d4e1975820c470d04a26622531caa9a13fd Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Tue, 5 Oct 2021 11:59:35 +0200 Subject: [PATCH 12/13] README.md: improved doc, added autoload details --- README.md | 65 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 5e45504..cc71bd5 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,18 @@ its requirements turn it naturally to Linux systems. It has long been tested using Debian GNU/Linux, Devuan and different flavors of Ubuntu. ## Table of content - * [1. Getting started](#1-getting-started) - * [2. Design](#2-design) - + [2.1. Command line](#21-command-line) - + [2.2. Loading order and process](#22-loading-order-and-process) - + [2.3. Main configuration file](#23-main-configuration-file) - + [2.4. Naming conventions](#24-naming-conventions) - + [2.5. Basic module structure](#25-basic-module-structure) - * [3. Error code table](#3-error-code-table) - * [4. Contact and more information](#4-contact-and-more-information) - +- [init.sh](#initsh) + - [1. Getting started](#1-getting-started) + - [2. Design](#2-design) + - [2.1. Command line](#21-command-line) + - [2.2. Loading order and process](#22-loading-order-and-process) + - [2.3. Configuration files](#23-configuration-files) + - [2.3.1. Main configuration file](#231-main-configuration-file) + - [2.3.2. Automatically loaded configuration files](#232-automatically-loaded-configuration-files) + - [2.4. Naming conventions](#24-naming-conventions) + - [2.5. Basic module structure](#25-basic-module-structure) + - [3. Error code table](#3-error-code-table) + - [4. Contact and more information](#4-contact-and-more-information) ## 1. Getting started You should consider reading that document entirely before use. If you need @@ -87,14 +89,18 @@ opposite the zzz_main_fct.sh file have to be loaded last, because it's widely using previously declared libraries. After that, a basic command line parameter treatment is done. That allows the -use of --version and --help options in user space. Those options just display +use of *--version* and *--help* options in user space. Those options display information and don't require any superuser rights and exit at that point of execution. Everything after that will require administrator rights and the -script will exit with error at that point if not superuser. +script will exit with error at that point if not superuser, unless the +*--no-root-check* option have been given. -Next will be the log file creation and the loading of configuration files. At -this point a deeper analysis of command line option will be done, triggering -errors in case of inconsistency or incompatible options. +Next will be the log file creation and the loading of configuration files. +Configuration files exists in two distinct categories. First system dependant +configuration will be loaded automatically depending on your platform, then +your own configuration. At this point a deeper analysis of command line option +will be done, triggering errors in case of inconsistency or incompatible +options. Finally, checking processes are launched in their declaration order (cf. configuration file). If no error occurs and after a confirmation prompt, final @@ -104,7 +110,8 @@ Without the *--keep-going* option, any error will immediately stop execution. Some errors that could make the script impossible to execute will stop execution, even if the *--keep-going* option is provided. -### 2.3. Main configuration file +### 2.3. Configuration files +#### 2.3.1. Main configuration file The main configuration file can be two different files. Either it's completely generic and will be named **init.conf.sh** in the "conf" directory, either it @@ -128,6 +135,32 @@ so you can declare something on your organization configuration file and supersede it in your host configuration file. The only limit will be Bash capabilities in terms of variable manipulation. +#### 2.3.2. Automatically loaded configuration files +Those file are basically the system dependent part that assure compatibility +with different Linux distributions. Some of those files are shipped with +init.sh but you can add what you want to improve possibilities or to add support +for a new distribution. init.sh understand the following possibilities in terms +of OS detection: + +| Name | Variable | | +|:------------|:---------|:----------------------------------------------------| +| **arch** | SYS_ARCH | This is the system architecture, like x86_64, i386, arm64, etc. | +| **dist** | SYS_DIST | The name of the Linux distribution as reported by */etc/os-release*. | +| **version** | SYS_VER | Version of the distribution. If you run a rolling release and no version is provided by your */etc/os-release* file, the main version of the Linux kernel will be used (e.g. 5.4 for any version of 5.4. kernel branch). | +| **codename**| SYS_CODE | If your distribution profide a version codename, it will be set with it. | + +The configuration files are loaded if exists in the following order: + 1) arch.conf.sh + 2) distro.conf.sh + 3) distro-arch.conf.sh + 4) distro-version.conf.sh + 5) distro-codename.conf.sh (if *$SYS_CODE* defined) + 6) distro-version-arch.conf.sh + 7) distro-codename-arch.conf.sh (if *$SYS_CODE* defined) + +The loading of those files, if one exists, cannot be avoided. They all must be +located in the *conf/auto* directory of the init.sh tree. + ### 2.4. Naming conventions Because of internal mechanics, the dash character is forbidden in module names. From 0ed780d80de8e1be1d0d99d045c8d4b4d27d52ac Mon Sep 17 00:00:00 2001 From: fatalerrors Date: Tue, 5 Oct 2021 12:00:21 +0200 Subject: [PATCH 13/13] improved script path detection for future improvement --- init.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/init.sh b/init.sh index c7f3d55..b0c8df6 100755 --- a/init.sh +++ b/init.sh @@ -38,8 +38,8 @@ export LANG=C # Version of init export VERSION="0.99.8" -# Store script's path -export MYPATH=$(dirname $0) +# Store script's path (realpath -s resolve symlinks if init.sh is a symlink) +export MYPATH=$(dirname $(realpath -s $0)) # Get hostname export HOSTNAME=$(hostname)