improved code quality, few bug fixes

This commit is contained in:
Geoffray Levasseur
2023-08-02 11:36:01 +02:00
parent e16ce485f9
commit cd35f52509
29 changed files with 174 additions and 168 deletions

View File

@@ -1,3 +1,4 @@
#!/bin/env bash
# ------------------------------------------------------------------------------
# Main program functions
# This file is part of the init.sh project
@@ -14,39 +15,46 @@
# errors with immediate exit.
read_commandline()
{
syntax_error()
{
prnt E "Error while analysing command line parameters."
die 1 --force
}
# Processing command line options
local want_module=false
local want_logfile=false
local want_conffile=false
local want_chroot=false
local opt=
for opt in $@; do
case $opt in
local params=''
params=$(getopt -n init.sh -o hvm:cjkrRDoPl:f:s \
--long help,version,module:,check-only,jump,keep-going,resume,no-root-check,no-deps,offline,no-proxy,logfile:,file:,shell,chroot,cron \
-- "$@")
eval set -- "$params"
while true; do
case $1 in
"-h"|"--help")
disp_help
shift
exit 0
;;
"-v"|"--version")
show_version
shift
exit 0
;;
"-m"|"--module")
local want_module=true
if [[ -z $MANUAL_MODULE_LIST ]]; then
export MANUAL_MODULE_LIST=$2
else
prnt E "A module list have already been given!"
prnt E "Commande line only tolerate one --module parameter."
die 1 --force
fi
shift 2
;;
"-c"|"--check-only")
export CHECK_ONLY=true
shift
;;
"-j"|"--jump")
export JUMP=true
shift
;;
"-k"|"--keep-going")
export KEEPGOING=true
shift
;;
"-r"|"--resume")
if [[ -s $STAGE_FILE ]]; then
@@ -56,91 +64,68 @@ read_commandline()
prnt E "Without it, resuming is impossible."
die 17 --force
fi
shift
;;
"-R"|"--no-root-check")
export NO_ROOT_CHECK=true
shift
;;
"-D"|"--no-deps")
export NO_DEPS=true
shift
;;
"-o"|"--offline")
export OFFLINE=true
shift
;;
"-P"|"--no-proxy")
export NO_PROXY=true
shift
;;
"-l"|"--logfile")
local want_logfile=true
if [[ -z $NEW_LOGFILE ]]; then
export NEW_LOGFILE=$2
else
prnt E "Impossible to specify several log files."
die 1 --force
fi
shift 2
;;
"-f"|"--file")
local want_conffile=true
export CONFFILES="$CONFFILES $opt"
shift 2
;;
"-s"|"--shell")
export RUN_SHELL=true
shift
;;
"--chroot")
local want_chroot=true
if [[ -z $CHROOT_PATH ]]; then
export CHROOT_PATH=$2
else
prnt E "A chroot path have already been given."
die 1 --force
fi
shift 2
;;
"--cron")
export CRON_MODE=true
shift
;;
--)
shift
break
;;
*)
if [[ $want_module == true ]]; then
[[ $want_logfile == true ]] && synthax_error
[[ $want_conffile == true ]] && synthax_error
[[ $want_chroot == true ]] && synthax_error
if [[ -z $MANUAL_MODULE_LIST ]]; then
export MANUAL_MODULE_LIST=$opt
want_module=false
else
prnt E "A module list have already been given!"
prnt E "Commande line only tolerate one --module parameter."
die 1 --force
fi
elif [[ $want_logfile == true ]]; then
[[ $want_module == true ]] && synthax_error
[[ $want_conffile == true ]] && synthax_error
[[ $want_chroot == true ]] && synthax_error
if [[ -z $NEW_LOGFILE ]]; then
export NEW_LOGFILE=$opt
want_logfile=false
else
prnt E "Impossible to specify several log files."
die 1 --force
fi
elif [[ $want_conffile == true ]]; then
[[ $want_module == true ]] && synthax_error
[[ $want_logfile == true ]] && synthax_error
[[ $want_chroot == true ]] && synthax_error
export CONFFILES="$CONFFILES $opt"
want_logfile=false
elif [[ $want_chroot == true ]]; then
[[ $want_module == true ]] && synthax_error
[[ $want_logfile == true ]] && synthax_error
[[ $want_conffile == true ]] && synthax_error
if [[ -z $CHROOT_PATH ]]; then
export CHROOT_PATH=$opt
want_chroot=false
else
prnt E "A chroot path have already been given."
die 1 --force
fi
else
prnt E "Unknow parameter \"$opt\"."
die 1 --force
fi
if [[ -n $1 ]]; then
prnt E "Unknow parameter \"$1\" !"
die 1
fi
break
;;
esac
done
unset opt
# If those var are true at that point, something is wrong
if [[ $want_logfile == true ]] || [[ $want_module == true ]] ||
[[ $want_conffile == true ]] || [[ $want_chroot == true ]]; then
syntax_error
fi
unset want_conffile want_logfile want_module want_chroot
}
export -f read_commandline
@@ -180,11 +165,12 @@ process_commandline_and_vars()
# Configure module list
if [[ -n $MANUAL_MODULE_LIST ]]; then
prnt W "A manual module list will be used."
export MODULE_LIST=$(echo $MANUAL_MODULE_LIST | sed "s/,/ /g")
prnt W "A manual module list will be used:"
export MODULE_LIST=${MANUAL_MODULE_LIST//,/ /g}
prnt m " * $MODULE_LIST"
fi
# Check for module list existance and basic syntax
# Check for module list exis<tance and basic syntax
if [[ -n $MODULE_LIST ]]; then
for mod in $MODULE_LIST; do
if [[ $mod =~ ['-!@#$%\&*=+'] ]]; then