From 33f261d8583de6f9b41b9c33dd15a034a48c5c06 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Fri, 20 Oct 2017 22:36:37 +0200 Subject: [PATCH] Add pre-install script feature --- check_process | 3 +++ package_check.sh | 9 +++++++-- sub_scripts/lxc_force_start.sh | 2 +- sub_scripts/testing_process.sh | 22 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/check_process b/check_process index 56fb1ca..a92e6da 100644 --- a/check_process +++ b/check_process @@ -1,5 +1,8 @@ ;; Nom du test # Commentaire ignoré + ; pre-install + echo -n "Here your commands to execute in the container" + echo ", before each installation of the app." ; Manifest domain="domain.tld" (DOMAIN) path="/path" (PATH) diff --git a/package_check.sh b/package_check.sh index 1f306ce..d9e79f3 100755 --- a/package_check.sh +++ b/package_check.sh @@ -840,7 +840,7 @@ then break; fi # Copy the line in the partial check_process - echo $line >> "$partial_check_process" + echo "$line" >> "$partial_check_process" fi # Search for the first line @@ -899,9 +899,14 @@ then # Extract the section of the current tests serie extract_section "^$tests_serie" "^;;" "$check_process" + partial_check_process=$partial1 + + # Check if there a pre-install instruction for this serie + extract_section "^; pre-install" "^;" "$partial2" + pre_install="$(cat "$partial_check_process")" + # Parse all infos about arguments of manifest # Extract the manifest arguments section from the second partial file - partial_check_process=$partial1 extract_section "^; Manifest" "^; " "$partial2" # Initialize the arguments list diff --git a/sub_scripts/lxc_force_start.sh b/sub_scripts/lxc_force_start.sh index f7d3607..8aa9680 100755 --- a/sub_scripts/lxc_force_start.sh +++ b/sub_scripts/lxc_force_start.sh @@ -38,4 +38,4 @@ echo "Pour établir une connexion ssh:" if [ $(cat "$script_dir/setup_user") = "root" ]; then echo -ne "\e[1msudo " fi -echo -e "\e[1mssh -t $LXC_NAME\e[0m" +echo -e "\e[1mssh -t $LXC_NAME 'bash -i'\e[0m" diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index ee32e47..77c08a3 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -31,6 +31,28 @@ SETUP_APP () { # Uses the default snapshot current_snapshot=snap0 + # Exec the pre-install instruction, if there one + if [ -n "$pre_install" ] + then + ECHO_FORMAT "Pre installation request\n" "white" "bold" clog + # Start the lxc container + LXC_START "true" + # Copy all the instructions into a script + echo "$pre_install" > "$script_dir/preinstall.sh" + chmod +x "$script_dir/preinstall.sh" + # Replace variables + sed -i "s/\$USER/$test_user/" "$script_dir/preinstall.sh" + sed -i "s/\$DOMAIN/$main_domain/" "$script_dir/preinstall.sh" + sed -i "s/\$SUBDOMAIN/$sub_domain/" "$script_dir/preinstall.sh" + sed -i "s/\$PASSWORD/$yuno_pwd/" "$script_dir/preinstall.sh" + # Copy the pre-install script into the container. + scp -rq "$script_dir/preinstall.sh" "$lxc_name": + # Then execute the script to execute the pre-install commands. + LXC_START "./preinstall.sh >&2" + # Print the log to print the results + ECHO_FORMAT "$(cat "$temp_log")\n" clog + fi + # Install the application in a LXC container LXC_START "sudo yunohost --debug app install \"$package_dir\" -a \"$manifest_args_mod\""