fixed indentation

This commit is contained in:
2022-12-17 20:19:03 +01:00
parent 2a05bc8392
commit a33726fba8
22 changed files with 800 additions and 800 deletions

View File

@@ -16,8 +16,8 @@ read_commandline()
{
syntax_error()
{
prnt E "Error while analysing command line parameters."
die 1 --force
prnt E "Error while analysing command line parameters."
die 1 --force
}
# Processing command line options
@@ -27,117 +27,117 @@ read_commandline()
local want_chroot=false
local opt=
for opt in $@; do
case $opt in
"-h"|"--help")
disp_help
exit 0
;;
"-v"|"--version")
show_version
exit 0
;;
"-m"|"--module")
local want_module=true
;;
"-c"|"--check-only")
export CHECK_ONLY=true
;;
"-j"|"--jump")
export JUMP=true
;;
"-k"|"--keep-going")
export KEEPGOING=true
;;
"-r"|"--resume")
if [[ -s $STAGE_FILE ]]; then
export RESUME=true
else
prnt E "The status file doesn't exists or is empty!"
prnt E "Without it, resuming is impossible."
die 17 --force
fi
;;
"-R"|"--no-root-check")
export NO_ROOT_CHECK=true
;;
"-D"|"--no-deps")
export NO_DEPS=true
;;
"-o"|"--offline")
export OFFLINE=true
;;
"-P"|"--no-proxy")
export NO_PROXY=true
;;
"-l"|"--logfile")
local want_logfile=true
;;
"-f"|"--file")
local want_conffile=true
;;
"-s"|"--shell")
export RUN_SHELL=true
;;
"--chroot")
local want_chroot=true
;;
"--cron")
export CRON_MODE=true
;;
*)
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
;;
esac
case $opt in
"-h"|"--help")
disp_help
exit 0
;;
"-v"|"--version")
show_version
exit 0
;;
"-m"|"--module")
local want_module=true
;;
"-c"|"--check-only")
export CHECK_ONLY=true
;;
"-j"|"--jump")
export JUMP=true
;;
"-k"|"--keep-going")
export KEEPGOING=true
;;
"-r"|"--resume")
if [[ -s $STAGE_FILE ]]; then
export RESUME=true
else
prnt E "The status file doesn't exists or is empty!"
prnt E "Without it, resuming is impossible."
die 17 --force
fi
;;
"-R"|"--no-root-check")
export NO_ROOT_CHECK=true
;;
"-D"|"--no-deps")
export NO_DEPS=true
;;
"-o"|"--offline")
export OFFLINE=true
;;
"-P"|"--no-proxy")
export NO_PROXY=true
;;
"-l"|"--logfile")
local want_logfile=true
;;
"-f"|"--file")
local want_conffile=true
;;
"-s"|"--shell")
export RUN_SHELL=true
;;
"--chroot")
local want_chroot=true
;;
"--cron")
export CRON_MODE=true
;;
*)
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
;;
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
[[ $want_conffile == true ]] || [[ $want_chroot == true ]]; then
syntax_error
fi
unset want_conffile want_logfile want_module
@@ -151,54 +151,54 @@ process_commandline_and_vars()
{
# Check unconsistant parameters
if [[ $CHECK_ONLY == true ]]; then
if [[ $JUMP == true ]]; then
prnt E "The options --check-only and --jump are mutually exclusive!"
die 1 --force
fi
if [[ $KEEPGOING == true ]]; then
prnt E "The options --keep-going and --check-only are not compatible!"
die 1 --force
fi
if [[ $JUMP == true ]]; then
prnt E "The options --check-only and --jump are mutually exclusive!"
die 1 --force
fi
if [[ $KEEPGOING == true ]]; then
prnt E "The options --keep-going and --check-only are not compatible!"
die 1 --force
fi
fi
if [[ $RESUME == true ]]; then
if [[ $CHECK_ONLY == true ]]; then
prnt E "Resuming doesn't make sense with --check-only."
die 1 --force
fi
if [[ $MANUAL_MODULE_LIST ]]; then
prnt E "Recovery mode can't work with a manual module list."
die 1 --force
fi
if [[ $CHECK_ONLY == true ]]; then
prnt E "Resuming doesn't make sense with --check-only."
die 1 --force
fi
if [[ $MANUAL_MODULE_LIST ]]; then
prnt E "Recovery mode can't work with a manual module list."
die 1 --force
fi
fi
if [[ $CRON_MODE == true ]]; then
if [[ $CHECK_ONLY == true || $JUMP == true ]]; then
prnt E "Some parameters are incompatible with cron mode."
die 16 --force
fi
if [[ $CHECK_ONLY == true || $JUMP == true ]]; then
prnt E "Some parameters are incompatible with cron mode."
die 16 --force
fi
fi
# 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=$(echo $MANUAL_MODULE_LIST | sed "s/,/ /g")
fi
# Check for module list existance and basic syntax
if [[ -n $MODULE_LIST ]]; then
for mod in $MODULE_LIST; do
if [[ $mod =~ ['-!@#$%\&*=+'] ]]; then
prnt E "The module \"$mod\" contains a forbidden character in its name."
die 5
fi
if [[ ! -s "modules/$mod.sh" ]]; then
prnt E "The asked module \"$mod\", doesn't have any module file or module file is empty."
die 18
fi
done
for mod in $MODULE_LIST; do
if [[ $mod =~ ['-!@#$%\&*=+'] ]]; then
prnt E "The module \"$mod\" contains a forbidden character in its name."
die 5
fi
if [[ ! -s "modules/$mod.sh" ]]; then
prnt E "The asked module \"$mod\", doesn't have any module file or module file is empty."
die 18
fi
done
else
prnt E "No module to execute!"
die 5
prnt E "No module to execute!"
die 5
fi
}
export -f process_commandline_and_vars

View File

@@ -14,23 +14,23 @@
blank_disk()
{
if [[ -b /dev/$1 ]]; then
prnt I "Wipping $1 drive signature (a backup is made in /root)..."
wipefs --force --all --backup /dev/$1
prnt I "Filling beginning of $1 drive with zeroes..."
if [[ $2 == "--full" ]]; then
# If full we display progress as it might take a very long time
# Need true to avoid error as the last byte will generate a disk
# full error
dd if="/dev/zero" of="$1" bs="512" status=progress || true
else
dd if="/dev/zero" of="$1" bs="512" count="1024"
fi
prnt I "Wipping $1 drive signature (a backup is made in /root)..."
wipefs --force --all --backup /dev/$1
prnt I "Filling beginning of $1 drive with zeroes..."
if [[ $2 == "--full" ]]; then
# If full we display progress as it might take a very long time
# Need true to avoid error as the last byte will generate a disk
# full error
dd if="/dev/zero" of="$1" bs="512" status=progress || true
else
dd if="/dev/zero" of="$1" bs="512" count="1024"
fi
# Update kernel partition scheme
partprobe
# Update kernel partition scheme
partprobe
else
prnt E "The /dev/$1 file is not a bloc device!"
die 19
prnt E "The /dev/$1 file is not a bloc device!"
die 19
fi
}
export -f blank_disk
@@ -44,16 +44,16 @@ export -f blank_disk
is_blank()
{
if [[ -b /dev/$1 ]]; then
# That technique is fast but might not be relayable enough if we are on
# exotic data structure or filesystem...
local devstat=$(file /dev/$1 | sed "s@/dev/$1: @@")
if [[ $devstat == 'data' ]]; then
return 0
else
return 1
fi
# That technique is fast but might not be relayable enough if we are on
# exotic data structure or filesystem...
local devstat=$(file /dev/$1 | sed "s@/dev/$1: @@")
if [[ $devstat == 'data' ]]; then
return 0
else
return 1
fi
else
return 2
return 2
fi
}
export -f is_blank
@@ -69,37 +69,37 @@ mkparts()
{
local device=$1 && shit
if [[ $1 == "gtp" || $1 == "dos" ]]; then
local parttype=$1 && shift
local parttype=$1 && shift
else
# Default is GPT
local parttype="gpt"
# Default is GPT
local parttype="gpt"
fi
if [[ $(is_blank $device) ]]; then
prnt I "Creating a new ${parttype^^} partition table on $device..."
sfdisk -label /dev/$device $parttype
prnt I "Creating a new partition scheme on /dev/$1..."
local tmpfile=$(mktemp sfd.XXXX)
if [[ -n $1 ]]; then
# For each given size we make a partition
for $part in $@; do
# If size is zero we interpret it as all available space
if [[ $part == 0 ]]; then
echo ",,L" >> $tmpfile
else
echo ",$part,L" >> $tmpfile
fi
done
else
echo ",,L" >> $tmpfile
fi
echo "write" >> $tmpfile
sfdisk "/dev/$device" < $tmpfile
rm $tmpfile
unset tmpfile
prnt I "Creating a new ${parttype^^} partition table on $device..."
sfdisk -label /dev/$device $parttype
prnt I "Creating a new partition scheme on /dev/$1..."
local tmpfile=$(mktemp sfd.XXXX)
if [[ -n $1 ]]; then
# For each given size we make a partition
for $part in $@; do
# If size is zero we interpret it as all available space
if [[ $part == 0 ]]; then
echo ",,L" >> $tmpfile
else
echo ",$part,L" >> $tmpfile
fi
done
else
echo ",,L" >> $tmpfile
fi
echo "write" >> $tmpfile
sfdisk "/dev/$device" < $tmpfile
rm $tmpfile
unset tmpfile
else
prnt E "The $1 block device is not blank, for security we won't proceed!"
die 20
prnt E "The $1 block device is not blank, for security we won't proceed!"
die 20
fi
unset device parttype
}
@@ -111,12 +111,12 @@ export -f mkparts
mkfs_gen()
{
for drv in $@; do
if [[ -b /dev/$drv ]]; then
$mkfstool $MKFSOPT /dev/$drv
else
prnt E "/dev/$drv is not a bloc device!"
die 18
fi
if [[ -b /dev/$drv ]]; then
$mkfstool $MKFSOPT /dev/$drv
else
prnt E "/dev/$drv is not a bloc device!"
die 18
fi
done
}
@@ -125,9 +125,9 @@ mkfs_gen()
# Format drive using ext4 filesystem, parameters will be a list of block device
mkext4()
{
export mkfstool="mkfs.ext4"
mkfs_gen $@
unset mkfstool
export mkfstool="mkfs.ext4"
mkfs_gen $@
unset mkfstool
}
export -f mkext4
@@ -136,9 +136,9 @@ export -f mkext4
# Format a XFS filesystem...
mkxfs()
{
export mkfstool="mkfs.xfs"
mkfs_gen $@
unset mkfstool
export mkfstool="mkfs.xfs"
mkfs_gen $@
unset mkfstool
}
export -f mkxfs
@@ -147,9 +147,9 @@ export -f mkxfs
# ... NTFS ...
mkntfs()
{
export mkfstool="mkfs.ntfs"
mkfs_gen $@
unset mkfstool
export mkfstool="mkfs.ntfs"
mkfs_gen $@
unset mkfstool
}
export -f mkntfs
@@ -158,9 +158,9 @@ export -f mkntfs
# ... FAT32 ...
mkfat32()
{
export mkfstool="mkfs.vfat"
mkfs_gen $@
unset mkfstool
export mkfstool="mkfs.vfat"
mkfs_gen $@
unset mkfstool
}
export -f mkfat32
@@ -169,9 +169,9 @@ export -f mkfat32
# ... BTRFS ...
mkbtrfs()
{
export mkfstool="mkfs.btrfs"
mkfs_gen $@
unset mkfstool
export mkfstool="mkfs.btrfs"
mkfs_gen $@
unset mkfstool
}
export -f mkbtrfs

View File

@@ -94,28 +94,28 @@ export On_IWhite='\e[0;107m'
prnt()
{
if [[ $1 == "-n" ]]; then
local echoopt=$1
shift
local echoopt=$1
shift
else
local echoopt=""
local echoopt=""
fi
case $1 in
"I")
local heads="[ ${IGreen}info${DEFAULTFG} ]"
shift
;;
"W")
local heads="[${IYellow}Warning${DEFAULTFG}]"
shift
;;
"E")
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
shift
;;
"m")
local heads=" "
shift
;;
"I")
local heads="[ ${IGreen}info${DEFAULTFG} ]"
shift
;;
"W")
local heads="[${IYellow}Warning${DEFAULTFG}]"
shift
;;
"E")
local heads="[ ${IRed}ERROR${DEFAULTFG} ]"
shift
;;
"m")
local heads=" "
shift
;;
esac
echo $echoopt -e "${IWhite}$(date $DATEFORMAT)${DEFAULTFG} ${heads} $@"
@@ -132,10 +132,10 @@ separator()
local i=0
declare -li length=$(( $(tput cols) - 1 ))
if [[ $length -gt 80 ]]; then
length=$(( $length - (($length - 80) / 2) ))
length=$(( $length - (($length - 80) / 2) ))
fi
for i in $(seq 1 $length); do
echo -n "-"
echo -n "-"
done
echo -e "$DEFAULTCOL"
unset i length
@@ -150,13 +150,13 @@ dsleep()
i=$1
while test $i -gt 0
do
if [[ -n $2 ]]; then
echo -n "$2"
else
echo -n " ${i}"
fi
(( i=i-1 ))
sleep 1
if [[ -n $2 ]]; then
echo -n "$2"
else
echo -n " ${i}"
fi
(( i=i-1 ))
sleep 1
done
echo
}

View File

@@ -21,35 +21,35 @@ export COMM_REPO_PATH=${COMM_REPO_PATH:-"$MYPATH/repo/common"}
backup_dist()
{
if [[ $# -lt 1 ]]; then
prnt E "backup_dist(): At least one argument is required."
exit 11
prnt E "backup_dist(): At least one argument is required."
exit 11
fi
local file=
for file in $@; do
local tmstmp=$(stdtime)
if [[ -L ${file} ]]; then
# With symbolik links we call again backup_dist to treat target
local tmstmp=$(stdtime)
if [[ -L ${file} ]]; then
# With symbolik links we call again backup_dist to treat target
prnt I "Following the symbolic link $file to do a proper backup..."
backup_dist $(readlink -f ${file})
elif [[ -f ${file} ]]; then
prnt I "Creating a backup of ${file} on $tmstmp..."
cp -av $file ${file}.dist.${tmstmp}
if [[ $? -ne 0 ]]; then
prnt E "backup_dist(): Failed copying file."
die 12
fi
elif [[ -d ${file} ]]; then
prnt I "Creation a backup of the directory ${file} on $tmstmp..."
cp -av $file ${file}.dist.${tmstmp}
if [[ $? -ne 0 ]]; then
prnt E "backup_dist(): Failed copyind directory recursively."
die 12
fi
else
prnt W "backup_dist(): $file don't exists, nothing to do."
fi
unset tmstmp
backup_dist $(readlink -f ${file})
elif [[ -f ${file} ]]; then
prnt I "Creating a backup of ${file} on $tmstmp..."
cp -av $file ${file}.dist.${tmstmp}
if [[ $? -ne 0 ]]; then
prnt E "backup_dist(): Failed copying file."
die 12
fi
elif [[ -d ${file} ]]; then
prnt I "Creation a backup of the directory ${file} on $tmstmp..."
cp -av $file ${file}.dist.${tmstmp}
if [[ $? -ne 0 ]]; then
prnt E "backup_dist(): Failed copyind directory recursively."
die 12
fi
else
prnt W "backup_dist(): $file don't exists, nothing to do."
fi
unset tmstmp
done
unset file
}
@@ -62,12 +62,12 @@ select_file()
{
local infile=$1
if [[ -f $HOST_REPO_PATH/$infile ]]; then
local source="$HOST_REPO_PATH/$infile"
local source="$HOST_REPO_PATH/$infile"
elif [[ -f $COMM_REPO_PATH/$infile ]]; then
local source="$COMM_REPO_PATH/$infile"
local source="$COMM_REPO_PATH/$infile"
else
# Not found in repository, we expect full name
local source="$infile"
# Not found in repository, we expect full name
local source="$infile"
fi
unset infile
echo $source
@@ -82,12 +82,12 @@ select_directory()
{
local indir=$1
if [[ -d $HOST_REPO_PATH/$indir ]]; then
local source="$HOST_REPO_PATH/$indir"
local source="$HOST_REPO_PATH/$indir"
elif [[ -d $COMM_REPO_PATH/$indir ]]; then
local source="$COMM_REPO_PATH/$indir"
local source="$COMM_REPO_PATH/$indir"
else
# Not found in repository, we expect full name
local source="$indir"
# Not found in repository, we expect full name
local source="$indir"
fi
unset indir
echo $source
@@ -105,44 +105,44 @@ install_file()
local i=0
if [[ $# -lt 2 ]]; then
prnt E "install_file(): At least two arguments are required."
die 11
prnt E "install_file(): At least two arguments are required."
die 11
fi
if [[ $(echo $@ | grep "\*\|\?") ]]; then
prnt E "install_file(): Wildcards are not authorized."
die 7
prnt E "install_file(): Wildcards are not authorized."
die 7
fi
local arg=
for arg in $@; do
filelist="$filelist $(select_file $arg)"
filelist="$filelist $(select_file $arg)"
done
unset arg
# Empty to just obtain the target which is the last element of the list
local file=
for file in $filelist; do
:
:
done
if [[ ! $file == /* ]]; then
prnt E "install_file(): Target must be on the root filesystem and full path must be provided."
die 13
prnt E "install_file(): Target must be on the root filesystem and full path must be provided."
die 13
fi
unset file
if [[ -d $(dirname $i) ]]; then
prnt I "Creating required target directory $(dirname $i)..."
mkdir -pv $(dirname $i)
if [[ $? -ne 0 ]]; then
prnt E "install_file(): Can't create target directory!"
die 12
fi
prnt I "Creating required target directory $(dirname $i)..."
mkdir -pv $(dirname $i)
if [[ $? -ne 0 ]]; then
prnt E "install_file(): Can't create target directory!"
die 12
fi
fi
prnt I "Copying files ${filelist} to target directory $(dirname $i)..."
cp -av $filelist
if [[ $? -ne 0 ]]; then
prnt E "install_file(): Couldn't copy some required files!"
die 12
prnt E "install_file(): Couldn't copy some required files!"
die 12
fi
}
export -f install_file
@@ -155,19 +155,19 @@ append_file()
local srcfile=$(select_file $1)
local dstfile=$2
if [[ -e $dstfile ]]; then
prnt E "append_file(): Target must be on the root filesystem and full path must be provided."
die 13
prnt E "append_file(): Target must be on the root filesystem and full path must be provided."
die 13
fi
if [[ ! $dstfile == /* ]]; then
prnt E "append_file(): Target file must exist."
die 13
prnt E "append_file(): Target file must exist."
die 13
fi
prnt I "Adding content to file $dstfile..."
cat $srcfile >> $dstfile
if [[ $? -ne 0 ]]; then
prnt E "append_file(): Couldn't append a file!"
die 12
prnt E "append_file(): Couldn't append a file!"
die 12
fi
}
export -f append_file
@@ -180,16 +180,16 @@ is_dir_empty()
dir=$1
if [[ -f $dir ]]; then
prnt E "is_dir_empty(): The given parameter is not a directory."
die 15
prnt E "is_dir_empty(): The given parameter is not a directory."
die 15
fi
if [[ ! -d $dir ]]; then
return 0
return 0
fi
nbfiles=$(ls -a1 $dir | egrep -v '^.$|^..$' | wc -l)
if [[ $nbfiles -eq 0 ]]; then
return 0
return 0
fi
return 1
}
@@ -206,29 +206,29 @@ patch_file()
local workfile=${dstfile}.work
if [[ ! -s $srcfile ]]; then
prnt E "patch_file(): Source file is empty, is not a file or don't exists!"
die 10
prnt E "patch_file(): Source file is empty, is not a file or don't exists!"
die 10
fi
# Create a sub-process, to avoid bash environment pollution
(
local varlist= pattern=
if [[ $# -eq 0 ]] ; then
pattern="-e s/<\(.*\)>/\$\1\$\1/g"
else
local var=
for var in $* ; do
if ! declare -p $var >/dev/null 2>&1 ; then
local $var=$(eval echo \$$var)
fi
export $var
pattern="$pattern -e s/@$var@/\$$var/g"
varlist=$varlist\$$var
done
fi
local varlist= pattern=
if [[ $# -eq 0 ]] ; then
pattern="-e s/<\(.*\)>/\$\1\$\1/g"
else
local var=
for var in $* ; do
if ! declare -p $var >/dev/null 2>&1 ; then
local $var=$(eval echo \$$var)
fi
export $var
pattern="$pattern -e s/@$var@/\$$var/g"
varlist=$varlist\$$var
done
fi
# sed replace <VAR> with \$$VAR and envsubst do the replace by value
sed $pattern $srcfile | envsubst ${varlist:+"$varlist"} > "$workfile"
# sed replace <VAR> with \$$VAR and envsubst do the replace by value
sed $pattern $srcfile | envsubst ${varlist:+"$varlist"} > "$workfile"
)
local -a rights=( $(stat --printf="%a %u %g" "$srcfile") )
@@ -247,13 +247,13 @@ export -f patch_file
tag_file()
{
for f in $@; do
local text="# File automatically modified by init.sh on $(stdtime)."
if [[ -e $f ]]; then
sed -i "1s/^/$text\n/" $f
else
echo $text > $f
sed -i -e "s/modified/generated/" $f
fi
local text="# File automatically modified by init.sh on $(stdtime)."
if [[ -e $f ]]; then
sed -i "1s/^/$text\n/" $f
else
echo $text > $f
sed -i -e "s/modified/generated/" $f
fi
done
}
export -f tag_file
@@ -264,10 +264,10 @@ export -f tag_file
file_exists()
{
for f in $@; do
if [[ ! -f $(select_file $f) ]]; then
echo $f
return 1
fi
if [[ ! -f $(select_file $f) ]]; then
echo $f
return 1
fi
done
return 0
}
@@ -281,8 +281,8 @@ file_must_exists()
prnt I "Checking $@ files existance..."
local mf=$(file_exists $@)
if [[ $? -ne 0 ]]; then
prnt E "file_must_exists(): The $mf file is missing, can't continue."
die 10
prnt E "file_must_exists(): The $mf file is missing, can't continue."
die 10
fi
unset mf
}
@@ -294,10 +294,10 @@ export -f file_must_exists
directory_exists()
{
for d in $@; do
if [[ ! -d $(select_directory $d) ]]; then
echo $d
return 1
fi
if [[ ! -d $(select_directory $d) ]]; then
echo $d
return 1
fi
done
return 0
}
@@ -310,8 +310,8 @@ directory_must_exists()
prnt I "Checking $@ directories existance..."
local md=$(directory_exists $@)
if [[ $? -ne 0 ]]; then
prnt E "directory_must_exists(): The $md directory is missing, can't continue."
die 10
prnt E "directory_must_exists(): The $md directory is missing, can't continue."
die 10
fi
unset md
}

View File

@@ -24,25 +24,25 @@ load_autoconf()
local prefix="$MYPATH/conf/auto"
if [[ -e $prefix/$SYS_ARCH.conf.sh ]]; then
. $prefix/$SYS_ARCH.conf.sh
. $prefix/$SYS_ARCH.conf.sh
fi
if [[ -e $prefix/$SYS_DIST.conf.sh ]]; then
. $prefix/$SYS_DIST.conf.sh
. $prefix/$SYS_DIST.conf.sh
fi
if [[ -e $prefix/$SYS_DIST-$SYS_ARCH.conf.sh ]]; then
. $prefix/$SYS_DIST-$SYS_ARCH.conf.sh
. $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
. $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
. $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
. $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
. $prefix/$SYS_DIST-$SYS_CODE-$SYS_ARCH.conf.sh
fi
unset prefix
@@ -58,31 +58,31 @@ export -f load_autoconf
load_configuration()
{
if [[ -n $CONFFILES ]]; then
local f=
for f in $CONFFILES; do
prnt I "Loading $f manually specified."
if [[ -s $f ]]; then
. $f
else
prnt E "The $f file doesn't exists or is empty."
die 6 --force
fi
done
unset f
local f=
for f in $CONFFILES; do
prnt I "Loading $f manually specified."
if [[ -s $f ]]; then
. $f
else
prnt E "The $f file doesn't exists or is empty."
die 6 --force
fi
done
unset f
else
prnt I "Loading configuration..."
if [[ -e $MYPATH/conf/$HOSTNAME.conf.sh ]]; then
prnt I "A specific configuration will be used."
. $MYPATH/conf/$HOSTNAME.conf.sh
else
if [[ -e $MYPATH/conf/init.conf.sh ]]; then
prnt I "A generic configuration will be used."
. $MYPATH/conf/init.conf.sh
else
prnt E "No configuration found, impossible to continue."
die 6 --force
fi
fi
prnt I "Loading configuration..."
if [[ -e $MYPATH/conf/$HOSTNAME.conf.sh ]]; then
prnt I "A specific configuration will be used."
. $MYPATH/conf/$HOSTNAME.conf.sh
else
if [[ -e $MYPATH/conf/init.conf.sh ]]; then
prnt I "A generic configuration will be used."
. $MYPATH/conf/init.conf.sh
else
prnt E "No configuration found, impossible to continue."
die 6 --force
fi
fi
fi
}
export -f load_configuration
@@ -94,8 +94,8 @@ load_prepost_actions()
{
local prepost=
for prepost in $MYPATH/prepost.d/*.sh; do
prnt I "Loading prepost actions in $prepost ..."
. $prepost
prnt I "Loading prepost actions in $prepost ..."
. $prepost
done
unset prepost
}

View File

@@ -25,21 +25,21 @@ pkginst()
{
prnt I "Installing packages..."
if [[ $# -lt 1 ]]; then
prnt E "pkginst(): some required parameters are missing."
exit 11
prnt E "pkginst(): some required parameters are missing."
exit 11
fi
if [[ ! $INSTALL_MODE == dev ]]; then
exec_preinst $@
$PKG_MAN $COM_INSTALL $@
exec_postinst
exec_preinst $@
$PKG_MAN $COM_INSTALL $@
exec_postinst
else
local pkg=
for pkg in $@; do
exec_preinst $pkg
$PKG_MAN $COM_INSTALL $pkg
exec_postinst
done
unset pkg
local pkg=
for pkg in $@; do
exec_preinst $pkg
$PKG_MAN $COM_INSTALL $pkg
exec_postinst
done
unset pkg
fi
}
export -f pkginst
@@ -63,21 +63,21 @@ pkgrm()
{
prnt I "Uninstalling packages..."
if [[ $# -lt 1 ]]; then
prnt E "pkgrem(): some required parameters are missing."
exit 11
prnt E "pkgrem(): some required parameters are missing."
exit 11
fi
if [[ ! $INSTALL_MODE == dev ]]; then
exec_prerm $@
$PKG_MAN $COM_REMOVE $@
exec_postrm
exec_prerm $@
$PKG_MAN $COM_REMOVE $@
exec_postrm
else
local pkg=
for pkg in $@; do
exec_prerm $pkg
$PKG_MAN $COM_REMOVE $pkg
exec_postrm
done
uset pkg
local pkg=
for pkg in $@; do
exec_prerm $pkg
$PKG_MAN $COM_REMOVE $pkg
exec_postrm
done
uset pkg
fi
}
export -f pkgrm
@@ -101,10 +101,10 @@ exec_preinst()
{
local pkglist=$(get_install_list $@)
for pkg in $pkglist; do
if [[ $(function_exists preinst_$pkg) ]]; then
prnt I "Running $pkg preinstallation script..."
preinst_$pkg
fi
if [[ $(function_exists preinst_$pkg) ]]; then
prnt I "Running $pkg preinstallation script..."
preinst_$pkg
fi
done
export POSTINSTLIST=$pkglist
unset pkglist
@@ -117,13 +117,13 @@ export -f exec_preinst
exec_postinst()
{
if [[ -z $POSTINSTLIST ]]; then
return 0
return 0
fi
for pkg in $POSTINSTLIST; do
if [[ $(function_exists postinst_$pkg) ]]; then
prnt I "Running $pkg postinstallation script..."
postinst_$pkg
fi
if [[ $(function_exists postinst_$pkg) ]]; then
prnt I "Running $pkg postinstallation script..."
postinst_$pkg
fi
done
unset POSTINSTLIST
}
@@ -137,10 +137,10 @@ exec_prerm()
local pkglist=$(get_remove_list $@)
unset $cmd
for pkg in $pkglist; do
if [[ $(function_exists prerm_$pkg) ]]; then
prnt I "Running $pkg preremove script..."
prerm_$pkg
fi
if [[ $(function_exists prerm_$pkg) ]]; then
prnt I "Running $pkg preremove script..."
prerm_$pkg
fi
done
export POSTRMLIST=$pkglist
unset pkglist
@@ -153,13 +153,13 @@ export -f exec_prerm
exec_postrm()
{
if [[ -z $POSTRMLIST ]]; then
return 0
return 0
fi
for pkg in $POSTRMLIST; do
if [[ $(function_exists postrm_$pkg) ]]; then
prnt I "Running $pkg postremove script..."
postrm_$pkg
fi
if [[ $(function_exists postrm_$pkg) ]]; then
prnt I "Running $pkg postremove script..."
postrm_$pkg
fi
done
unset POSTRMLIST
}
@@ -172,10 +172,10 @@ exec_preupgd()
{
local pkglist=$(get_upgrade_list)
for pkg in $pkglist; do
if [[ $(function_exists preupgd_$pkg) ]]; then
prnt I "Running $pkg preupgrade script..."
preupgd_$pkg
fi
if [[ $(function_exists preupgd_$pkg) ]]; then
prnt I "Running $pkg preupgrade script..."
preupgd_$pkg
fi
done
export POSTUPGDLIST=$pkglist
unset pkglist
@@ -188,13 +188,13 @@ export -f exec_preupgd
exec_postupgd()
{
if [[ -z $POSTUPGDLIST ]]; then
return 0
return 0
fi
for pkg in $POSTUPGDLIST; do
if [[ $(function_exists postupgd_$pkg) ]]; then
prnt I "Running $pkg postupgrade script..."
postupgd_$pkg
fi
if [[ $(function_exists postupgd_$pkg) ]]; then
prnt I "Running $pkg postupgrade script..."
postupgd_$pkg
fi
done
unset POSTUPGDLIST
}
@@ -207,10 +207,10 @@ exec_preautorm()
{
local pkglist=$(get_autorem_list)
for pkg in $pkglist; do
if [[ $(function_exists prerm_$pkg) ]]; then
prnt I "Running $pkg preremove script..."
prerm_$pkg
fi
if [[ $(function_exists prerm_$pkg) ]]; then
prnt I "Running $pkg preremove script..."
prerm_$pkg
fi
done
export POSTRMLIST=$pkglist
unset pkglist

View File

@@ -15,16 +15,16 @@
exec_serv()
{
if [[ $# -lt 2 ]]; then
prnt E "exec_serv(): Syntax error (parameters: $@)!"
exit 11
prnt E "exec_serv(): Syntax error (parameters: $@)!"
exit 11
fi
local svcname=$1 command=$2
shift 2
local lineexec=$(echo $INIT_COM |
sed -e s/%srv%/$svcname/ \
-e s/%com%/$command/)
sed -e s/%srv%/$svcname/ \
-e s/%com%/$command/)
unset svcname command
prnt I "Launching command $command for the service $svcname"
@@ -41,7 +41,7 @@ svc_start()
{
local svc=
for svc in $@; do
exec_serv $svc start
exec_serv $svc start
done
unset svc
}
@@ -53,7 +53,7 @@ export -f svc_start
svc_reload()
{
for svc in $@; do
exec_serv $svc reload
exec_serv $svc reload
done
}
export -f svc_reload
@@ -65,7 +65,7 @@ svc_restart()
{
local svc=
for svc in $@; do
exec_serv $svc restart
exec_serv $svc restart
done
unset svc
}
@@ -78,7 +78,7 @@ svc_stop()
{
local svc=
for svc in $@; do
exec_serv $svc stop
exec_serv $svc stop
done
unset svc
}

View File

@@ -84,21 +84,21 @@ show_version()
local mod=
for mod in $MYPATH/modules/*.sh; do
# Ran in a subshell to not pollute environment
(
. $mod
local modname=$(get_mod_name $mod)
local version=VER_$modname
# Ran in a subshell to not pollute environment
(
. $mod
local modname=$(get_mod_name $mod)
local version=VER_$modname
echo -e "\t$BWhite$modname${DEFAULTCOL}: $BGreen${!version}$DEFAULTCOL"
echo -e "\t$BWhite$modname${DEFAULTCOL}: $BGreen${!version}$DEFAULTCOL"
unset modname version
)
unset modname version
)
done
unset mod
if [[ $(id -u) -ne 0 ]]; then
echo -e "\n${BYellow}Warning:$DEFAULTCOL That script requires superuser rights to work."
echo -e "\n${BYellow}Warning:$DEFAULTCOL That script requires superuser rights to work."
fi
}
export -f show_version

View File

@@ -21,14 +21,14 @@ export -f stdtime
# Check if a function exists, return 0 if so
function_exists() {
if [[ $# -ne 1 ]]; then
prnt E "function_exists(): A function name is required!"
die 11 --force
prnt E "function_exists(): A function name is required!"
die 11 --force
fi
if [[ $(LC_ALL=C type -t $1 | grep function) ]]; then
return 0
return 0
else
return 1
return 1
fi
}
export -f function_exists
@@ -39,8 +39,8 @@ export -f function_exists
get_mod_name()
{
if [[ $# -ne 1 ]]; then
prnt E "get_mod_name(): Bad number of parameters."
die 11 --force
prnt E "get_mod_name(): Bad number of parameters."
die 11 --force
fi
echo $(basename $1 | cut -f 1 -d '.')
}
@@ -62,7 +62,7 @@ export -f trim
dump_key_buffer()
{
while read -r -t 0.001; do
:
:
done
}
export -f dump_key_buffer

View File

@@ -13,32 +13,32 @@
get_os_version()
{
if [[ ! -f /etc/os-release ]]; then
prnt E "get_os_version(): Your distribution doesn't have the needed os-release file."
die 8 --force
prnt E "get_os_version(): 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"
# Iniitalise version codename in case the var don't exists
VERSION_CODENAME="NULL"
# Import the file in the environment
source /etc/os-release
# Import the file in the environment
source /etc/os-release
if [[ -z $ID ]]; then
prnt E "get_os_version(): Your /etc/os-release file mises some vital information."
die 8 --force
fi
if [[ -z $ID ]]; then
prnt E "get_os_version(): Your /etc/os-release file mises some vital information."
die 8 --force
fi
if [[ -z $VERSION_ID ]]; then
local maj=$(uname -r | cut -d'.' -f1)
local min=$(uname -r | cut -d'.' -f2)
VERSION_ID="$maj.$min"
unset maj min
fi
if [[ -z $VERSION_ID ]]; then
local maj=$(uname -r | cut -d'.' -f1)
local min=$(uname -r | cut -d'.' -f2)
VERSION_ID="$maj.$min"
unset maj min
fi
# Return values on stdout
echo ${ID,,} ${VERSION_ID} ${VERSION_CODENAME,,}
# Return values on stdout
echo ${ID,,} ${VERSION_ID} ${VERSION_CODENAME,,}
)
}
export read_os_release
@@ -50,17 +50,17 @@ export read_os_release
set_sys_vars()
{
if [[ $# -ne 4 ]]; then
prnt E "set_sys_vars(): Incorrect number of parameters ($@)."
die 7 --force
prnt E "set_sys_vars(): Incorrect number of parameters ($@)."
die 7 --force
fi
export SYS_ARCH=$1
export SYS_DIST=$2
export SYS_VER=$3
if [[ $4 != "null" ]]; then
export SYS_CODE=$4
export SYS_CODE=$4
elif [[ -n $SYS_CODE ]]; then
unset SYS_CODE
unset SYS_CODE
fi
}
export -f get_os_version