command line parsing implemented, implemented --force option to die(), few typos
This commit is contained in:
@@ -81,4 +81,4 @@ export PKGS_TOOLS="asciidoc docbook-utils doxygen help2man python-sphinx \
|
|||||||
|
|
||||||
# Agrégation de tout par défaut
|
# Agrégation de tout par défaut
|
||||||
export PKGSEL="$PKGS_BASE $PKGS_BUR $PKGS_FONTS $PKGS_GRAF $PKGS_MULTI \
|
export PKGSEL="$PKGS_BASE $PKGS_BUR $PKGS_FONTS $PKGS_GRAF $PKGS_MULTI \
|
||||||
$PKGS_SCI $PKGS_PRGM $PKGS_TEX $PKGS_TOOLS"
|
$PKGS_SCI $PKGS_PRGM $PKGS_TEX $PKGS_TOOLS"
|
||||||
|
|||||||
157
init.sh
157
init.sh
@@ -14,13 +14,20 @@ set -o errexit
|
|||||||
export VERSION="0.95.1"
|
export VERSION="0.95.1"
|
||||||
|
|
||||||
# Stocke le chemin du script
|
# Stocke le chemin du script
|
||||||
MYPATH=$(dirname $0)
|
export MYPATH=$(dirname $0)
|
||||||
|
|
||||||
|
# récupère le nom d'hote
|
||||||
|
export HOSTNAME=$(hostname)
|
||||||
|
|
||||||
# Charge les bibliothèques
|
# Charge les bibliothèques
|
||||||
for lib in $MYPATH/lib/*.sh; do
|
for lib in $MYPATH/lib/*.sh; do
|
||||||
. $lib
|
. $lib
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# =============================
|
||||||
|
# ==== Basic sanity checks ====
|
||||||
|
# =============================
|
||||||
|
|
||||||
# Check if a function exists
|
# Check if a function exists
|
||||||
function_exists() {
|
function_exists() {
|
||||||
declare -f -F $1 > /dev/null
|
declare -f -F $1 > /dev/null
|
||||||
@@ -28,18 +35,22 @@ function_exists() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function_exists prnt || (
|
function_exists prnt || (
|
||||||
echo "Il manque des fonctions vitales venant des bibliothèques !"
|
echo "*** ERREUR FATALE !"
|
||||||
|
echo "*** Il manque des fonctions vitales venant des bibliothèques."
|
||||||
exit 2
|
exit 2
|
||||||
)
|
)
|
||||||
|
|
||||||
# Vérifie qu'on soit root
|
# Vérifie qu'on soit root
|
||||||
if [[ $EUID -ne 0 ]];
|
if [[ $EUID -ne 0 ]];
|
||||||
prnt E "Ce script doit être démarré en tant que root. Arrêt."
|
prnt E "Ce script doit être démarré en tant que root. Arrêt."
|
||||||
die 1
|
die 1 --force
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Variables globales importantes
|
# ===========================
|
||||||
export HOSTNAME=$(hostname)
|
# ==== Log file creation ====
|
||||||
|
# ===========================
|
||||||
|
|
||||||
|
# Variables globales importantes
|
||||||
export LOGFILE=${LOGFILE:-"$MYPATH/log/init-$(uname -n)-$(stdtime).log"}
|
export LOGFILE=${LOGFILE:-"$MYPATH/log/init-$(uname -n)-$(stdtime).log"}
|
||||||
|
|
||||||
prnt I "Création du répertoire d'accueil du fichier log..."
|
prnt I "Création du répertoire d'accueil du fichier log..."
|
||||||
@@ -61,19 +72,23 @@ else
|
|||||||
. $MYPATH/conf/init.conf.sh
|
. $MYPATH/conf/init.conf.sh
|
||||||
else
|
else
|
||||||
prnt E "Aucune configuration trouvée, impossible de continuer."
|
prnt E "Aucune configuration trouvée, impossible de continuer."
|
||||||
die 2
|
die 2 --force
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ================================
|
||||||
|
# ==== Main program functions ====
|
||||||
|
# ================================
|
||||||
|
|
||||||
# Affiche l'aide
|
# Affiche l'aide
|
||||||
disp_help()
|
disp_help()
|
||||||
{
|
{
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Utilisation : init.sh [OPTION] [-m module1,...,moduleN]
|
Utilisation : init.sh [OPTIONS] [-m|--module <module1,...,moduleN>]
|
||||||
Initialise une machine pour l'intégrer à un réseau.
|
Initialise une machine pour l'intégrer à un réseau.
|
||||||
|
|
||||||
Option :
|
Options :
|
||||||
-m, --module=<liste> Lance les modules indiqués même s'il ne sont pas
|
-m, --module <liste> Lance les modules indiqués même s'il ne sont pas
|
||||||
dans les fichiers de configuration.
|
dans les fichiers de configuration.
|
||||||
-c, --check-only Lance les procédure de vérification préexecution
|
-c, --check-only Lance les procédure de vérification préexecution
|
||||||
sans rien modifier.
|
sans rien modifier.
|
||||||
@@ -81,6 +96,10 @@ Option :
|
|||||||
-k, --keep-going L'execution continura en cas d'erreur.
|
-k, --keep-going L'execution continura en cas d'erreur.
|
||||||
-r, --resume Reprend l'execution la ou elle c'est arrêté.
|
-r, --resume Reprend l'execution la ou elle c'est arrêté.
|
||||||
-h, --help Affiche ce texte d'aide.
|
-h, --help Affiche ce texte d'aide.
|
||||||
|
-v, --version Show version of that script and version of all
|
||||||
|
available modules.
|
||||||
|
|
||||||
|
Attention : les options courtes ne sont pas concaténable.
|
||||||
|
|
||||||
Variable d'environnement :
|
Variable d'environnement :
|
||||||
LOGFILE Stocke le nom complet du fichier de log qui sera
|
LOGFILE Stocke le nom complet du fichier de log qui sera
|
||||||
@@ -97,44 +116,112 @@ Fichiers de configuration :
|
|||||||
|
|
||||||
Veuiller consulter les fichiers de configuration fournis en exemple
|
Veuiller consulter les fichiers de configuration fournis en exemple
|
||||||
pour avoir un aperçu des paramêtres disponibles.
|
pour avoir un aperçu des paramêtres disponibles.
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Show version infos
|
||||||
|
show_version()
|
||||||
|
{
|
||||||
|
echo -e "${White}init.sh${DEFAULTCOL} version ${Green}$VERSION${DEFAULTCOL}"
|
||||||
|
echo ""
|
||||||
|
echo "Available modules:"
|
||||||
|
for mod in $MYPATH/modules/*.sh; do
|
||||||
|
. $mod
|
||||||
|
local modname=$(get_mod_name $mod)
|
||||||
|
local version=VER_$modname
|
||||||
|
echo -e "\t$modname:\t ${!version}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get module name from module file
|
||||||
|
get_mod_name()
|
||||||
|
{
|
||||||
|
echo $(basename $1 | cut -f 1 -d '.')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ======================
|
# ======================
|
||||||
# ==== Main Program ====
|
# ==== Main Program ====
|
||||||
# ======================
|
# ======================
|
||||||
|
|
||||||
# Processing command line options
|
# Processing command line options
|
||||||
|
want_module=false
|
||||||
for opt in $@; do
|
for opt in $@; do
|
||||||
case $opt in
|
if [[ want_module == false ]]; then
|
||||||
"-h"|"--help")
|
case $opt in
|
||||||
disp_help
|
"-h"|"--help")
|
||||||
exit 0
|
disp_help
|
||||||
;;
|
exit 0
|
||||||
*)
|
;;
|
||||||
prnt E "Paramètre \'$opt\' non géré."
|
"-v"|"--version")
|
||||||
disp_help
|
show_version
|
||||||
exit 1
|
exit 0
|
||||||
;;
|
"-m"|"--module")
|
||||||
esac
|
want_module=true
|
||||||
|
;;
|
||||||
|
"-c"|"--check-only")
|
||||||
|
export CHECKONLY=true
|
||||||
|
;;
|
||||||
|
"-j"|"--jump")
|
||||||
|
export JUMP=true
|
||||||
|
;;
|
||||||
|
"-k"|"--keep-going")
|
||||||
|
export KEEPGOING=true
|
||||||
|
;;
|
||||||
|
"-r"|"--resume")
|
||||||
|
if [[ -s $MYPATH/stage ]]; then
|
||||||
|
export RESUME=true
|
||||||
|
else
|
||||||
|
prnt E "Le fichier d'état n'existe pas ou est vide !"
|
||||||
|
prnt E "Sans ce fichier, la reprise n'est pas possible."
|
||||||
|
die 1 --force
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
prnt E "Paramètre \'$opt\' non géré."
|
||||||
|
disp_help
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
if [[ ! MANUAL_MODULE_LIST ]]; then
|
||||||
|
MANUAL_MODULE_LIST=$opt
|
||||||
|
want_module=false
|
||||||
|
else
|
||||||
|
prnt E "Une liste de module à déjà été fournie !"
|
||||||
|
prnt E "La ligne de commande ne tolère qu'un paramètre --module."
|
||||||
|
die 1 --force
|
||||||
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
if [[ $want_module == true ]]; then
|
||||||
|
prnt E "La liste des modules à exécuter est manquante !"
|
||||||
|
die 1 --force
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check unconsistant parameters
|
||||||
|
[[ $CHECK_ONLY == true ]] && [[ $JUMP == true ]] && (
|
||||||
|
prnt E "Les options --check-only et --jump s'excluent mutuellement !"
|
||||||
|
die 1 --force
|
||||||
|
)
|
||||||
|
[[ $KEEPGOING == true ]] && [[ $CHECKONLY == true ]] && (
|
||||||
|
prnt E "Les options --keep-going et --check-only sont incompatible !"
|
||||||
|
die 1 --force
|
||||||
|
)
|
||||||
|
if [[ $RESUME == true ]]; then
|
||||||
|
[[ $CHECK_ONLY == true ]] && (
|
||||||
|
prnt E "La reprise n'a pas de sens avec --check-only."
|
||||||
|
die 1 --force
|
||||||
|
)
|
||||||
|
[[ $MANUAL_MODULE_LIST ]] && (
|
||||||
|
prnt E "Le mode reprise ne fonctionne pas avec une liste de \
|
||||||
|
modules passé manuellement."
|
||||||
|
die 1 --force
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
upgrade_dist
|
|
||||||
[[ ! $PVEHST ]] && install_ceph && conf_ceph
|
|
||||||
[[ ! $PVEHST ]] && apt_blacklist
|
|
||||||
#[[ ! $PVEHST ]] && authnz
|
|
||||||
#[[ ! $PVEHST ]] && add_users
|
|
||||||
conf_locale
|
|
||||||
install_pkg
|
|
||||||
conf_ntp
|
|
||||||
conf_ssh
|
|
||||||
install_profile
|
|
||||||
patch_snmp
|
|
||||||
install_mk-agent
|
|
||||||
conf_syslog
|
|
||||||
conf_mail
|
|
||||||
|
|
||||||
prnt I "That's all folks !"
|
prnt I "That's all folks !"
|
||||||
echo "Après vérification des logs, vous devriez redémarrer la machine..."
|
echo "Après vérification des logs, vous devriez redémarrer la machine..."
|
||||||
|
|||||||
@@ -4,15 +4,21 @@
|
|||||||
function die()
|
function die()
|
||||||
{
|
{
|
||||||
local errorcode=$1
|
local errorcode=$1
|
||||||
prnt E "Sortie prématuré avec erreur (code #$errorcode)."
|
[[ $2 == "--force" ]] && unset KEEPGOING
|
||||||
exit $errorcode
|
|
||||||
|
if [[ $KEEPGOING ]]; then
|
||||||
|
prnt E "Sortie prématuré avec erreur (code #$errorcode)."
|
||||||
|
exit $errorcode
|
||||||
|
else
|
||||||
|
prnt W "On continue malgrés l'erreur #$errorcode."
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
export -f die
|
export -f die
|
||||||
|
|
||||||
function terminate()
|
function terminate()
|
||||||
{
|
{
|
||||||
prnt E "$1 reçu, sortie immédiate."
|
prnt E "$1 reçu, sortie immédiate."
|
||||||
die 128
|
die 128 --force
|
||||||
}
|
}
|
||||||
trap terminate 'Ctrl + C' SIGINT
|
trap terminate 'Ctrl + C' SIGINT
|
||||||
trap terminate 'SIGTERM' SIGTERM
|
trap terminate 'SIGTERM' SIGTERM
|
||||||
|
|||||||
125
lib/display.sh
125
lib/display.sh
@@ -1,72 +1,79 @@
|
|||||||
# Some display functions and defines color codes
|
# Some display functions and defines color codes
|
||||||
|
|
||||||
# Standard 16 colors display declaration
|
# Standard 16 colors display declaration
|
||||||
DEFAULTFG="\e[0;39m"
|
export DEFAULTFG="\e[0;39m"
|
||||||
DEFAULTBG="\e[0;49m"
|
export DEFAULTBG="\e[0;49m"
|
||||||
DEFAULTCOL=${DEFAULTBG}${DEFAULTFG}
|
export DEFAULTCOL=${DEFAULTBG}${DEFAULTFG}
|
||||||
|
|
||||||
# Regular Colors
|
# Regular Colors
|
||||||
Black='\e[0;30m'
|
export Black='\e[0;30m'
|
||||||
Red='\e[0;31m'
|
export Red='\e[0;31m'
|
||||||
Green='\e[0;32m'
|
export Green='\e[0;32m'
|
||||||
Yellow='\e[0;33m'
|
export Yellow='\e[0;33m'
|
||||||
Blue='\e[0;34m'
|
export Blue='\e[0;34m'
|
||||||
Purple='\e[0;35m'
|
export Purple='\e[0;35m'
|
||||||
Cyan='\e[0;36m'
|
export Cyan='\e[0;36m'
|
||||||
White='\e[0;37m'
|
export White='\e[0;37m'
|
||||||
|
|
||||||
# Bold
|
# Bold
|
||||||
BBlack='\e[1;30m'
|
export BBlack='\e[1;30m'
|
||||||
BRed='\e[1;31m'
|
export BRed='\e[1;31m'
|
||||||
BGreen='\e[1;32m'
|
export BGreen='\e[1;32m'
|
||||||
BYellow='\e[1;33m'
|
export BYellow='\e[1;33m'
|
||||||
BBlue='\e[1;34m'
|
export BBlue='\e[1;34m'
|
||||||
BPurple='\e[1;35m'
|
export BPurple='\e[1;35m'
|
||||||
BCyan='\e[1;36m'
|
export BCyan='\e[1;36m'
|
||||||
BWhite='\e[1;37m'
|
export BWhite='\e[1;37m'*
|
||||||
|
|
||||||
# Underline
|
# Underline
|
||||||
UBlack='\e[4;30m'
|
export UBlack='\e[4;30m'
|
||||||
URed='\e[4;31m'
|
export URed='\e[4;31m'
|
||||||
UGreen='\e[4;32m'
|
export UGreen='\e[4;32m'
|
||||||
UYellow='\e[4;33m'
|
export UYellow='\e[4;33m'
|
||||||
UBlue='\e[4;34m'
|
export UBlue='\e[4;34m'
|
||||||
UPurple='\e[4;35m'
|
export UPurple='\e[4;35m'
|
||||||
UCyan='\e[4;36m'
|
export UCyan='\e[4;36m'
|
||||||
UWhite='\e[4;37m'
|
export UWhite='\e[4;37m'
|
||||||
|
|
||||||
# Background
|
# Background
|
||||||
On_Black='\e[40m'
|
export On_Black='\e[40m'
|
||||||
On_Red='\e[41m'
|
export On_Red='\e[41m'
|
||||||
On_Green='\e[42m'
|
export On_Green='\e[42m'
|
||||||
On_Yellow='\e[43m'
|
export On_Yellow='\e[43m'
|
||||||
On_Blue='\e[44m'
|
export On_Blue='\e[44m'
|
||||||
On_Purple='\e[45m'
|
export On_Purple='\e[45m'
|
||||||
On_Cyan='\e[46m'
|
export On_Cyan='\e[46m'
|
||||||
On_White='\e[47m'
|
export On_White='\e[47m'
|
||||||
|
|
||||||
# High Intensity
|
# High Intensity
|
||||||
IBlack='\e[0;90m'
|
export IBlack='\e[0;90m'
|
||||||
IRed='\e[0;91m'
|
export IRed='\e[0;91m'
|
||||||
IGreen='\e[0;92m'
|
export IGreen='\e[0;92m'
|
||||||
IYellow='\e[0;93m'
|
export IYellow='\e[0;93m'
|
||||||
IBlue='\e[0;94m'
|
export IBlue='\e[0;94m'
|
||||||
IPurple='\e[0;95m'
|
export IPurple='\e[0;95m'
|
||||||
ICyan='\e[0;96m'
|
export ICyan='\e[0;96m'
|
||||||
IWhite='\e[0;97m'
|
export IWhite='\e[0;97m'
|
||||||
|
|
||||||
# Bold High Intensity
|
# Bold High Intensity
|
||||||
BIBlack='\e[1;90m'
|
export BIBlack='\e[1;90m'
|
||||||
BIRed='\e[1;91m'
|
export BIRed='\e[1;91m'
|
||||||
BIGreen='\e[1;92m'
|
export BIGreen='\e[1;92m'
|
||||||
BIYellow='\e[1;93m'
|
export BIYellow='\e[1;93m'
|
||||||
BIBlue='\e[1;94m'
|
export BIBlue='\e[1;94m'
|
||||||
BIPurple='\e[1;95m'
|
export BIPurple='\e[1;95m'
|
||||||
BICyan='\e[1;96m'
|
export BICyan='\e[1;96m'
|
||||||
BIWhite='\e[1;97m'
|
export BIWhite='\e[1;97m'
|
||||||
|
|
||||||
# High Intensity backgrounds
|
# High Intensity backgrounds
|
||||||
On_IBlack='\e[0;100m'
|
export On_IBlack='\e[0;100m'
|
||||||
On_IRed='\e[0;101m'
|
export On_IRed='\e[0;101m'
|
||||||
On_IGreen='\e[0;102m'
|
export On_IGreen='\e[0;102m'
|
||||||
On_IYellow='\e[0;103m'
|
export On_IYellow='\e[0;103m'
|
||||||
On_IBlue='\e[0;104m'
|
export On_IBlue='\e[0;104m'
|
||||||
On_IPurple='\e[0;105m'
|
export On_IPurple='\e[0;105m'
|
||||||
On_ICyan='\e[0;106m'
|
export On_ICyan='\e[0;106m'
|
||||||
On_IWhite='\e[0;107m'
|
export On_IWhite='\e[0;107m'
|
||||||
|
|
||||||
# Affiche le status avec en-tête coloré et timestamp
|
# Affiche le status avec en-tête coloré et timestamp
|
||||||
# (valeur de $1 : I=info, W=warning, E=error, pas d'entête si différent)
|
# (valeur de $1 : I=info, W=warning, E=error, pas d'entête si différent)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ backupdist()
|
|||||||
|
|
||||||
for file in $@; do
|
for file in $@; do
|
||||||
if [[ -e ${file} ]]; then
|
if [[ -e ${file} ]]; then
|
||||||
tmpstmp=$(stdtime)
|
local tmpstmp=$(stdtime)
|
||||||
prnt I "Création d'une sauvegarde de ${file} du $tmpstmp..."
|
prnt I "Création d'une sauvegarde de ${file} du $tmpstmp..."
|
||||||
cp -av $file $file.dist.$tmpstmp
|
cp -av $file $file.dist.$tmpstmp
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user