Add option to rebuild the base container from ./package_check.sh

This commit is contained in:
Alexandre Aubin 2020-12-25 14:52:50 +01:00
parent 37292a300e
commit 4805c79d35
2 changed files with 45 additions and 38 deletions

7
build_base_lxc.sh → lib/build_base_lxc.sh Executable file → Normal file
View file

@ -1,8 +1,5 @@
#!/bin/bash #!/bin/bash
cd $(dirname $(realpath $0))
source "./lib/common.sh"
function launch_new_lxc() function launch_new_lxc()
{ {
lxc info $LXC_BASE >/dev/null && lxc delete $LXC_BASE --force lxc info $LXC_BASE >/dev/null && lxc delete $LXC_BASE --force
@ -69,9 +66,7 @@ function rebuild_base_lxc()
lxc stop $LXC_BASE lxc stop $LXC_BASE
lxc image delete $LXC_BASE lxc image delete $LXC_BASE
lxc publish $LXC_BASE --alias $LXC_BASE lxc publish $LXC_BASE --alias $LXC_BASE --public
lxc delete $LXC_BASE lxc delete $LXC_BASE
set +x set +x
} }
rebuild_base_lxc 2>&1 | tee -a "./build_base_lxc.log"

View file

@ -3,18 +3,16 @@
cd $(dirname $(realpath $0)) cd $(dirname $(realpath $0))
source "./lib/common.sh" source "./lib/common.sh"
source "./lib/tests_coordination.sh" source "./lib/tests_coordination.sh"
source "./lib/build_base_lxc.sh"
print_help() { print_help() {
cat << EOF cat << EOF
Usage: package_check.sh [OPTION]... PACKAGE_TO_CHECK
Usage: -r, --rebuild (Re)Build the base container
package_check.sh [OPTION]... PACKAGE_TO_CHECK -b, --branch=BRANCH Specify a branch to check.
-b, --branch=BRANCH -i, --interactive Wait for the user to continue before each remove.
Specify a branch to check. -h, --help Display this help
-i, --interactive
Wait for the user to continue before each remove.
-h, --help
Display this help
EOF EOF
exit 0 exit 0
} }
@ -30,6 +28,7 @@ exit 0
gitbranch="" gitbranch=""
interactive=0 interactive=0
rebuild=0
function parse_args() { function parse_args() {
@ -45,6 +44,7 @@ function parse_args() {
fi fi
# For each argument in the array, reduce to short argument for getopts # For each argument in the array, reduce to short argument for getopts
arguments[$i]=${arguments[$i]//--interactive/-i} arguments[$i]=${arguments[$i]//--interactive/-i}
arguments[$i]=${arguments[$i]//--rebuild/-r}
arguments[$i]=${arguments[$i]//--help/-h} arguments[$i]=${arguments[$i]//--help/-h}
getopts_built_arg+=("${arguments[$i]}") getopts_built_arg+=("${arguments[$i]}")
done done
@ -72,6 +72,11 @@ function parse_args() {
interactive=1 interactive=1
shift_value=1 shift_value=1
;; ;;
r)
# --rebuild
rebuild=1
shift_value=1
;;
h) h)
# --help # --help
print_help print_help
@ -102,30 +107,6 @@ function parse_args() {
arguments=("$@") arguments=("$@")
parse_args parse_args
#=================================================
# Check if the lock file exist
#=================================================
if test -e "$lock_file"
then
# If the lock file exist
echo "The lock file $lock_file is present. Package check would not continue."
if [ $interactive -eq 1 ]; then
echo -n "Do you want to continue anyway? (y/n) :"
read answer
fi
# Set the answer at lowercase only
answer=${answer,,}
if [ "${answer:0:1}" != "y" ]
then
echo "Cancel Package check execution"
exit 0
fi
fi
# Create the lock file
# $$ is the PID of package_check itself.
echo "start:$(date +%s):$$" > "$lock_file"
#================================================= #=================================================
# Pick up the package # Pick up the package
#================================================= #=================================================
@ -179,12 +160,43 @@ FETCH_PACKAGE_TO_TEST() {
fi fi
} }
#=================================================
# Check if the lock file exist
#=================================================
if test -e "$lock_file"
then
# If the lock file exist
echo "The lock file $lock_file is present. Package check would not continue."
if [ $interactive -eq 1 ]; then
echo -n "Do you want to continue anyway? (y/n) :"
read answer
fi
# Set the answer at lowercase only
answer=${answer,,}
if [ "${answer:0:1}" != "y" ]
then
echo "Cancel Package check execution"
exit 0
fi
fi
# Create the lock file
# $$ is the PID of package_check itself.
echo "start:$(date +%s):$$" > "$lock_file"
################################### ###################################
# Main code # Main code
################################### ###################################
assert_we_are_connected_to_the_internets assert_we_are_connected_to_the_internets
assert_we_have_all_dependencies assert_we_have_all_dependencies
if [[ $rebuild == 0 ]]
then
rebuild_base_lxc 2>&1 | tee -a "./build_base_lxc.log"
clean_exit 0
fi
#self_upgrade # FIXME renenable this later #self_upgrade # FIXME renenable this later
fetch_or_upgrade_package_linter fetch_or_upgrade_package_linter