Compare commits

...

4 Commits

22 changed files with 823 additions and 822 deletions

100
init.sh
View File

@@ -152,12 +152,12 @@ fi
# If cron mode, run cron tasks then exit # If cron mode, run cron tasks then exit
if [[ $CRON_MODE == true ]]; then if [[ $CRON_MODE == true ]]; then
for mod in $MODULE_LIST; do for mod in $MODULE_LIST; do
if [[ $(function_exists cron_$mod) ]]; then if [[ $(function_exists cron_$mod) ]]; then
prnt I "Running cron task for module $mod ..." prnt I "Running cron task for module $mod ..."
cron_$mod cron_$mod
else else
prnt I "No cron task for module $mod." prnt I "No cron task for module $mod."
fi fi
done done
prnt I "All cron executed successfully!" prnt I "All cron executed successfully!"
exit 0 exit 0
@@ -173,37 +173,37 @@ fi
if [[ JUMP != true ]]; then if [[ JUMP != true ]]; then
tmpfile=$(mktemp /tmp/init-XXXXXX) tmpfile=$(mktemp /tmp/init-XXXXXX)
if [[ -n $MANUAL_MODULE_LIST ]]; then if [[ -n $MANUAL_MODULE_LIST ]]; then
prnt W "Dependency checks are deactivated with a manual module list." prnt W "Dependency checks are deactivated with a manual module list."
fi fi
if [[ $NO_DEPS == true ]]; then if [[ $NO_DEPS == true ]]; then
prnt W "Dependency checks have been deactivated manually." prnt W "Dependency checks have been deactivated manually."
fi fi
if [[ $RESUME == true ]]; then if [[ $RESUME == true ]]; then
cat $STAGE_FILE >> $tmpfile cat $STAGE_FILE >> $tmpfile
fi fi
for mod in $MODULE_LIST; do for mod in $MODULE_LIST; do
version=VER_$mod version=VER_$mod
if [[ $RESUME == true ]] && [[ $(grep $mod $STAGE_FILE) ]]; then if [[ $RESUME == true ]] && [[ $(grep $mod $STAGE_FILE) ]]; then
prnt I "Checks previously executed for $mod version ${!version}." prnt I "Checks previously executed for $mod version ${!version}."
continue continue
fi fi
prnt I "Running initial checks for $mod version ${!version}..." prnt I "Running initial checks for $mod version ${!version}..."
if [[ -z $MANUAL_MODULE_LIST && $NO_DEPS != true ]]; then if [[ -z $MANUAL_MODULE_LIST && $NO_DEPS != true ]]; then
deps=DEP_$mod deps=DEP_$mod
for dep in ${!deps}; do for dep in ${!deps}; do
if [[ ! $(grep $dep $tmpfile) ]]; then if [[ ! $(grep $dep $tmpfile) ]]; then
prnt E "Module $mod have unsatisfied dependencies or is executed too early." prnt E "Module $mod have unsatisfied dependencies or is executed too early."
prnt E " * $dep must be executed before $mod, please check your module list." prnt E " * $dep must be executed before $mod, please check your module list."
die 9 die 9
fi fi
done done
unset deps unset deps
fi fi
# We run in a subshell to protect main environment # We run in a subshell to protect main environment
( (
precheck_$mod precheck_$mod
) )
echo $mod >> $tmpfile echo $mod >> $tmpfile
done done
rm -f $tmpfile rm -f $tmpfile
unset mod unset mod
@@ -239,23 +239,23 @@ echo && separator && echo
if [[ $key == "C" || $key == 'c' ]]; then if [[ $key == "C" || $key == 'c' ]]; then
# We launch modules one after one # We launch modules one after one
for mod in $MODULE_LIST; do for mod in $MODULE_LIST; do
if [[ $RESUME == true ]] && [[ $(grep $mod $STAGE_FILE) ]]; then if [[ $RESUME == true ]] && [[ $(grep $mod $STAGE_FILE) ]]; then
continue continue
fi fi
# We need this only if JUMP is set but doesn't matter if it's done again # We need this only if JUMP is set but doesn't matter if it's done again
version=VER_$mod version=VER_$mod
prnt I "Applying changes for $mod version ${!version}..." prnt I "Applying changes for $mod version ${!version}..."
# Yet again, executed in a subshell # Yet again, executed in a subshell
( (
export REBOOT_NEEDED=false export REBOOT_NEEDED=false
$mod $mod
if [[ $REBOOT_NEEDED == true ]]; then if [[ $REBOOT_NEEDED == true ]]; then
echo "$mod reboot" >> $STAGE_FILE # Mark as done for resuming echo "$mod reboot" >> $STAGE_FILE # Mark as done for resuming
else else
echo $mod >> $STAGE_FILE # Mark as done for resuming function echo $mod >> $STAGE_FILE # Mark as done for resuming function
fi fi
) )
separator separator
done done
unset mod unset mod
else else
@@ -268,8 +268,8 @@ echo
if [[ -s $STAGE_FILE && $(grep " reboot" $STAGE_FILE) ]]; then if [[ -s $STAGE_FILE && $(grep " reboot" $STAGE_FILE) ]]; then
prnt W "A reboot is required to apply some changes by the following packages:" prnt W "A reboot is required to apply some changes by the following packages:"
prnt m " * $(grep ' reboot' $STAGE_FILE | \ prnt m " * $(grep ' reboot' $STAGE_FILE | \
sed 's/ reboot//' | \ sed 's/ reboot//' | \
sed ':a' -e 'N' -e '$!ba' -e 's/\n/ /g')" sed ':a' -e 'N' -e '$!ba' -e 's/\n/ /g')"
prnt I "Please reboot now or as soon as possible!" prnt I "Please reboot now or as soon as possible!"
echo echo
fi fi

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -20,34 +20,34 @@ Initialise une machine pour l'intégrer à un réseau.
Options : Options :
-f, --file <fichier> Permet de spécifier un fichier de configuration -f, --file <fichier> Permet de spécifier un fichier de configuration
à charger manuellement. Cette option peut être répétée à charger manuellement. Cette option peut être répétée
pour permettre le chargement de plusieurs fichiers de pour permettre le chargement de plusieurs fichiers de
configuration, le dernier surchargeant les précédants. configuration, le dernier surchargeant les précédants.
-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. Les noms des dans les fichiers de configuration. Les noms des
modules doivent être séparés par des virgules. modules doivent être séparés par des virgules.
-c, --check-only Lance les procédures de vérification sans rien -c, --check-only Lance les procédures de vérification sans rien
modifier. modifier.
-j, --jump Saute les procédures de vérification des -j, --jump Saute les procédures de vérification des
modules. modules.
-k, --keep-going Continue l'execution en cas d'erreur. -k, --keep-going Continue l'execution en cas d'erreur.
-r, --resume Reprend l'execution là ou elle s'est arrêté. -r, --resume Reprend l'execution là ou elle s'est arrêté.
-R, --no-root-check Ne pas vérifier les droits root (ou UID 0) -R, --no-root-check Ne pas vérifier les droits root (ou UID 0)
-o, --offline Assume that all needed resource are available on a LAN -o, --offline Assume that all needed resource are available on a LAN
and avoid any Internet connectivity checks. and avoid any Internet connectivity checks.
-P, --no-proxy Ne pas utiliser de proxy lors de l'utilisation de -P, --no-proxy Ne pas utiliser de proxy lors de l'utilisation de
ce script (n'empêche pas leur configuration via modules) ce script (n'empêche pas leur configuration via modules)
-D, --no-deps Ne pas vérifier les dépendances entre les modules. -D, --no-deps Ne pas vérifier les dépendances entre les modules.
-h, --help Affiche ce texte d'aide. -h, --help Affiche ce texte d'aide.
-s, --shell Lance un shell avec tout l'environnement du script pour -s, --shell Lance un shell avec tout l'environnement du script pour
débogage. Aucune action ou vérification n'est faite en débogage. Aucune action ou vérification n'est faite en
dehors des commandes lancées dans le shell. dehors des commandes lancées dans le shell.
--chroot <chemin> Permet à init de ne pas appliquer les modifications au --chroot <chemin> Permet à init de ne pas appliquer les modifications au
système de fichier racine mais à un système différent. système de fichier racine mais à un système différent.
-l, --logfile <nom> Nom du fichier de log. Peut aussi être changé -l, --logfile <nom> Nom du fichier de log. Peut aussi être changé
via la variable d'environnement LOGFILE. via la variable d'environnement LOGFILE.
-v, --version Affiche la version de ce script et celles de -v, --version Affiche la version de ce script et celles de
tous les modules disponibles. tous les modules disponibles.
Attention : les options courtes ne sont pas concaténable. Attention : les options courtes ne sont pas concaténable.
@@ -84,21 +84,21 @@ show_version()
local mod= local mod=
for mod in $MYPATH/modules/*.sh; do for mod in $MYPATH/modules/*.sh; do
# Ran in a subshell to not pollute environment # Ran in a subshell to not pollute environment
( (
. $mod . $mod
local modname=$(get_mod_name $mod) local modname=$(get_mod_name $mod)
local version=VER_$modname 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 done
unset mod unset mod
if [[ $(id -u) -ne 0 ]]; then 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 fi
} }
export -f show_version export -f show_version

View File

@@ -12,7 +12,7 @@
# Define normalised time display, filename friendly # Define normalised time display, filename friendly
stdtime() stdtime()
{ {
date --rfc-3339=seconds | sed -e 's/ /-/' -e 's/://g' date --rfc-3339=seconds | sed -e 's/ /-/' -e 's/://g' | cut -d'+' -f1
} }
export -f stdtime export -f stdtime
@@ -21,14 +21,14 @@ export -f stdtime
# Check if a function exists, return 0 if so # Check if a function exists, return 0 if so
function_exists() { function_exists() {
if [[ $# -ne 1 ]]; then if [[ $# -ne 1 ]]; then
prnt E "function_exists(): A function name is required!" prnt E "function_exists(): A function name is required!"
die 11 --force die 11 --force
fi fi
if [[ $(LC_ALL=C type -t $1 | grep function) ]]; then if [[ $(LC_ALL=C type -t $1 | grep function) ]]; then
return 0 return 0
else else
return 1 return 1
fi fi
} }
export -f function_exists export -f function_exists
@@ -39,8 +39,8 @@ export -f function_exists
get_mod_name() get_mod_name()
{ {
if [[ $# -ne 1 ]]; then if [[ $# -ne 1 ]]; then
prnt E "get_mod_name(): Bad number of parameters." prnt E "get_mod_name(): Bad number of parameters."
die 11 --force die 11 --force
fi fi
echo $(basename $1 | cut -f 1 -d '.') echo $(basename $1 | cut -f 1 -d '.')
} }
@@ -57,4 +57,15 @@ trim()
} }
export -f trim export -f trim
# ------------------------------------------------------------------------------
# Dump the keyboard's buffer
dump_key_buffer()
{
while read -r -t 0.001; do
:
done
}
export -f dump_key_buffer
# EOF # EOF

View File

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

View File

@@ -35,69 +35,69 @@ conf_network()
# First configure IPv4 ifaces # First configure IPv4 ifaces
local iface= local iface=
for iface in $IPV4_IFACES; do for iface in $IPV4_IFACES; do
echo -e "\n# --------------------------------\n" >> $if_file echo -e "\n# --------------------------------\n" >> $if_file
if [[ $(eval echo \$NET4_MODE_$iface) == static ]]; then if [[ $(eval echo \$NET4_MODE_$iface) == static ]]; then
prnt I "Configuring IPv4 network interface $iface in static mode..." prnt I "Configuring IPv4 network interface $iface in static mode..."
echo "auto $iface" >> $if_file echo "auto $iface" >> $if_file
echo "iface $iface inet static" >> $if_file echo "iface $iface inet static" >> $if_file
echo -e "\taddress $(eval echo \$NET4_IP_$iface)" >> $if_file echo -e "\taddress $(eval echo \$NET4_IP_$iface)" >> $if_file
if [[ -n $(eval echo \$NET4_GW_$iface) ]]; then if [[ -n $(eval echo \$NET4_GW_$iface) ]]; then
echo -e "\tgateway $(eval echo \$NET4_GW_$iface)" >> $if_file echo -e "\tgateway $(eval echo \$NET4_GW_$iface)" >> $if_file
fi fi
if [[ -n $(eval echo \$NET4_NS_$iface) ]]; then if [[ -n $(eval echo \$NET4_NS_$iface) ]]; then
echo -e "\tdns_nameservers $(eval echo \$NET4_NS_$iface)" >> $if_file echo -e "\tdns_nameservers $(eval echo \$NET4_NS_$iface)" >> $if_file
fi fi
if [[ -n $(eval echo \$NET4_NS_SEARCH_$iface) ]]; then if [[ -n $(eval echo \$NET4_NS_SEARCH_$iface) ]]; then
echo -e "\tdns_search $(eval echo \$NET4_NS_SEARCH_$iface)" >> $if_file echo -e "\tdns_search $(eval echo \$NET4_NS_SEARCH_$iface)" >> $if_file
fi fi
elif [[ $(eval echo \$NET4_MODE_$iface) == dhcp ]]; then elif [[ $(eval echo \$NET4_MODE_$iface) == dhcp ]]; then
prnt I "Configuring IPv4 network interface $iface in DHCP mode..." prnt I "Configuring IPv4 network interface $iface in DHCP mode..."
echo "auto $iface" >> $if_file echo "auto $iface" >> $if_file
echo "iface $iface inet dhcp" >> $if_file echo "iface $iface inet dhcp" >> $if_file
elif [[ $(eval echo \$NET4_MODE_$iface) == manual ]]; then elif [[ $(eval echo \$NET4_MODE_$iface) == manual ]]; then
local fname=$(eval echo \$NET4_MANUAL_FILE_$iface) local fname=$(eval echo \$NET4_MANUAL_FILE_$iface)
append_file $fname $if_file append_file $fname $if_file
unset fname unset fname
fi fi
done done
for iface in $IPV6_IFACES; do for iface in $IPV6_IFACES; do
echo -e "\n# --------------------------------\n" >> $if_file echo -e "\n# --------------------------------\n" >> $if_file
if [[ $(eval echo \$NET6_MODE_$iface) == static ]]; then if [[ $(eval echo \$NET6_MODE_$iface) == static ]]; then
prnt I "Configuring IPv6 network interface $iface in static mode..." prnt I "Configuring IPv6 network interface $iface in static mode..."
echo "auto $iface" >> $if_file echo "auto $iface" >> $if_file
echo "iface $iface inet6 static" >> $if_file echo "iface $iface inet6 static" >> $if_file
echo -e "\taddress $(eval echo \$NET6_IP_$iface)" >> $if_file echo -e "\taddress $(eval echo \$NET6_IP_$iface)" >> $if_file
if [[ -n $(eval echo \$NET6_GW_$iface) ]]; then if [[ -n $(eval echo \$NET6_GW_$iface) ]]; then
echo -e "\tgateway $(eval echo \$NET6_GW_$iface)" >> $if_file echo -e "\tgateway $(eval echo \$NET6_GW_$iface)" >> $if_file
fi fi
if [[ -n $(eval echo \$NET6_NS_$iface) ]]; then if [[ -n $(eval echo \$NET6_NS_$iface) ]]; then
echo -e "\tdns_nameservers $(eval echo \$NET6_NS_$iface)" >> $if_file echo -e "\tdns_nameservers $(eval echo \$NET6_NS_$iface)" >> $if_file
fi fi
if [[ -n $(eval echo \$NET6_NS_SEARCH_$iface) ]]; then if [[ -n $(eval echo \$NET6_NS_SEARCH_$iface) ]]; then
echo -e "\tdns_search $(eval echo \$NET6_NS_SEARCH_$iface)" >> $if_file echo -e "\tdns_search $(eval echo \$NET6_NS_SEARCH_$iface)" >> $if_file
fi fi
elif [[ $(eval echo \$NET6_MODE_$iface) == dhcp ]]; then elif [[ $(eval echo \$NET6_MODE_$iface) == dhcp ]]; then
prnt I "Configuring IPv6 network interface $iface in DHCP mode..." prnt I "Configuring IPv6 network interface $iface in DHCP mode..."
echo "auto $iface" >> $if_file echo "auto $iface" >> $if_file
echo "iface $iface inet6 dhcp" >> $if_file echo "iface $iface inet6 dhcp" >> $if_file
elif [[ $(eval echo \$NET6_MODE_$iface) == manual ]]; then elif [[ $(eval echo \$NET6_MODE_$iface) == manual ]]; then
local fname=$(eval echo \$NET6_MANUAL_FILE_$iface) local fname=$(eval echo \$NET6_MANUAL_FILE_$iface)
append_file $fname $if_file append_file $fname $if_file
unset fname unset fname
fi fi
done done
unset iface if_file unset iface if_file
@@ -108,80 +108,80 @@ precheck_conf_network()
{ {
file_must_exists interfaces.head file_must_exists interfaces.head
if [[ -z $IPV4_IFACES ]]; then if [[ -z $IPV4_IFACES ]]; then
prnt W "No IPv4 interfaces to configure." prnt W "No IPv4 interfaces to configure."
else else
for iface in $IPV4_IFACES; do for iface in $IPV4_IFACES; do
if [[ ! -d /sys/class/net/$iface ]]; then if [[ ! -d /sys/class/net/$iface ]]; then
prnt E "The iface $iface, asked to configure, do not exist!" prnt E "The iface $iface, asked to configure, do not exist!"
die 175 die 175
else else
if [[ $(grep "up" /sys/class/net/$iface/operstate) ]]; then if [[ $(grep "up" /sys/class/net/$iface/operstate) ]]; then
prnt W "The IPv4 iface $iface, is already configured, a reboot will be required." prnt W "The IPv4 iface $iface, is already configured, a reboot will be required."
fi fi
fi fi
if [[ -z $(eval echo \$NET4_MODE_$iface) ]]; then if [[ -z $(eval echo \$NET4_MODE_$iface) ]]; then
prnt E "Interfaces $iface have no mode set!" prnt E "Interfaces $iface have no mode set!"
die 175 die 175
else else
case $(eval echo \$NET4_MODE_$iface) in case $(eval echo \$NET4_MODE_$iface) in
"static") "static")
if [[ -z $(eval echo \$NET4_IP_$iface) ]]; then if [[ -z $(eval echo \$NET4_IP_$iface) ]]; then
prnt E "No IPv4 have been assigned to static interface $iface!" prnt E "No IPv4 have been assigned to static interface $iface!"
fi fi
prnt m " * Interface $iface will have $(eval echo \$NET4_IP_$iface) static IPv4 address." prnt m " * Interface $iface will have $(eval echo \$NET4_IP_$iface) static IPv4 address."
;; ;;
"dhcp") "dhcp")
prnt m " * Interface $iface will use DHCP." prnt m " * Interface $iface will use DHCP."
;; ;;
"manual") "manual")
file_must_exists $(eval echo \$NET4_MANUAL_FILE_$iface) file_must_exists $(eval echo \$NET4_MANUAL_FILE_$iface)
prnt m " * Interface $iface will use manual IPv4 configuration in a file." prnt m " * Interface $iface will use manual IPv4 configuration in a file."
;; ;;
*) *)
prnt E "Interfaces mode \"$(eval echo \$NET4_MODE_$iface)\" unsuported!" prnt E "Interfaces mode \"$(eval echo \$NET4_MODE_$iface)\" unsuported!"
die 175 die 175
;; ;;
esac esac
fi fi
done done
fi fi
if [[ -z $IPV6_IFACES ]]; then if [[ -z $IPV6_IFACES ]]; then
prnt W "No IPv6 interfaces to configure." prnt W "No IPv6 interfaces to configure."
else else
for iface in $IPV6_IFACES; do for iface in $IPV6_IFACES; do
if [[ ! -d /sys/class/net/$iface ]]; then if [[ ! -d /sys/class/net/$iface ]]; then
prnt E "The iface $iface, asked to configure, do not exist!" prnt E "The iface $iface, asked to configure, do not exist!"
die 175 die 175
else else
if [[ $(grep "up" /sys/class/net/$iface/operstate) ]]; then if [[ $(grep "up" /sys/class/net/$iface/operstate) ]]; then
prnt W "The IPv6 iface $iface, is already configured, a reboot will be required." prnt W "The IPv6 iface $iface, is already configured, a reboot will be required."
fi fi
fi fi
if [[ -z $(eval echo \$NET6_MODE_$iface) ]]; then if [[ -z $(eval echo \$NET6_MODE_$iface) ]]; then
prnt E "Interfaces $iface have no mode set!" prnt E "Interfaces $iface have no mode set!"
die 175 die 175
else else
case $(eval echo \$NET6_MODE_$iface) in case $(eval echo \$NET6_MODE_$iface) in
"static") "static")
if [[ -z $(eval echo \$NET6_IP_$iface) ]]; then if [[ -z $(eval echo \$NET6_IP_$iface) ]]; then
prnt E "No IPv6 have been assigned to static interface $iface!" prnt E "No IPv6 have been assigned to static interface $iface!"
fi fi
prnt m " * Interface $iface will have $(eval echo \$NET6_IP_$iface) static IPv6 address." prnt m " * Interface $iface will have $(eval echo \$NET6_IP_$iface) static IPv6 address."
;; ;;
"dhcp") "dhcp")
prnt m " * Interface $iface will use DHCPv6." prnt m " * Interface $iface will use DHCPv6."
;; ;;
"manual") "manual")
file_must_exists $(eval echo \$NET6_MANUAL_FILE_$iface) file_must_exists $(eval echo \$NET6_MANUAL_FILE_$iface)
prnt m " * Interface $iface will use manual IPv6 configuration in a file." prnt m " * Interface $iface will use manual IPv6 configuration in a file."
;; ;;
*) *)
prnt E "Interfaces mode \"$(eval echo \$NET6_MODE_$iface)\" unsuported!" prnt E "Interfaces mode \"$(eval echo \$NET6_MODE_$iface)\" unsuported!"
die 175 die 175
;; ;;
esac esac
fi fi
done done
fi fi
} }

View File

@@ -17,8 +17,8 @@ export DEP_conf_ntp=""
conf_ntp() conf_ntp()
{ {
if [[ $(pidof systemd) ]]; then if [[ $(pidof systemd) ]]; then
prnt I "Disabling Systemd-timesyncd..." prnt I "Disabling Systemd-timesyncd..."
systemctl disable systemd-timesyncd || true systemctl disable systemd-timesyncd || true
fi fi
prnt I "Installing ntp daemon..." prnt I "Installing ntp daemon..."
@@ -33,11 +33,11 @@ conf_ntp()
install_file ntp.conf $dest install_file ntp.conf $dest
local line="" local line=""
for srv in $NTP_SERVERS; do for srv in $NTP_SERVERS; do
line="${line}server $srv iburst\n" line="${line}server $srv iburst\n"
done done
sed -i -e "s/@SERVERLIST@/$line/" $dest && sed -i -e "s/@SERVERLIST@/$line/" $dest &&
echo "# Generated on $(stdtime)" >> $dest && echo "# Generated on $(stdtime)" >> $dest &&
mv -fv $dest /etc/ntp.conf mv -fv $dest /etc/ntp.conf
prnt I "Starting service ntp..." prnt I "Starting service ntp..."
svc_start ntp svc_start ntp
@@ -49,14 +49,14 @@ conf_ntp()
precheck_conf_ntp() precheck_conf_ntp()
{ {
if [[ -z $NTP_SERVERS ]]; then if [[ -z $NTP_SERVERS ]]; then
prnt E "No configured NTP server!" prnt E "No configured NTP server!"
die 151 die 151
else else
file_must_exists ntp.conf file_must_exists ntp.conf
prnt m "The NTP servers to be used will be:" prnt m "The NTP servers to be used will be:"
for srv in $NTP_SERVERS; do for srv in $NTP_SERVERS; do
prnt m " * $srv" prnt m " * $srv"
done done
fi fi
} }

View File

@@ -24,9 +24,9 @@ conf_ssh()
prnt I "Installating OpenSSH configuration files..." prnt I "Installating OpenSSH configuration files..."
for f in /etc/ssh/ssh{,d}_config; do for f in /etc/ssh/ssh{,d}_config; do
backup_dist $f backup_dist $f
install_file ssh/$(basename $f) $f install_file ssh/$(basename $f) $f
tag_file $f tag_file $f
done done
sed -i -e "s#@SSHD_PERMITROOT_RANGE@#$SSHD_PERMITROOT_RANGE#" /etc/ssh/sshd_config sed -i -e "s#@SSHD_PERMITROOT_RANGE@#$SSHD_PERMITROOT_RANGE#" /etc/ssh/sshd_config

View File

@@ -17,8 +17,8 @@ export DEP_create_vm="upgrade_dist install_pkg"
create_vm() create_vm()
{ {
if [[ $WITH_VM != "yes" ]]; then if [[ $WITH_VM != "yes" ]]; then
prnt W "That computer is not configured for virtualisation, nothing to do." prnt W "That computer is not configured for virtualisation, nothing to do."
return 0 return 0
fi fi
pkginst virtualbox pkginst virtualbox
@@ -32,60 +32,60 @@ create_vm()
local accel_2d=off local accel_2d=off
case $VM_OS in case $VM_OS in
Windows*) Windows*)
accel_2d=on accel_2d=on
;; ;;
esac esac
# Create emty VM # Create emty VM
local targetdir=$VM_ROOT/vms/$VM_NAME local targetdir=$VM_ROOT/vms/$VM_NAME
vboxmanage createvm --ostype $VM_OS --basefolder $targetdir \ vboxmanage createvm --ostype $VM_OS --basefolder $targetdir \
--name $VM_NAME --register --name $VM_NAME --register
# Give main caracteristics # Give main caracteristics
vboxmanage modifyvm $VM_NAME \ vboxmanage modifyvm $VM_NAME \
--cpus $VM_CPU --memory $VM_MEM --vram $VM_VID_MEM \ --cpus $VM_CPU --memory $VM_MEM --vram $VM_VID_MEM \
--boot1 $VM_BOOT1 --VM_BOOT2 $VM_BOOT2 --boot3 $VM_BOOT3 \ --boot1 $VM_BOOT1 --VM_BOOT2 $VM_BOOT2 --boot3 $VM_BOOT3 \
--nic1 bridged --bridgeadapter1 $VM_IF_BRIDGE \ --nic1 bridged --bridgeadapter1 $VM_IF_BRIDGE \
--accelerate2dvideo $accel_2d \ --accelerate2dvideo $accel_2d \
--clipboard bidirectional --draganddrop disabled --clipboard bidirectional --draganddrop disabled
# Add a SATA controler # Add a SATA controler
vboxmanage storagectl $VM_NAME \ vboxmanage storagectl $VM_NAME \
--name sata0 --add sata --controller IntelAHCI --bootable on \ --name sata0 --add sata --controller IntelAHCI --bootable on \
--hostiocache on --portcount 6 --hostiocache on --portcount 6
# Create a virtual HDD # Create a virtual HDD
vboxmanage createmedium \ vboxmanage createmedium \
--size $VM_DISK_SIZE --variant Fixed --filename $targetdir/$VM_NAME.vdi --size $VM_DISK_SIZE --variant Fixed --filename $targetdir/$VM_NAME.vdi
# Connect the created HDD to the VM # Connect the created HDD to the VM
vboxmanage storageattach $VM_NAME \ vboxmanage storageattach $VM_NAME \
--storagectl sata0 --port 1 --device 0 --type hdd \ --storagectl sata0 --port 1 --device 0 --type hdd \
--medium $targetdir/$VM_NAME.vdi --medium $targetdir/$VM_NAME.vdi
unset targetdir accel_2d unset targetdir accel_2d
# Add empty DVD # Add empty DVD
vboxmanage storageattach $VM_NAME --storagectl sata0 --port 2 --device 0 \ vboxmanage storageattach $VM_NAME --storagectl sata0 --port 2 --device 0 \
--medium emptydrive --medium emptydrive
# Add shares # Add shares
local share= i=0 local share= i=0
for share in $VM_SHARES_NAME; do for share in $VM_SHARES_NAME; do
(( i+=1 )) (( i+=1 ))
local j=0 hostpath="" local j=0 hostpath=""
for path in $VM_SHARES_PATH; do for path in $VM_SHARES_PATH; do
(( j+=1 )) (( j+=1 ))
if [[ $i -eq $j ]]; then if [[ $i -eq $j ]]; then
hostpath=$path hostpath=$path
fi fi
done done
unset j unset j
vboxmanage sharedfolder add $VM_NAME \ vboxmanage sharedfolder add $VM_NAME \
--name ${VM_SHARES_NAME,,} --hostpath $hostpath --name ${VM_SHARES_NAME,,} --hostpath $hostpath
done done
unset share i unset share i
} }
@@ -93,35 +93,35 @@ create_vm()
precheck_create_vm() precheck_create_vm()
{ {
if [[ $WITH_VM == "yes" ]]; then if [[ $WITH_VM == "yes" ]]; then
if [[ -z $VM_NAME ]]; then if [[ -z $VM_NAME ]]; then
prnt E "The virtual machine must have a name." prnt E "The virtual machine must have a name."
die 181 die 181
fi fi
if [[ -z VM_CPU || -z VM_MEM || -z VM_OS || -z VM_ROOT || \ if [[ -z VM_CPU || -z VM_MEM || -z VM_OS || -z VM_ROOT || \
-z VM_BOOT1 || -z VM_BOOT2 || -z VM_BOOT3 || -z VM_VID_MEM || -z VM_BOOT1 || -z VM_BOOT2 || -z VM_BOOT3 || -z VM_VID_MEM ||
-z VM_IF_BRIDGE || -z VM_DISK_SIZE ]]; then -z VM_IF_BRIDGE || -z VM_DISK_SIZE ]]; then
prnt E "A necessary declaration for the virtual machine is absent!" prnt E "A necessary declaration for the virtual machine is absent!"
die 181 die 181
else else
prnt I "The virtual machine \"$VM_NAME\" will be created in $VM_ROOT..." prnt I "The virtual machine \"$VM_NAME\" will be created in $VM_ROOT..."
fi fi
local share= i=0 j=0 local share= i=0 j=0
for share in $VM_SHARES_NAME; do for share in $VM_SHARES_NAME; do
(( i+=1 )) (( i+=1 ))
done done
for share in $VM_SHARES_PATH; do for share in $VM_SHARES_PATH; do
(( j+=1 )) (( j+=1 ))
done done
unset share unset share
if [[ $i -eq $j ]]; then if [[ $i -eq $j ]]; then
prnt I "The virtual machine will access $i directories from the host." prnt I "The virtual machine will access $i directories from the host."
else else
prnt E "The number of share and path to share is different!" prnt E "The number of share and path to share is different!"
die 182 die 182
fi fi
else else
prnt I "No virtual machine to create." prnt I "No virtual machine to create."
fi fi
} }

View File

@@ -20,18 +20,18 @@ install_chromium()
{ {
# Add Debian repo to sources.list.d directory depending on Ubuntu version # Add Debian repo to sources.list.d directory depending on Ubuntu version
case $SYS_VER in case $SYS_VER in
16.04|16.10|17.04|17.10) 16.04|16.10|17.04|17.10)
prnt I "Adding Debian Stretch repository to software sources..." prnt I "Adding Debian Stretch repository to software sources..."
install_file debian_stretch.list /etc/apt/sources.list.d/ install_file debian_stretch.list /etc/apt/sources.list.d/
;; ;;
18.04|18.10|19.04|19.10) 18.04|18.10|19.04|19.10)
prnt I "Adding Debian Buster repository to software sources..." prnt I "Adding Debian Buster repository to software sources..."
install_file debian_buster.list /etc/apt/sources.list.d/ install_file debian_buster.list /etc/apt/sources.list.d/
;; ;;
20.04|20.10|21.04|21.10) 20.04|20.10|21.04|21.10)
prnt I "Adding Debian Bullseye repository to software sources..." prnt I "Adding Debian Bullseye repository to software sources..."
install_file debian_bullseye.list /etc/apt/sources.list.d/ install_file debian_bullseye.list /etc/apt/sources.list.d/
;; ;;
esac esac
# Install Debian GPG keys # Install Debian GPG keys
@@ -56,23 +56,23 @@ precheck_install_chromium()
{ {
# Check we run Ubuntu # Check we run Ubuntu
if [[ $SYS_DIST != "ubuntu" ]]; then if [[ $SYS_DIST != "ubuntu" ]]; then
prnt E "The install_chromium module is a Ubuntu only workaround." prnt E "The install_chromium module is a Ubuntu only workaround."
die 165 die 165
fi fi
case $SYS_VER in case $SYS_VER in
16.04|16.10|17.04|17.10) 16.04|16.10|17.04|17.10)
prnt m " * Detected Ubuntu $SYS_VER, will install Stretch version of Chromium" prnt m " * Detected Ubuntu $SYS_VER, will install Stretch version of Chromium"
;; ;;
18.04|18.10|19.04|19.10) 18.04|18.10|19.04|19.10)
prnt m " * Detected Ubuntu $SYS_VER, will install Buster version of Chromium" prnt m " * Detected Ubuntu $SYS_VER, will install Buster version of Chromium"
;; ;;
20.04|20.10|21.04|21.10) 20.04|20.10|21.04|21.10)
prnt m " * Detected Ubuntu $SYS_VER, will install Bullseye version of Chromium" prnt m " * Detected Ubuntu $SYS_VER, will install Bullseye version of Chromium"
;; ;;
*) *)
prnt E "Unable to determine the corresponding Debian version." prnt E "Unable to determine the corresponding Debian version."
die 165 die 165
;; ;;
esac esac
} }

View File

@@ -21,12 +21,12 @@ export DEP_install_desktop="upgrade_dist"
install_desktop() install_desktop()
{ {
if [[ -n $X11_DRV ]]; then if [[ -n $X11_DRV ]]; then
prnt I "Installing additionnal X11 drivers..." prnt I "Installing additionnal X11 drivers..."
pkginst $X11_DRV pkginst $X11_DRV
fi fi
if [[ $UBUNTU_FLAVOR ]]; then if [[ $UBUNTU_FLAVOR ]]; then
prnt I "Installing $UBUNTU_FLAVOR environment..." prnt I "Installing $UBUNTU_FLAVOR environment..."
pkginst ${UBUNTU_FLAVOR}-desktop pkginst ${UBUNTU_FLAVOR}-desktop
fi fi
# Because we're lazy but manual actions can avoid reboot... # Because we're lazy but manual actions can avoid reboot...
NEED_REBOOT=true NEED_REBOOT=true
@@ -35,12 +35,12 @@ install_desktop()
precheck_install_desktop() precheck_install_desktop()
{ {
if [[ -z $UBUNTU_FLAVOR ]]; then if [[ -z $UBUNTU_FLAVOR ]]; then
prnt W "No Ubuntu flavor chosen, no desktop environment will be installed!" prnt W "No Ubuntu flavor chosen, no desktop environment will be installed!"
else else
prnt m " * The flavor $UBUNTU_FLAVOR will be installed..." prnt m " * The flavor $UBUNTU_FLAVOR will be installed..."
fi fi
if [[ -n $X11_DRV ]]; then if [[ -n $X11_DRV ]]; then
prnt W "Non free drivers will be installed." prnt W "Non free drivers will be installed."
fi fi
} }

View File

@@ -35,16 +35,16 @@ install_mkagent()
precheck_install_mkagent() precheck_install_mkagent()
{ {
if [[ -z $MK_VERSION ]]; then if [[ -z $MK_VERSION ]]; then
prnt E "Undeclared check_mk version of the agent to install." prnt E "Undeclared check_mk version of the agent to install."
die 162 die 162
fi fi
if [[ -z $MK_URL ]]; then if [[ -z $MK_URL ]]; then
prnt E "Undeclared check_mk download URL." prnt E "Undeclared check_mk download URL."
die 162 die 162
fi fi
if [[ -z $MK_SERVER_IP ]]; then if [[ -z $MK_SERVER_IP ]]; then
prnt E "Undeclared check_mk server." prnt E "Undeclared check_mk server."
die 162 die 162
fi fi
file_must_exists cmk/check_mk cmk/mk_apt file_must_exists cmk/check_mk cmk/mk_apt
} }

View File

@@ -20,28 +20,28 @@ install_pkg()
{ {
# Remove unnecessary packages # Remove unnecessary packages
if [[ -n $PKGS_RMLIST ]]; then if [[ -n $PKGS_RMLIST ]]; then
prnt I "Removing some undesired packages..." prnt I "Removing some undesired packages..."
pkgrm $PKGS_RMLIST pkgrm $PKGS_RMLIST
fi fi
# Blacklist some anoying packages (and remove them if needed) # Blacklist some anoying packages (and remove them if needed)
if [[ -n PKGS_BLACKLIST ]]; then if [[ -n PKGS_BLACKLIST ]]; then
for pkg in $PKGS_BLACKLIST; do for pkg in $PKGS_BLACKLIST; do
prnt I "Placing $pkg into the blacklist..." prnt I "Placing $pkg into the blacklist..."
local dest=/etc/apt/preferences.d/blacklist_$pkg local dest=/etc/apt/preferences.d/blacklist_$pkg
install_file pkgman/blacklist.conf $dest && install_file pkgman/blacklist.conf $dest &&
sed -i -e "s/@pkg@/pkg/" $dest sed -i -e "s/@pkg@/pkg/" $dest
tag_file $dest tag_file $dest
# If blacklisted we suppose uninstall as well (if neeeded) # If blacklisted we suppose uninstall as well (if neeeded)
pkgrm $pkg pkgrm $pkg
done done
fi fi
# Install all the configured packages # Install all the configured packages
if [[ -n $PKGSEL ]]; then if [[ -n $PKGSEL ]]; then
prnt I "Installing the package selection..." prnt I "Installing the package selection..."
pkginst $PKGSEL pkginst $PKGSEL
fi fi
# Cleaning # Cleaning
@@ -52,22 +52,22 @@ install_pkg()
precheck_install_pkg() precheck_install_pkg()
{ {
if [[ -z PKGS_RMLIST ]]; then if [[ -z PKGS_RMLIST ]]; then
prnt m " * No package to remove." prnt m " * No package to remove."
else else
prnt m " * $(echo $PKGS_RMLIST | wc -w) package to remove." prnt m " * $(echo $PKGS_RMLIST | wc -w) package to remove."
fi fi
if [[ -z PKGS_BLACKLIST ]]; then if [[ -z PKGS_BLACKLIST ]]; then
prnt m " * The packages $pkg will be placed into the blacklist !" prnt m " * The packages $pkg will be placed into the blacklist !"
file_must_exists pkgman/blacklist.conf file_must_exists pkgman/blacklist.conf
else else
prnt m " * No package to blacklist." prnt m " * No package to blacklist."
fi fi
if [[ -z $PKGSEL ]]; then if [[ -z $PKGSEL ]]; then
prnt m " * No additionnal package to install !" prnt m " * No additionnal package to install !"
else else
prnt m " * $(echo $PKGSEL | wc -w) additionnal package have to be installed." prnt m " * $(echo $PKGSEL | wc -w) additionnal package have to be installed."
fi fi
} }

View File

@@ -18,16 +18,16 @@ install_profile()
local usrlist="/root" local usrlist="/root"
if find /home -mindepth 1 -maxdepth 1 -type d | read; then if find /home -mindepth 1 -maxdepth 1 -type d | read; then
usrlist="$usrlist /home/*" usrlist="$usrlist /home/*"
fi fi
for usr in $usrlist; do for usr in $usrlist; do
prnt I "Installing profile for user $usr..." prnt I "Installing profile for user $usr..."
backup_dist $usr/{.,}profile $usr/.bashrc backup_dist $usr/{.,}profile $usr/.bashrc
install_file profile/{{.,}profile,.bashrc} $usr/ install_file profile/{{.,}profile,.bashrc} $usr/
tag_file $usr/{{.,}profile,.bashrc} tag_file $usr/{{.,}profile,.bashrc}
install_file profile/.tmux/.tmux.conf{,.local} $usr/ install_file profile/.tmux/.tmux.conf{,.local} $usr/
tag_file $usr/.tmux.conf{,.local} tag_file $usr/.tmux.conf{,.local}
done done
unset usrlist unset usrlist

View File

@@ -16,21 +16,21 @@ patch_snmp()
pkginst snmpd pkginst snmpd
prnt I "Configuring SNMP daemon..." prnt I "Configuring SNMP daemon..."
backup_dist /etc/snmp/snmpd.conf /etc/default/snmpd \ backup_dist /etc/snmp/snmpd.conf /etc/default/snmpd \
/lib/systemd/system/snmpd.service /etc/init.d/snmpd /lib/systemd/system/snmpd.service /etc/init.d/snmpd
install_file snmpd/snmpd.conf /etc/snmp/snmpd.conf install_file snmpd/snmpd.conf /etc/snmp/snmpd.conf
tag_file /etc/snmp/snmpd.conf tag_file /etc/snmp/snmpd.conf
# No longer required with Debian >= 11 or Devuan >= 4 # No longer required with Debian >= 11 or Devuan >= 4
if [[ ($SYS_DIST == 'debian' && $SYS_VER -lt 11) || if [[ ($SYS_DIST == 'debian' && $SYS_VER -lt 11) ||
($SYS_DIST == 'devuan' && $SYS_VER -lt 4) ]]; then ($SYS_DIST == 'devuan' && $SYS_VER -lt 4) ]]; then
install_file snmpd/snmpd.init /etc/init.d/snmpd install_file snmpd/snmpd.init /etc/init.d/snmpd
fi fi
install_file snmpd/snmpd.default /etc/default/snmpd install_file snmpd/snmpd.default /etc/default/snmpd
tag_file /etc/default/snmpd tag_file /etc/default/snmpd
if [[ -e /lib/systemd/system/snmpd.service ]]; then if [[ -e /lib/systemd/system/snmpd.service ]]; then
install_file snmpd/snmpd.service /lib/systemd/system/snmpd.service install_file snmpd/snmpd.service /lib/systemd/system/snmpd.service
if command -v systemctl &> /dev/null; then if command -v systemctl &> /dev/null; then
systemctl daemon-reload systemctl daemon-reload
fi fi
fi fi
svc_restart snmpd svc_restart snmpd
} }
@@ -39,7 +39,7 @@ precheck_patch_snmp()
{ {
file_must_exists snmpd/snmpd.{conf,default} file_must_exists snmpd/snmpd.{conf,default}
if [[ -e /lib/systemd/system/snmpd.service ]]; then if [[ -e /lib/systemd/system/snmpd.service ]]; then
file_must_exists snmpd/snmpd.service file_must_exists snmpd/snmpd.service
fi fi
} }

View File

@@ -36,19 +36,19 @@ upgrade_dist()
prnt I "Configuring proxy for APT..." prnt I "Configuring proxy for APT..."
if [[ -n $PROXY_APT ]]; then if [[ -n $PROXY_APT ]]; then
if [[ ! -d $(dirname $proxyfile) ]]; then if [[ ! -d $(dirname $proxyfile) ]]; then
mkdir -pv $(dirname $proxyfile) || ( mkdir -pv $(dirname $proxyfile) || (
prnt E "Impossible to create directory to receive APT configuration." prnt E "Impossible to create directory to receive APT configuration."
die 60 die 60
) )
fi fi
tag_file $proxyfile tag_file $proxyfile
echo "Acquire::http::Proxy \"http://${PROXY_APT}:${PROXY_APT_PORT}\";" >> $proxyfile echo "Acquire::http::Proxy \"http://${PROXY_APT}:${PROXY_APT_PORT}\";" >> $proxyfile
elif [[ -n $PROXY_SRV ]]; then elif [[ -n $PROXY_SRV ]]; then
tag_file $proxyfile tag_file $proxyfile
echo "Acquire::http::Proxy \"http://${PROXY_SRV}:${PROXY_SRV_PORT}\";" >> $proxyfile echo "Acquire::http::Proxy \"http://${PROXY_SRV}:${PROXY_SRV_PORT}\";" >> $proxyfile
else else
prnt I "No proxy configured, nothing to do." prnt I "No proxy configured, nothing to do."
fi fi
# Remplace source.list from dist with ours (be smarter) # Remplace source.list from dist with ours (be smarter)
@@ -69,16 +69,16 @@ precheck_upgrade_dist()
prnt I "Checking network connectivity..." prnt I "Checking network connectivity..."
if [[ $(noerror wget -q --tries=10 --timeout=20 --spider http://www.tetaneutral.net) != 0 ]]; then if [[ $(noerror wget -q --tries=10 --timeout=20 --spider http://www.tetaneutral.net) != 0 ]]; then
prnt E "It seems network configuration is not functionnal! Giving up." prnt E "It seems network configuration is not functionnal! Giving up."
die 160 die 160
fi fi
if [[ -n $PROXY_APT && -z $PROXY_APT_PORT ]]; then if [[ -n $PROXY_APT && -z $PROXY_APT_PORT ]]; then
prnt E "An APT proxy server have been specified but not its working port." prnt E "An APT proxy server have been specified but not its working port."
die 160 die 160
fi fi
if [[ -n $PROXY_SRV && -z $PROXY_SRV_PORT ]]; then if [[ -n $PROXY_SRV && -z $PROXY_SRV_PORT ]]; then
prnt E "A general proxy server have been specified but not its working port." prnt E "A general proxy server have been specified but not its working port."
die 160 die 160
fi fi
file_must_exists pkgman/${SYS_DIST}_${SYS_VER}.list file_must_exists pkgman/${SYS_DIST}_${SYS_VER}.list
} }