From 4805c79d35a4fc5d802066d33be8bc1177665cdd Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 25 Dec 2020 14:52:50 +0100 Subject: [PATCH] Add option to rebuild the base container from ./package_check.sh --- build_base_lxc.sh => lib/build_base_lxc.sh | 7 +- package_check.sh | 76 +++++++++++++--------- 2 files changed, 45 insertions(+), 38 deletions(-) rename build_base_lxc.sh => lib/build_base_lxc.sh (93%) mode change 100755 => 100644 diff --git a/build_base_lxc.sh b/lib/build_base_lxc.sh old mode 100755 new mode 100644 similarity index 93% rename from build_base_lxc.sh rename to lib/build_base_lxc.sh index 0d2a2a3..45c0f02 --- a/build_base_lxc.sh +++ b/lib/build_base_lxc.sh @@ -1,8 +1,5 @@ #!/bin/bash -cd $(dirname $(realpath $0)) -source "./lib/common.sh" - function launch_new_lxc() { lxc info $LXC_BASE >/dev/null && lxc delete $LXC_BASE --force @@ -69,9 +66,7 @@ function rebuild_base_lxc() lxc stop $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 set +x } - -rebuild_base_lxc 2>&1 | tee -a "./build_base_lxc.log" diff --git a/package_check.sh b/package_check.sh index 1277175..0883fa8 100755 --- a/package_check.sh +++ b/package_check.sh @@ -3,18 +3,16 @@ cd $(dirname $(realpath $0)) source "./lib/common.sh" source "./lib/tests_coordination.sh" +source "./lib/build_base_lxc.sh" print_help() { cat << EOF + Usage: package_check.sh [OPTION]... PACKAGE_TO_CHECK -Usage: -package_check.sh [OPTION]... PACKAGE_TO_CHECK - -b, --branch=BRANCH - Specify a branch to check. - -i, --interactive - Wait for the user to continue before each remove. - -h, --help - Display this help + -r, --rebuild (Re)Build the base container + -b, --branch=BRANCH Specify a branch to check. + -i, --interactive Wait for the user to continue before each remove. + -h, --help Display this help EOF exit 0 } @@ -30,6 +28,7 @@ exit 0 gitbranch="" interactive=0 +rebuild=0 function parse_args() { @@ -45,6 +44,7 @@ function parse_args() { fi # For each argument in the array, reduce to short argument for getopts arguments[$i]=${arguments[$i]//--interactive/-i} + arguments[$i]=${arguments[$i]//--rebuild/-r} arguments[$i]=${arguments[$i]//--help/-h} getopts_built_arg+=("${arguments[$i]}") done @@ -72,6 +72,11 @@ function parse_args() { interactive=1 shift_value=1 ;; + r) + # --rebuild + rebuild=1 + shift_value=1 + ;; h) # --help print_help @@ -102,30 +107,6 @@ function parse_args() { arguments=("$@") 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 #================================================= @@ -179,12 +160,43 @@ FETCH_PACKAGE_TO_TEST() { 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 ################################### assert_we_are_connected_to_the_internets 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 fetch_or_upgrade_package_linter