introduced distro version detection and automatic system dependent configuration loading
This commit is contained in:
@@ -229,6 +229,7 @@ The following table is giving a list of error code with explanation:
|
|||||||
| 5 | Malformed module list |
|
| 5 | Malformed module list |
|
||||||
| 6 | Unable to find configuration |
|
| 6 | Unable to find configuration |
|
||||||
| 7 | Misuse of script internal function |
|
| 7 | Misuse of script internal function |
|
||||||
|
| 8 | Can't determine OS version |
|
||||||
| 11 | Bad function call |
|
| 11 | Bad function call |
|
||||||
| 12 | Error copying files |
|
| 12 | Error copying files |
|
||||||
| 13 | Bad target file system |
|
| 13 | Bad target file system |
|
||||||
|
|||||||
23
conf/auto/devuan.conf.sh
Normal file
23
conf/auto/devuan.conf.sh
Normal file
@@ -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%"
|
||||||
23
conf/auto/ubuntu.conf.sh
Normal file
23
conf/auto/ubuntu.conf.sh
Normal file
@@ -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%"
|
||||||
@@ -7,9 +7,6 @@
|
|||||||
# Importe les paramètres spécifiques LEGOS
|
# Importe les paramètres spécifiques LEGOS
|
||||||
. $MYPATH/conf/includes/legos.conf.sh
|
. $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
|
# Importe la sélection de paquets par défaut
|
||||||
. $MYPATH/conf/includes/pkgsel.full.conf.sh
|
. $MYPATH/conf/includes/pkgsel.full.conf.sh
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,6 @@
|
|||||||
# Importe les paramètres spécifiques LEGOS
|
# Importe les paramètres spécifiques LEGOS
|
||||||
. $MYPATH/conf/includes/legos-bas.conf.sh
|
. $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
|
# Importe la sélection de paquets par défaut
|
||||||
. $MYPATH/conf/includes/pkgsel.full.conf.sh
|
. $MYPATH/conf/includes/pkgsel.full.conf.sh
|
||||||
|
|
||||||
|
|||||||
13
init.sh
13
init.sh
@@ -44,6 +44,9 @@ export MYPATH=$(dirname $0)
|
|||||||
# Get hostname
|
# Get hostname
|
||||||
export HOSTNAME=$(hostname)
|
export HOSTNAME=$(hostname)
|
||||||
|
|
||||||
|
# System architecture
|
||||||
|
export SYS_ARCH=$(uname -m)
|
||||||
|
|
||||||
# Load libraries
|
# Load libraries
|
||||||
for lib in $MYPATH/lib/*.sh; do
|
for lib in $MYPATH/lib/*.sh; do
|
||||||
. $lib
|
. $lib
|
||||||
@@ -65,6 +68,9 @@ function_exists prnt || (
|
|||||||
exit 3
|
exit 3
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Set system dependent vars
|
||||||
|
get_os_version $(read_os_release)
|
||||||
|
|
||||||
# ======================
|
# ======================
|
||||||
# ==== Main Program ====
|
# ==== Main Program ====
|
||||||
# ======================
|
# ======================
|
||||||
@@ -102,9 +108,12 @@ exec > >(tee -a $LOGFILE)
|
|||||||
exec 2> >(tee -a $LOGFILE >&2)
|
exec 2> >(tee -a $LOGFILE >&2)
|
||||||
prnt I "Démarrage d'init version $VERSION."
|
prnt I "Démarrage d'init version $VERSION."
|
||||||
prnt I "Le fichier de log est $LOGFILE."
|
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
|
# -- Cannot be a function ends here
|
||||||
|
|
||||||
|
load_auto_conf
|
||||||
|
|
||||||
load_configuration
|
load_configuration
|
||||||
|
|
||||||
process_commandline_and_vars
|
process_commandline_and_vars
|
||||||
@@ -127,7 +136,7 @@ done
|
|||||||
|
|
||||||
if [[ $RUN_SHELL == true ]]; then
|
if [[ $RUN_SHELL == true ]]; then
|
||||||
prnt I "Lancement d'un shell intéractif..."
|
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."
|
prnt I "Sortie du script après exécution du shell."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
@@ -185,3 +194,5 @@ fi
|
|||||||
|
|
||||||
prnt I "That's all folks !"
|
prnt I "That's all folks !"
|
||||||
rm -f $STAGEFILE
|
rm -f $STAGEFILE
|
||||||
|
|
||||||
|
# EOF
|
||||||
|
|||||||
56
lib/version.sh
Normal file
56
lib/version.sh
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# Version determination function
|
||||||
|
# This file is part of the init.sh project
|
||||||
|
# Copyright (c) 2019-2021 Geoffray Levasseur <fatalerrors@geoffray-levasseur.org>
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
|
# 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
|
||||||
|
}
|
||||||
@@ -115,6 +115,45 @@ read_commandline()
|
|||||||
export -f 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:
|
# Load configuration with the following priorities:
|
||||||
# 1) Those given on command line, if any
|
# 1) Those given on command line, if any
|
||||||
|
|||||||
@@ -40,9 +40,7 @@ upgrade_dist()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Remplace source.list from dist with ours (be smarter)
|
# Remplace source.list from dist with ours (be smarter)
|
||||||
if [[ -n $APT_LIST_FILE ]]; then
|
installfile "${SYS_DIST}_${SYS_VER}" /etc/apt/sources.list
|
||||||
installfile $APT_LIST_FILE /etc/apt/sources.list
|
|
||||||
fi
|
|
||||||
|
|
||||||
prnt I "Mise à jour de la liste des paquets..."
|
prnt I "Mise à jour de la liste des paquets..."
|
||||||
pkgupdt
|
pkgupdt
|
||||||
|
|||||||
Reference in New Issue
Block a user