diff --git a/package_check.sh b/package_check.sh index a160cb1..d74ecb6 100755 --- a/package_check.sh +++ b/package_check.sh @@ -13,28 +13,26 @@ if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$( #================================================= clean_exit () { - # Exit and remove all temp files - # $1 = exit code + # Exit and remove all temp files + # $1 = exit code - # Deactivate LXC network - LXC_TURNOFF + # Deactivate LXC network + LXC_TURNOFF - # Remove temporary files - rm -f "$temp_log" - rm -f "$temp_result" - rm -f "$script_dir/url_output" - rm -f "$script_dir/curl_print" - rm -f "$script_dir/manifest_extract" + # Remove temporary files + rm -f "$script_dir/url_output" + rm -f "$script_dir/curl_print" + rm -f "$script_dir/manifest_extract" - # Remove the application which been tested - if [ -n "$package_path" ]; then - rm -rf "$package_path" - fi + # Remove the application which been tested + if [ -n "$package_path" ]; then + rm -rf "$package_path" + fi - # Remove the lock file - rm -f "$lock_file" + # Remove the lock file + rm -f "$lock_file" - exit $1 + exit $1 } #================================================= @@ -55,134 +53,134 @@ show_resources=0 # If no arguments provided if [ "$#" -eq 0 ] then - # Print the help and exit - notice=1 + # Print the help and exit + notice=1 else - # Store arguments in a array to keep each argument separated - arguments=("$@") - getopts_built_arg=() + # Store arguments in a array to keep each argument separated + arguments=("$@") + getopts_built_arg=() - # Read the array value per value - for i in `seq 0 $(( ${#arguments[@]} -1 ))` - do - if [[ "${arguments[$i]}" =~ "--branch=" ]] - then - getopts_built_arg+=(-b) - arguments[$i]=${arguments[$i]//--branch=/} - fi - # For each argument in the array, reduce to short argument for getopts - arguments[$i]=${arguments[$i]//--force-install-ok/-f} - arguments[$i]=${arguments[$i]//--interrupt/-i} - arguments[$i]=${arguments[$i]//--help/-h} - arguments[$i]=${arguments[$i]//--build-lxc/-l} - arguments[$i]=${arguments[$i]//--bash-mode/-y} - arguments[$i]=${arguments[$i]//--show-resources/-r} - getopts_built_arg+=("${arguments[$i]}") - done + # Read the array value per value + for i in `seq 0 $(( ${#arguments[@]} -1 ))` + do + if [[ "${arguments[$i]}" =~ "--branch=" ]] + then + getopts_built_arg+=(-b) + arguments[$i]=${arguments[$i]//--branch=/} + fi + # For each argument in the array, reduce to short argument for getopts + arguments[$i]=${arguments[$i]//--force-install-ok/-f} + arguments[$i]=${arguments[$i]//--interrupt/-i} + arguments[$i]=${arguments[$i]//--help/-h} + arguments[$i]=${arguments[$i]//--build-lxc/-l} + arguments[$i]=${arguments[$i]//--bash-mode/-y} + arguments[$i]=${arguments[$i]//--show-resources/-r} + getopts_built_arg+=("${arguments[$i]}") + done - # Read and parse all the arguments - # Use a function here, to use standart arguments $@ and be able to use shift. - parse_arg () { - while [ $# -ne 0 ] - do - # If the paramater begins by -, treat it with getopts - if [ "${1:0:1}" == "-" ] - then - # Initialize the index of getopts - OPTIND=1 - # Parse with getopts only if the argument begin by - - getopts ":b:fihlyr" parameter || true - case $parameter in - b) - # --branch=branch-name - gitbranch="-b $OPTARG" - shift_value=2 - ;; - f) - # --force-install-ok - force_install_ok=1 - shift_value=1 - ;; - i) - # --interrupt - interrupt=1 - shift_value=1 - ;; - h) - # --help - notice=1 - shift_value=1 - ;; - l) - # --build-lxc - build_lxc=1 - shift_value=1 - ;; - y) - # --bash-mode - bash_mode=1 - shift_value=1 - ;; - r) - # --show-resources - show_resources=1 - shift_value=1 - ;; - \?) - echo "Invalid argument: -${OPTARG:-}" - notice=1 - shift_value=1 - ;; - :) - echo "-$OPTARG parameter requires an argument." - notice=1 - shift_value=1 - ;; - esac - # Otherwise, it's not an option, it's an operand - else - app_arg="$1" - shift_value=1 - fi - # Shift the parameter and its argument - shift $shift_value - done - } + # Read and parse all the arguments + # Use a function here, to use standart arguments $@ and be able to use shift. + parse_arg () { + while [ $# -ne 0 ] + do + # If the paramater begins by -, treat it with getopts + if [ "${1:0:1}" == "-" ] + then + # Initialize the index of getopts + OPTIND=1 + # Parse with getopts only if the argument begin by - + getopts ":b:fihlyr" parameter || true + case $parameter in + b) + # --branch=branch-name + gitbranch="-b $OPTARG" + shift_value=2 + ;; + f) + # --force-install-ok + force_install_ok=1 + shift_value=1 + ;; + i) + # --interrupt + interrupt=1 + shift_value=1 + ;; + h) + # --help + notice=1 + shift_value=1 + ;; + l) + # --build-lxc + build_lxc=1 + shift_value=1 + ;; + y) + # --bash-mode + bash_mode=1 + shift_value=1 + ;; + r) + # --show-resources + show_resources=1 + shift_value=1 + ;; + \?) + echo "Invalid argument: -${OPTARG:-}" + notice=1 + shift_value=1 + ;; + :) + echo "-$OPTARG parameter requires an argument." + notice=1 + shift_value=1 + ;; + esac + # Otherwise, it's not an option, it's an operand + else + app_arg="$1" + shift_value=1 + fi + # Shift the parameter and its argument + shift $shift_value + done + } - # Call parse_arg and pass the modified list of args as a array of arguments. - parse_arg "${getopts_built_arg[@]}" + # Call parse_arg and pass the modified list of args as a array of arguments. + parse_arg "${getopts_built_arg[@]}" fi # Prevent a conflict between --interrupt and --bash-mode if [ $interrupt -eq 1 ] && [ $bash_mode -eq 1 ] then - echo "You can't use --interrupt and --bash-mode together !" - notice=1 + echo "You can't use --interrupt and --bash-mode together !" + notice=1 fi # Print help if [ $notice -eq 1 ] then - cat << EOF + cat << EOF Usage: package_check.sh [OPTION]... PACKAGE_TO_CHECK - -b, --branch=BRANCH - Specify a branch to check. - -f, --force-install-ok - Force remaining tests even if installation tests failed or were not selected for execution. - -i, --interrupt - Force auto_remove value, break before each remove. - -h, --help - Display this notice. - -l, --build-lxc - Install LXC and build the container if necessary. - -y, --bash-mode - Do not ask for continue check. Ignore auto_remove. - -r, --show-resources - Show the unavailable resources when accessing the url. + -b, --branch=BRANCH + Specify a branch to check. + -f, --force-install-ok + Force remaining tests even if installation tests failed or were not selected for execution. + -i, --interrupt + Force auto_remove value, break before each remove. + -h, --help + Display this notice. + -l, --build-lxc + Install LXC and build the container if necessary. + -y, --bash-mode +Do not ask for continue check. Ignore auto_remove. + -r, --show-resources + Show the unavailable resources when accessing the url. EOF - exit 0 +exit 0 fi #================================================= @@ -193,19 +191,19 @@ lock_file="$script_dir/pcheck.lock" 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 [ $bash_mode -ne 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 + # If the lock file exist + echo "The lock file $lock_file is present. Package check would not continue." + if [ $bash_mode -ne 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. @@ -218,17 +216,17 @@ echo "start:$(date +%s):$$" > "$lock_file" # Try to ping yunohost.org ping -q -c 2 yunohost.org > /dev/null 2>&1 if [ "$?" -ne 0 ]; then - # If fail, try to ping another domain - ping -q -c 2 framasoft.org > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then - # If ping failed twice, it's seems the internet connection is down. - echo "\e[91mUnable to connect to internet.\e[0m" + # If fail, try to ping another domain + ping -q -c 2 framasoft.org > /dev/null 2>&1 + if [ "$?" -ne 0 ]; then + # If ping failed twice, it's seems the internet connection is down. + echo "\e[91mUnable to connect to internet.\e[0m" - # Remove the lock file - rm -f "$lock_file" - # And exit - exit 1 - fi + # Remove the lock file + rm -f "$lock_file" + # And exit + exit 1 + fi fi #================================================= @@ -243,14 +241,14 @@ check_version="$(git ls-remote $git_repository | cut -f 1 | head -n1)" # If the version file exist, check for an upgrade if [ -e "$version_file" ] then - # Check if the last commit on the repository match with the current version - if [ "$check_version" != "$(cat "$version_file")" ] - then - # If the versions don't matches. Do an upgrade - echo -e "\e[97m\e[1mUpgrade Package check...\n\e[0m" + # Check if the last commit on the repository match with the current version + if [ "$check_version" != "$(cat "$version_file")" ] + then + # If the versions don't matches. Do an upgrade + echo -e "\e[97m\e[1mUpgrade Package check...\n\e[0m" - # Build the upgrade script - cat > "$script_dir/upgrade_script.sh" << EOF + # Build the upgrade script + cat > "$script_dir/upgrade_script.sh" << EOF #!/bin/bash # Clone in another directory @@ -264,19 +262,19 @@ rm "$script_dir/pcheck.lock" exec "$script_dir/package_check.sh" "${arguments[@]}" EOF - # Give the execution right - chmod +x "$script_dir/upgrade_script.sh" +# Give the execution right +chmod +x "$script_dir/upgrade_script.sh" - # Temporary upgrade fix - # Check if lynx is already installed. - if [ ! -e "$(which lynx)" ] - then - sudo apt-get install -y lynx - fi +# Temporary upgrade fix +# Check if lynx is already installed. +if [ ! -e "$(which lynx)" ] +then + sudo apt-get install -y lynx +fi - # Start the upgrade script by replacement of this process - exec "$script_dir/upgrade_script.sh" - fi +# Start the upgrade script by replacement of this process +exec "$script_dir/upgrade_script.sh" + fi fi # Update the version file @@ -294,24 +292,24 @@ check_version="$(git ls-remote $git_repository | cut -f 1 | head -n1)" # If the version file exist, check for an upgrade if [ -e "$version_file" ] then - # Check if the last commit on the repository match with the current version - if [ "$check_version" != "$(cat "$version_file")" ] - then - # If the versions don't matches. Do an upgrade - echo -e "\e[97m\e[1mUpgrade Package linter...\n\e[0m" + # Check if the last commit on the repository match with the current version + if [ "$check_version" != "$(cat "$version_file")" ] + then + # If the versions don't matches. Do an upgrade + echo -e "\e[97m\e[1mUpgrade Package linter...\n\e[0m" - # Clone in another directory - git clone --quiet https://github.com/YunoHost/package_linter "$script_dir/package_linter_tmp" - pip3 install pyparsing six + # Clone in another directory + git clone --quiet https://github.com/YunoHost/package_linter "$script_dir/package_linter_tmp" + pip3 install pyparsing six - # And replace - cp -a "$script_dir/package_linter_tmp/." "$script_dir/package_linter/." - sudo rm -r "$script_dir/package_linter_tmp" - fi + # And replace + cp -a "$script_dir/package_linter_tmp/." "$script_dir/package_linter/." + sudo rm -r "$script_dir/package_linter_tmp" + fi else - echo -e "\e[97mInstall Package linter.\n\e[0m" - git clone --quiet $git_repository "$script_dir/package_linter" - pip3 install pyparsing six + echo -e "\e[97mInstall Package linter.\n\e[0m" + git clone --quiet $git_repository "$script_dir/package_linter" + pip3 install pyparsing six fi # Update the version file @@ -326,63 +324,63 @@ build_script="$script_dir/sub_scripts/lxc_build.sh" if [ -e "$pcheck_config" ] then - # Read the config file if it exists - ip_range=$(grep PLAGE_IP= "$pcheck_config" | cut -d '=' -f2) - main_domain=$(grep DOMAIN= "$pcheck_config" | cut -d '=' -f2) - yuno_pwd=$(grep YUNO_PWD= "$pcheck_config" | cut -d '=' -f2) - lxc_name=$(grep LXC_NAME= "$pcheck_config" | cut -d '=' -f2) - lxc_bridge=$(grep LXC_BRIDGE= "$pcheck_config" | cut -d '=' -f2) - main_iface=$(grep iface= "$pcheck_config" | cut -d '=' -f2) + # Read the config file if it exists + ip_range=$(grep PLAGE_IP= "$pcheck_config" | cut -d '=' -f2) + main_domain=$(grep DOMAIN= "$pcheck_config" | cut -d '=' -f2) + yuno_pwd=$(grep YUNO_PWD= "$pcheck_config" | cut -d '=' -f2) + lxc_name=$(grep LXC_NAME= "$pcheck_config" | cut -d '=' -f2) + lxc_bridge=$(grep LXC_BRIDGE= "$pcheck_config" | cut -d '=' -f2) + main_iface=$(grep iface= "$pcheck_config" | cut -d '=' -f2) fi # Use the default value and set it in the config file replace_default_value () { - CONFIG_KEY=$1 - local value=$(grep "|| $CONFIG_KEY=" "$build_script" | cut -d '=' -f2) - if grep -q $CONFIG_KEY= "$pcheck_config" - then - sed -i "s/$CONFIG_KEY=.*/$CONFIG_KEY=$value/" "$pcheck_config" - else - echo -e "$CONFIG_KEY=$value\n" >> "$pcheck_config" - fi - echo $value + CONFIG_KEY=$1 + local value=$(grep "|| $CONFIG_KEY=" "$build_script" | cut -d '=' -f2) + if grep -q $CONFIG_KEY= "$pcheck_config" + then + sed -i "s/$CONFIG_KEY=.*/$CONFIG_KEY=$value/" "$pcheck_config" + else + echo -e "$CONFIG_KEY=$value\n" >> "$pcheck_config" + fi + echo $value } # Use default value from the build script if needed if [ -z "$ip_range" ]; then - ip_range=$(replace_default_value PLAGE_IP) + ip_range=$(replace_default_value PLAGE_IP) fi if [ -z "$main_domain" ]; then - main_domain=$(replace_default_value DOMAIN) + main_domain=$(replace_default_value DOMAIN) fi if [ -z "$yuno_pwd" ]; then - yuno_pwd=$(replace_default_value YUNO_PWD) + yuno_pwd=$(replace_default_value YUNO_PWD) fi if [ -z "$lxc_name" ]; then - lxc_name=$(replace_default_value LXC_NAME) + lxc_name=$(replace_default_value LXC_NAME) fi if [ -z "$lxc_bridge" ]; then - lxc_bridge=$(replace_default_value LXC_BRIDGE) + lxc_bridge=$(replace_default_value LXC_BRIDGE) fi if [ -z "$main_iface" ]; then - # Try to determine the main iface - main_iface=$(sudo ip route | grep default | awk '{print $5;}') - if [ -z $main_iface ] - then - echo -e "\e[91mUnable to find the name of the main iface.\e[0m" + # Try to determine the main iface + main_iface=$(sudo ip route | grep default | awk '{print $5;}') + if [ -z $main_iface ] + then + echo -e "\e[91mUnable to find the name of the main iface.\e[0m" - # Remove the lock file - rm -f "$lock_file" - # And exit - exit 1 - fi - # Store the main iface in the config file - if grep -q iface= "$pcheck_config" - then - sed -i "s/iface=.*/iface=$main_iface/" - else - echo -e "# Main host iface\niface=$main_iface\n" >> "$pcheck_config" - fi + # Remove the lock file + rm -f "$lock_file" + # And exit + exit 1 + fi + # Store the main iface in the config file + if grep -q iface= "$pcheck_config" + then + sed -i "s/iface=.*/iface=$main_iface/" + else + echo -e "# Main host iface\niface=$main_iface\n" >> "$pcheck_config" + fi fi #================================================= @@ -392,15 +390,15 @@ fi setup_user_file="$script_dir/sub_scripts/setup_user" if [ -e "$setup_user_file" ] then - # Compare the current user and the user stored in $setup_user_file - authorised_user="$(cat "$setup_user_file")" - if [ "$(whoami)" != "$authorised_user" ] - then - echo -e "\e[91mThis script need to be executed by the user $setup_user_file !\nThe current user is $(whoami).\e[0m" - clean_exit 1 - fi + # Compare the current user and the user stored in $setup_user_file + authorised_user="$(cat "$setup_user_file")" + if [ "$(whoami)" != "$authorised_user" ] + then + echo -e "\e[91mThis script need to be executed by the user $setup_user_file !\nThe current user is $(whoami).\e[0m" + clean_exit 1 + fi else - echo -e "\e[93mUnable to define the user who authorised to use package check. Please fill the file $setup_user_file\e[0m" + echo -e "\e[93mUnable to define the user who authorised to use package check. Please fill the file $setup_user_file\e[0m" fi #================================================= @@ -409,12 +407,6 @@ fi # Complete result log. Complete log of YunoHost complete_log="$script_dir/Complete.log" -# Partial YunoHost log, just the log for the current test -temp_log="$script_dir/temp_yunohost-cli.log" -# Temporary result log -temp_result="$script_dir/temp_result.log" -# Result log with warning and error only -test_result="$script_dir/Test_results.log" # Real YunoHost log yunohost_log="/var/lib/lxc/$lxc_name/rootfs/var/log/yunohost/yunohost-cli.log" @@ -425,9 +417,9 @@ test_user=package_checker # Load all functions #================================================= +source "$script_dir/sub_scripts/common.sh" source "$script_dir/sub_scripts/launcher.sh" source "$script_dir/sub_scripts/testing_process.sh" -source "$script_dir/sub_scripts/log_extractor.sh" #================================================= # Check LXC @@ -436,29 +428,29 @@ source "$script_dir/sub_scripts/log_extractor.sh" # Check if lxc is already installed if dpkg-query -W -f '${Status}' "lxc" 2>/dev/null | grep -q "ok installed" then - # If lxc is installed, check if the container is already built. - if ! sudo lxc-ls | grep -q "$lxc_name" - then - if [ $build_lxc -eq 1 ] - then - # If lxc's not installed and build_lxc set. Asks to build the container. - build_lxc=2 - else - ECHO_FORMAT "LXC is not installed or the container $lxc_name doesn't exist.\n" "red" - ECHO_FORMAT "Use the script 'lxc_build.sh' to fix them.\n" "red" - clean_exit 1 - fi - fi + # If lxc is installed, check if the container is already built. + if ! sudo lxc-ls | grep -q "$lxc_name" + then + if [ $build_lxc -eq 1 ] + then + # If lxc's not installed and build_lxc set. Asks to build the container. + build_lxc=2 + else + critical "LXC is not installed or the container $lxc_name doesn't exist." + critical "Use the script 'lxc_build.sh' to fix them." + clean_exit 1 + fi + fi elif [ $build_lxc -eq 1 ] then - # If lxc's not installed and build_lxc set. Asks to build the container. - build_lxc=2 + # If lxc's not installed and build_lxc set. Asks to build the container. + build_lxc=2 fi if [ $build_lxc -eq 2 ] then - # Install LXC and build the container before continue. - "$script_dir/sub_scripts/lxc_build.sh" + # Install LXC and build the container before continue. + "$script_dir/sub_scripts/lxc_build.sh" fi # Stop and restore the LXC container. In case of previous incomplete execution. @@ -474,13 +466,13 @@ LXC_TURNOFF type_exec_env=0 if [ -e "$script_dir/../config" ] then - # CI environment - type_exec_env=1 + # CI environment + type_exec_env=1 fi if [ -e "$script_dir/../auto_build/auto.conf" ] then - # Official CI environment - type_exec_env=2 + # Official CI environment + type_exec_env=2 fi #================================================= @@ -496,13 +488,11 @@ then app_arg="${app_arg%%/tree/*}" fi -ECHO_FORMAT "Test the package $app_arg" "blue" "bold" if [ -n "$gitbranch" ] then - ECHO_FORMAT " on the branch ${gitbranch##-b }.\n" "blue" "bold" -else - ECHO_FORMAT ".\n" "blue" "bold" + branch_msg=" on the branch ${gitbranch##-b }" fi +info "Test the package $app_arg $branch_msg" # Remove the previous package if it's still here. rm -rf "$script_dir"/*_check @@ -524,24 +514,24 @@ then then gitbranch="-b stable" else - ECHO_FORMAT "Unable to find a default branch to test (master or stable)" "red" + critical "Unable to find a default branch to test (master or stable)" clean_exit 1 fi fi fi - # Clone the repository - git clone $app_arg $gitbranch "$package_path" + # Clone the repository + git clone $app_arg $gitbranch "$package_path" -# If it's a local directory + # If it's a local directory else - # Do a copy in the directory of Package check - cp -a "$app_arg" "$package_path" + # Do a copy in the directory of Package check + cp -a "$app_arg" "$package_path" fi # Check if the package directory is really here. if [ ! -d "$package_path" ]; then - ECHO_FORMAT "Unable to find the directory $package_path for the package...\n" "red" - clean_exit 1 + critical "Unable to find the directory $package_path for the package..." + clean_exit 1 fi @@ -553,195 +543,188 @@ fi TEST_RESULTS () { - # Print the test result - print_result () { - # Print the name of the test - ECHO_FORMAT "$1: " + # Print the test result + print_result () { - # Complete with spaces according to the lenght of the previous string. To align the results - local i=0 - for i in `seq ${#1} 30` - do - echo -n " " - done + # Print the result of this test + # we use printf to force the length to 30 (filled with space) + testname=$(printf %-30.30s "$1:") + if [ $2 -eq 1 ] + then + echo "$testname ${BOLD}${GREEN}SUCCESS${NORMAL}" + elif [ $2 -eq -1 ] + then + echo "$testname ${BOLD}${RED}FAIL${NORMAL}" + else + echo "$testname Not evaluated." + fi + } - # Print the result of this test - if [ $2 -eq 1 ] - then - ECHO_FORMAT "SUCCESS\n" "lgreen" - elif [ $2 -eq -1 ] - then - ECHO_FORMAT "FAIL\n" "red" - else - ECHO_FORMAT "Not evaluated.\n" "white" - fi - } - - # Print the result for each test - echo -e "\n\n" - print_result "Package linter" $RESULT_linter - print_result "Install" $RESULT_global_setup - print_result "Remove" $RESULT_global_remove + # Print the result for each test + echo -e "\n\n" + print_result "Package linter" $RESULT_linter + print_result "Install" $RESULT_global_setup + print_result "Remove" $RESULT_global_remove print_result "Install (subpath)" $RESULT_check_sub_dir print_result "Remove (subpath)" $RESULT_check_remove_sub_dir print_result "Install (root)" $RESULT_check_root print_result "Remove (root)" $RESULT_check_remove_root - print_result "Upgrade" $RESULT_check_upgrade + print_result "Upgrade" $RESULT_check_upgrade print_result "Install (private mode)" $RESULT_check_private print_result "Install (public mode)" $RESULT_check_public print_result "Install (multi-instance)" $RESULT_check_multi_instance - print_result "Port already used" $RESULT_check_port - print_result "Backup" $RESULT_check_backup - print_result "Restore" $RESULT_check_restore - print_result "Change URL" $RESULT_change_url - print_result "Actions and config-panel" $RESULT_action_config_panel + print_result "Port already used" $RESULT_check_port + print_result "Backup" $RESULT_check_backup + print_result "Restore" $RESULT_check_restore + print_result "Change URL" $RESULT_change_url + print_result "Actions and config-panel" $RESULT_action_config_panel - # Determine the level for this app + # Determine the level for this app - # Each level can has 5 different values - # 0 -> If this level can't be validated - # 1 -> If this level is forced. Even if the tests fails - # 2 -> Indicates the tests had previously validated this level - # auto -> This level has not a value yet. - # na -> This level will not be checked, but it'll be ignored in the final sum + # Each level can has 5 different values + # 0 -> If this level can't be validated + # 1 -> If this level is forced. Even if the tests fails + # 2 -> Indicates the tests had previously validated this level + # auto -> This level has not a value yet. + # na -> This level will not be checked, but it'll be ignored in the final sum - # Set default values for level, if they're empty. - test -n "${level[1]}" || level[1]=auto - test -n "${level[2]}" || level[2]=auto - test -n "${level[3]}" || level[3]=auto - test -n "${level[4]}" || level[4]=auto - test -n "${level[5]}" || level[5]=auto - test -n "${level[5]}" || level[5]=auto - test -n "${level[6]}" || level[6]=auto - test -n "${level[7]}" || level[7]=auto - test -n "${level[8]}" || level[8]=0 - test -n "${level[9]}" || level[9]=0 - test -n "${level[10]}" || level[10]=0 + # Set default values for level, if they're empty. + test -n "${level[1]}" || level[1]=auto + test -n "${level[2]}" || level[2]=auto + test -n "${level[3]}" || level[3]=auto + test -n "${level[4]}" || level[4]=auto + test -n "${level[5]}" || level[5]=auto + test -n "${level[5]}" || level[5]=auto + test -n "${level[6]}" || level[6]=auto + test -n "${level[7]}" || level[7]=auto + test -n "${level[8]}" || level[8]=0 + test -n "${level[9]}" || level[9]=0 + test -n "${level[10]}" || level[10]=0 - # Check if the level can be changed - level_can_change () { - # If the level is set at auto, it's waiting for a change - # And if it's set at 2, its value can be modified by a new result - if [ "${level[$1]}" == "auto" ] || [ "${level[$1]}" -eq 2 ] - then - return 0 - fi - return 1 - } - - # Evaluate the first level - # -> The package can be install and remove. - if level_can_change 1 - then - # Validated if at least one install and remove work fine - if [ $RESULT_global_setup -eq 1 ] && \ - [ $RESULT_global_remove -eq 1 ] - then level[1]=2 - else level[1]=0 - fi - fi - - # Evaluate the second level - # -> The package can be install and remove in all tested configurations. - if level_can_change 2 - then - # Validated if none install failed - if [ $RESULT_check_sub_dir -ne -1 ] && \ - [ $RESULT_check_remove_sub_dir -ne -1 ] && \ - [ $RESULT_check_root -ne -1 ] && \ - [ $RESULT_check_remove_root -ne -1 ] && \ - [ $RESULT_check_private -ne -1 ] && \ - [ $RESULT_check_public -ne -1 ] && \ - [ $RESULT_check_multi_instance -ne -1 ] - then level[2]=2 - else level[2]=0 - fi - fi - - # Evaluate the third level - # -> The package can be upgraded from the same version. - if level_can_change 3 - then - # Validated if the upgrade is ok. Or if the upgrade has been not tested but already validated before. - if [ $RESULT_check_upgrade -eq 1 ] || \ - ( [ $RESULT_check_upgrade -ne -1 ] && \ - [ "${level[3]}" == "2" ] ) - then level[3]=2 - else level[3]=0 - fi - fi - - # Evaluate the fourth level - # -> The package can be backup and restore without error - if level_can_change 4 - then - # Validated if backup and restore are ok. Or if backup and restore have been not tested but already validated before. - if ( [ $RESULT_check_backup -eq 1 ] && \ - [ $RESULT_check_restore -eq 1 ] ) || \ - ( [ $RESULT_check_backup -ne -1 ] && \ - [ $RESULT_check_restore -ne -1 ] && \ - [ "${level[4]}" == "2" ] ) - then level[4]=2 - else level[4]=0 - fi - fi - - # Evaluate the fifth level - # -> The package have no error with package linter - # -> The package does not have any alias_traversal error - if level_can_change 5 - then - # Validated if Linter is ok. Or if Linter has been not tested but already validated before. - if [ $RESULT_linter -ge 1 ] || \ - ( [ $RESULT_linter -eq 0 ] && \ - [ "${level[5]}" == "2" ] ) - then level[5]=2 - else level[5]=0 - fi - if [ $RESULT_alias_traversal -eq 1 ] - then - level[5]=0 - fi - fi - - # Evaluate the sixth level - # -> The package can be backup and restore without error - if level_can_change 6 - then - # This is from the linter, tests if app is the Yunohost-apps organization - if [ $RESULT_linter_level_6 -eq 1 ] - then level[6]=2 - else level[6]=0 + # Check if the level can be changed + level_can_change () { + # If the level is set at auto, it's waiting for a change + # And if it's set at 2, its value can be modified by a new result + if [ "${level[$1]}" == "auto" ] || [ "${level[$1]}" -eq 2 ] + then + return 0 fi + return 1 + } + + # Evaluate the first level + # -> The package can be install and remove. + if level_can_change 1 + then + # Validated if at least one install and remove work fine + if [ $RESULT_global_setup -eq 1 ] && \ + [ $RESULT_global_remove -eq 1 ] + then level[1]=2 + else level[1]=0 + fi +fi + +# Evaluate the second level +# -> The package can be install and remove in all tested configurations. +if level_can_change 2 +then + # Validated if none install failed + if [ $RESULT_check_sub_dir -ne -1 ] && \ + [ $RESULT_check_remove_sub_dir -ne -1 ] && \ + [ $RESULT_check_root -ne -1 ] && \ + [ $RESULT_check_remove_root -ne -1 ] && \ + [ $RESULT_check_private -ne -1 ] && \ + [ $RESULT_check_public -ne -1 ] && \ + [ $RESULT_check_multi_instance -ne -1 ] +then level[2]=2 +else level[2]=0 +fi fi - # Evaluate the seventh level - # -> None errors in all tests performed - if level_can_change 7 + # Evaluate the third level + # -> The package can be upgraded from the same version. + if level_can_change 3 then - level[7]=0 - # Validated if none errors is happened. - if [ $RESULT_global_setup -ne -1 ] && \ - [ $RESULT_global_remove -ne -1 ] && \ - [ $RESULT_check_sub_dir -ne -1 ] && \ - [ $RESULT_check_remove_sub_dir -ne -1 ] && \ - [ $RESULT_check_remove_root -ne -1 ] && \ - [ $RESULT_check_upgrade -ne -1 ] && \ - [ $RESULT_check_private -ne -1 ] && \ - [ $RESULT_check_public -ne -1 ] && \ - [ $RESULT_check_multi_instance -ne -1 ] && \ - [ $RESULT_check_path -ne -1 ] && \ - [ $RESULT_check_port -ne -1 ] && \ - [ $RESULT_check_backup -ne -1 ] && \ - [ $RESULT_check_restore -ne -1 ] && \ - [ $RESULT_change_url -ne -1 ] && \ - [ $RESULT_action_config_panel -ne -1 ] && \ - [ $RESULT_linter_level_7 -ge 1 ] - then - level[7]=2 - fi + # Validated if the upgrade is ok. Or if the upgrade has been not tested but already validated before. + if [ $RESULT_check_upgrade -eq 1 ] || \ + ( [ $RESULT_check_upgrade -ne -1 ] && \ + [ "${level[3]}" == "2" ] ) + then level[3]=2 + else level[3]=0 + fi +fi + +# Evaluate the fourth level +# -> The package can be backup and restore without error +if level_can_change 4 +then + # Validated if backup and restore are ok. Or if backup and restore have been not tested but already validated before. + if ( [ $RESULT_check_backup -eq 1 ] && \ + [ $RESULT_check_restore -eq 1 ] ) || \ + ( [ $RESULT_check_backup -ne -1 ] && \ + [ $RESULT_check_restore -ne -1 ] && \ + [ "${level[4]}" == "2" ] ) +then level[4]=2 +else level[4]=0 +fi + fi + + # Evaluate the fifth level + # -> The package have no error with package linter + # -> The package does not have any alias_traversal error + if level_can_change 5 + then + # Validated if Linter is ok. Or if Linter has been not tested but already validated before. + if [ $RESULT_linter -ge 1 ] || \ + ( [ $RESULT_linter -eq 0 ] && \ + [ "${level[5]}" == "2" ] ) + then level[5]=2 + else level[5]=0 + fi + if [ $RESULT_alias_traversal -eq 1 ] + then + level[5]=0 + fi +fi + +# Evaluate the sixth level +# -> The package can be backup and restore without error +if level_can_change 6 +then + # This is from the linter, tests if app is the Yunohost-apps organization + if [ $RESULT_linter_level_6 -eq 1 ] + then level[6]=2 + else level[6]=0 + fi +fi + +# Evaluate the seventh level +# -> None errors in all tests performed +if level_can_change 7 +then + level[7]=0 + # Validated if none errors is happened. + if [ $RESULT_global_setup -ne -1 ] && \ + [ $RESULT_global_remove -ne -1 ] && \ + [ $RESULT_check_sub_dir -ne -1 ] && \ + [ $RESULT_check_remove_sub_dir -ne -1 ] && \ + [ $RESULT_check_remove_root -ne -1 ] && \ + [ $RESULT_check_upgrade -ne -1 ] && \ + [ $RESULT_check_private -ne -1 ] && \ + [ $RESULT_check_public -ne -1 ] && \ + [ $RESULT_check_multi_instance -ne -1 ] && \ + [ $RESULT_check_path -ne -1 ] && \ + [ $RESULT_check_port -ne -1 ] && \ + [ $RESULT_check_backup -ne -1 ] && \ + [ $RESULT_check_restore -ne -1 ] && \ + [ $RESULT_change_url -ne -1 ] && \ + [ $RESULT_action_config_panel -ne -1 ] && \ + [ $RESULT_linter_level_7 -ge 1 ] +then + level[7]=2 +fi fi # Evaluate the eighth level @@ -772,82 +755,76 @@ TEST_RESULTS () { fi fi - # Evaluate the tenth level - # -> Not available yet... - level[10]=0 + # Evaluate the tenth level + # -> Not available yet... + level[10]=0 - # Initialize the global level - global_level=0 + # Initialize the global level + global_level=0 - # Calculate the final level - for i in `seq 1 10` - do + # Calculate the final level + for i in `seq 1 10` + do - # If there is a level still at 'auto', it's a mistake. - if [ "${level[i]}" == "auto" ] - then - # So this level will set at 0. - level[i]=0 + # If there is a level still at 'auto', it's a mistake. + if [ "${level[i]}" == "auto" ] + then + # So this level will set at 0. + level[i]=0 - # If the level is at 'na', it will be ignored - elif [ "${level[i]}" == "na" ] - then - continue + # If the level is at 'na', it will be ignored + elif [ "${level[i]}" == "na" ] + then + continue - # If the level is at 1 or 2. The global level will be set at this level - elif [ "${level[i]}" -ge 1 ] - then - global_level=$i + # If the level is at 1 or 2. The global level will be set at this level + elif [ "${level[i]}" -ge 1 ] + then + global_level=$i - # But, if the level is at 0, the loop stop here - # Like that, the global level rise while none level have failed - else - break - fi - done + # But, if the level is at 0, the loop stop here + # Like that, the global level rise while none level have failed + else + break + fi + done - # If some witness files was missing, it's a big error ! So, the level fall immediately at 0. - if [ $RESULT_witness -eq 1 ] - then - ECHO_FORMAT "Some witness files has been deleted during those tests ! It's a very bad thing !\n" "red" "bold" - global_level=0 - fi + # If some witness files was missing, it's a big error ! So, the level fall immediately at 0. + if [ $RESULT_witness -eq 1 ] + then + error "Some witness files has been deleted during those tests ! It's a very bad thing !" + global_level=0 + fi - # If the package linter returned a critical error, the app is flagged as broken / level 0 - if [ $RESULT_linter -le -2 ] - then - ECHO_FORMAT "The package linter reported a critical failure ! App is considered broken !\n" "red" "bold" - global_level=0 - fi + # If the package linter returned a critical error, the app is flagged as broken / level 0 + if [ $RESULT_linter -le -2 ] + then + error "The package linter reported a critical failure ! App is considered broken !" + global_level=0 + fi - if [ $RESULT_alias_traversal -eq 1 ] - then - ECHO_FORMAT "Issue alias_traversal was detected ! Please see here https://github.com/YunoHost/example_ynh/pull/45 to fix that.\n" "red" "bold" - fi + if [ $RESULT_alias_traversal -eq 1 ] + then + error "Issue alias_traversal was detected ! Please see here https://github.com/YunoHost/example_ynh/pull/45 to fix that." + fi - if [ $RESULT_template -eq 1 ] - then - ECHO_FORMAT "This package does not fully respect the template.\nYou should consider upgrade your package to respect the template of the example app.\n" "red" "bold" - fi + # Then, print the levels + # Print the global level + verbose_level=$(grep "^$global_level " "$script_dir/levels.list" | cut -c4-) - # Then, print the levels - # Print the global level - verbose_level=$(grep "^$global_level " "$script_dir/levels.list" | cut -c4-) + info "Level of this application: $global_level ($verbose_level)" - ECHO_FORMAT "Level of this application: $global_level ($verbose_level)\n" "white" "bold" - - # And print the value for each level - for i in `seq 1 10` - do - ECHO_FORMAT "\t Level $i: " - if [ "${level[$i]}" == "na" ]; then - ECHO_FORMAT "N/A\n" - elif [ "${level[$i]}" -ge 1 ]; then - ECHO_FORMAT "1\n" "white" "bold" - else - ECHO_FORMAT "0\n" - fi - done + # And print the value for each level + for i in `seq 1 10` + do + display="0" + if [ "${level[$i]}" == "na" ]; then + display="N/A" + elif [ "${level[$i]}" -ge 1 ]; then + display="1" + fi + echo -e "\t Level $i: $display" + done } #================================================= @@ -861,9 +838,9 @@ check_process="$package_path/check_process" if [ ! -e "$check_process" ] then - ECHO_FORMAT "\nUnable to find a check_process file.\n" "red" - ECHO_FORMAT "Package check will be used in lower mode.\n" "lyellow" - check_file=0 + error "Unable to find a check_process file." + warning "Package check will attempt to automatically guess what tests to run." + check_file=0 fi #================================================= @@ -881,7 +858,6 @@ complete_start_timer=$starttime # Purge some log files > "$complete_log" -> "$test_result" > "$script_dir/lxc_boot.log" # Initialize LXC network @@ -889,47 +865,46 @@ LXC_INIT # Default values for check_process and TESTING_PROCESS initialize_values() { - # Test results - RESULT_witness=0 - RESULT_alias_traversal=0 - RESULT_linter=0 + # Test results + RESULT_witness=0 + RESULT_alias_traversal=0 + RESULT_linter=0 RESULT_linter_level_6=0 RESULT_linter_level_7=0 RESULT_linter_level_8=0 - RESULT_global_setup=0 - RESULT_global_remove=0 - RESULT_check_sub_dir=0 - RESULT_check_root=0 - RESULT_check_remove_sub_dir=0 - RESULT_check_remove_root=0 - RESULT_check_upgrade=0 - RESULT_check_backup=0 - RESULT_check_restore=0 - RESULT_check_private=0 - RESULT_check_public=0 - RESULT_check_multi_instance=0 - RESULT_check_path=0 - RESULT_check_port=0 - RESULT_change_url=0 - RESULT_action_config_panel=0 - RESULT_template=0 + RESULT_global_setup=0 + RESULT_global_remove=0 + RESULT_check_sub_dir=0 + RESULT_check_root=0 + RESULT_check_remove_sub_dir=0 + RESULT_check_remove_root=0 + RESULT_check_upgrade=0 + RESULT_check_backup=0 + RESULT_check_restore=0 + RESULT_check_private=0 + RESULT_check_public=0 + RESULT_check_multi_instance=0 + RESULT_check_path=0 + RESULT_check_port=0 + RESULT_change_url=0 + RESULT_action_config_panel=0 - # auto_remove parameter - if [ $interrupt -eq 1 ]; then - auto_remove=0 - else - auto_remove=1 - fi + # auto_remove parameter + if [ $interrupt -eq 1 ]; then + auto_remove=0 + else + auto_remove=1 + fi - # Number of tests to proceed - all_test=0 + # Number of tests to proceed + all_test=0 - # Default path - test_path=/ + # Default path + test_path=/ - # CHECK_URL default values - curl_error=0 - yuno_portal=0 + # CHECK_URL default values + curl_error=0 + yuno_portal=0 } #================================================= @@ -939,418 +914,418 @@ initialize_values() { # Parse the check_process only if it's exist if [ $check_file -eq 1 ] then - ECHO_FORMAT "Parsing of check_process file\n" + info "Parsing check_process file" - # Remove all commented lines in the check_process - sed --in-place '/^#/d' "$check_process" - # Remove all spaces at the beginning of the lines - sed --in-place 's/^[ \t]*//g' "$check_process" + # Remove all commented lines in the check_process + sed --in-place '/^#/d' "$check_process" + # Remove all spaces at the beginning of the lines + sed --in-place 's/^[ \t]*//g' "$check_process" - # Check if a string can be find in the current line - check_line () { - return $(echo "$line" | grep -q "$1") - } + # Check if a string can be find in the current line + check_line () { + return $(echo "$line" | grep -q "$1") + } - # Search a string in the partial check_process - find_string () { - echo $(grep -m1 "$1" "$partial_check_process") - } + # Search a string in the partial check_process + find_string () { + echo $(grep -m1 "$1" "$partial_check_process") + } - # Extract a section found between $1 and $2 from the file $3 - extract_section () { - # Erase the partial check_process - > "$partial_check_process" - local source_file="$3" - local extract=0 - local line="" - while read line - do - # Extract the line - if [ $extract -eq 1 ] - then - # Check if the line is the second line to found - if check_line "$2"; then - # Break the loop to finish the extract process - break; - fi - # Copy the line in the partial check_process - echo "$line" >> "$partial_check_process" - fi + # Extract a section found between $1 and $2 from the file $3 + extract_section () { + # Erase the partial check_process + > "$partial_check_process" + local source_file="$3" + local extract=0 + local line="" + while read line + do + # Extract the line + if [ $extract -eq 1 ] + then + # Check if the line is the second line to found + if check_line "$2"; then + # Break the loop to finish the extract process + break; + fi + # Copy the line in the partial check_process + echo "$line" >> "$partial_check_process" + fi - # Search for the first line - if check_line "$1"; then - # Activate the extract process - extract=1 - fi - done < "$source_file" - } + # Search for the first line + if check_line "$1"; then + # Activate the extract process + extract=1 + fi + done < "$source_file" + } - # Use 2 partial files, to keep one for a whole tests serie - partial1="${check_process}_part1" - partial2="${check_process}_part2" + # Use 2 partial files, to keep one for a whole tests serie + partial1="${check_process}_part1" + partial2="${check_process}_part2" - # Extract the level section - partial_check_process=$partial1 - extract_section "^;;; Levels" ";; " "$check_process" + # Extract the level section + partial_check_process=$partial1 + extract_section "^;;; Levels" ";; " "$check_process" - # Get the value associated to each level - # Get only the value for the level 5 from the check_process -# for i in `seq 1 10` -# do - # Find the line for this level -# line=$(find_string "^Level $i=") - line=$(find_string "^Level 5=") - # And get the value -# level[$i]=$(echo "$line" | cut -d'=' -f2) - level[5]=$(echo "$line" | cut -d'=' -f2) -# done + # Get the value associated to each level + # Get only the value for the level 5 from the check_process + # for i in `seq 1 10` + # do + # Find the line for this level + # line=$(find_string "^Level $i=") + line=$(find_string "^Level 5=") + # And get the value + # level[$i]=$(echo "$line" | cut -d'=' -f2) + level[5]=$(echo "$line" | cut -d'=' -f2) + # done - # Extract the Options section - partial_check_process=$partial1 - extract_section "^;;; Options" ";; " "$check_process" + # Extract the Options section + partial_check_process=$partial1 + extract_section "^;;; Options" ";; " "$check_process" - # Try to find a optionnal email address to notify the maintainer - # In this case, this email will be used instead of the email from the manifest. - dest="$(echo $(find_string "^Email=") | cut -d '=' -f2)" + # Try to find a optionnal email address to notify the maintainer + # In this case, this email will be used instead of the email from the manifest. + dest="$(echo $(find_string "^Email=") | cut -d '=' -f2)" - # Try to find a optionnal option for the grade of notification - notification_grade="$(echo $(find_string "^Notification=") | cut -d '=' -f2)" + # Try to find a optionnal option for the grade of notification + notification_grade="$(echo $(find_string "^Notification=") | cut -d '=' -f2)" - # Parse each tests serie - while read <&3 tests_serie - do + # Parse each tests serie + while read <&3 tests_serie + do - # Initialize the values for this serie of tests - initialize_values + # Initialize the values for this serie of tests + initialize_values - # Break after the first tests serie - if [ $all_test -ne 0 ] && [ $bash_mode -ne 1 ]; then - read -p "Press a key to start the next tests serie..." < /dev/tty - fi + # Break after the first tests serie + if [ $all_test -ne 0 ] && [ $bash_mode -ne 1 ]; then + read -p "Press a key to start the next tests serie..." < /dev/tty + fi - # Use the second file to extract the whole section of a tests serie - partial_check_process=$partial2 + # Use the second file to extract the whole section of a tests serie + partial_check_process=$partial2 - # Extract the section of the current tests serie - extract_section "^$tests_serie" "^;;" "$check_process" - partial_check_process=$partial1 + # 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")" + # 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 - extract_section "^; Manifest" "^; " "$partial2" + # Parse all infos about arguments of manifest + # Extract the manifest arguments section from the second partial file + extract_section "^; Manifest" "^; " "$partial2" - # Initialize the arguments list - manifest_arguments="" + # Initialize the arguments list + manifest_arguments="" - # Read each arguments and store them - while read line - do - # Extract each argument by removing spaces or tabulations before a parenthesis - add_arg="$(echo $line | sed 's/[ *|\t*](.*//')" - # Remove all double quotes - add_arg="${add_arg//\"/}" - # Then add this argument and follow it by & - manifest_arguments="${manifest_arguments}${add_arg}&" - done < "$partial_check_process" + # Read each arguments and store them + while read line + do + # Extract each argument by removing spaces or tabulations before a parenthesis + add_arg="$(echo $line | sed 's/[ *|\t*](.*//')" + # Remove all double quotes + add_arg="${add_arg//\"/}" + # Then add this argument and follow it by & + manifest_arguments="${manifest_arguments}${add_arg}&" + done < "$partial_check_process" - # Try to find all specific arguments needed for the tests - keep_name_arg_only () { - # Find the line for the given argument - local argument=$(find_string "($1") - # If a line exist for this argument - if [ -n "$argument" ]; then - # Keep only the name of the argument - echo "$(echo "$argument" | cut -d '=' -f1)" - fi - } - domain_arg=$(keep_name_arg_only "DOMAIN") - user_arg=$(keep_name_arg_only "USER") - port_arg=$(keep_name_arg_only "PORT") - path_arg=$(keep_name_arg_only "PATH") - # Get the path value - if [ -n "$path_arg" ] - then - line="$(find_string "(PATH")" - # Keep only the part after the = - line="$(echo "$line" | grep -o "path=.* " | cut -d "=" -f2)" - # And remove " et spaces to keep only the path. - line="${line//[\" ]/}" - # If this path is not empty or equal to /. It's become the new default path value. - if [ ${#line} -gt 1 ]; then - test_path="$line" - fi - fi - public_arg=$(keep_name_arg_only "PUBLIC") - # Find the values for public and private - if [ -n "$public_arg" ] - then - line=$(find_string "(PUBLIC") - public_public_arg=$(echo "$line" | grep -o "|public=[[:alnum:]]*" | cut -d "=" -f2) - public_private_arg=$(echo "$line" | grep -o "|private=[[:alnum:]]*" | cut -d "=" -f2) - fi + # Try to find all specific arguments needed for the tests + keep_name_arg_only () { + # Find the line for the given argument + local argument=$(find_string "($1") + # If a line exist for this argument + if [ -n "$argument" ]; then + # Keep only the name of the argument + echo "$(echo "$argument" | cut -d '=' -f1)" + fi + } + domain_arg=$(keep_name_arg_only "DOMAIN") + user_arg=$(keep_name_arg_only "USER") + port_arg=$(keep_name_arg_only "PORT") + path_arg=$(keep_name_arg_only "PATH") + # Get the path value + if [ -n "$path_arg" ] + then + line="$(find_string "(PATH")" + # Keep only the part after the = + line="$(echo "$line" | grep -o "path=.* " | cut -d "=" -f2)" + # And remove " et spaces to keep only the path. + line="${line//[\" ]/}" + # If this path is not empty or equal to /. It become the new default path value. + if [ ${#line} -gt 1 ]; then + test_path="$line" + fi + fi + public_arg=$(keep_name_arg_only "PUBLIC") + # Find the values for public and private + if [ -n "$public_arg" ] + then + line=$(find_string "(PUBLIC") + public_public_arg=$(echo "$line" | grep -o "|public=[[:alnum:]]*" | cut -d "=" -f2) + public_private_arg=$(echo "$line" | grep -o "|private=[[:alnum:]]*" | cut -d "=" -f2) + fi - if echo "$LIGNE" | grep -q "(PATH)"; then # Path dans le manifest - MANIFEST_PATH=$(echo "$LIGNE" | cut -d '=' -f1) # Récupère la clé du manifest correspondant au path - parse_path=$(echo "$LIGNE" | cut -d '"' -f2) # Lit le path du check_process - if [ -n "$parse_path" ]; then # Si le path n'est pas null, utilise ce path au lieu de la valeur par défaut. - PATH_TEST=$(echo "$LIGNE" | cut -d '"' -f2) - fi - LIGNE=$(echo "$LIGNE" | cut -d '(' -f1) # Retire l'indicateur de clé de manifest à la fin de la ligne - fi + if echo "$LIGNE" | grep -q "(PATH)"; then # Path dans le manifest + MANIFEST_PATH=$(echo "$LIGNE" | cut -d '=' -f1) # Récupère la clé du manifest correspondant au path + parse_path=$(echo "$LIGNE" | cut -d '"' -f2) # Lit le path du check_process + if [ -n "$parse_path" ]; then # Si le path nest pas null, utilise ce path au lieu de la valeur par défaut. + PATH_TEST=$(echo "$LIGNE" | cut -d '"' -f2) + fi + LIGNE=$(echo "$LIGNE" | cut -d '(' -f1) # Retire lindicateur de clé de manifest à la fin de la ligne + fi - # Parse all infos about arguments of actions.toml - # Extract the actions arguments section from the second partial file - extract_section "^; Actions" "^; " "$partial2" + # Parse all infos about arguments of actions.toml + # Extract the actions arguments section from the second partial file + extract_section "^; Actions" "^; " "$partial2" - # Initialize the arguments list - actions_arguments="" + # Initialize the arguments list + actions_arguments="" - # Read each arguments and store them - while read line - do - # Remove all double quotes - add_arg="${line//\"/}" - # Then add this argument and follow it by : - actions_arguments="${actions_arguments}${add_arg}:" - done < "$partial_check_process" + # Read each arguments and store them + while read line + do + # Remove all double quotes + add_arg="${line//\"/}" + # Then add this argument and follow it by : + actions_arguments="${actions_arguments}${add_arg}:" + done < "$partial_check_process" - # Parse all infos about arguments of config-panel.toml - # Extract the config_panel arguments section from the second partial file - extract_section "^; Config_panel" "^; " "$partial2" + # Parse all infos about arguments of config-panel.toml + # Extract the config_panel arguments section from the second partial file + extract_section "^; Config_panel" "^; " "$partial2" - # Initialize the arguments list - config_panel_arguments="" + # Initialize the arguments list + config_panel_arguments="" - # Read each arguments and store them - while read line - do - # Remove all double quotes - add_arg="${line//\"/}" - # Then add this argument and follow it by : - config_panel_arguments="${config_panel_arguments}${add_arg}:" - done < "$partial_check_process" + # Read each arguments and store them + while read line + do + # Remove all double quotes + add_arg="${line//\"/}" + # Then add this argument and follow it by : + config_panel_arguments="${config_panel_arguments}${add_arg}:" + done < "$partial_check_process" - # Parse all tests to perform - # Extract the checks options section from the second partial file - extract_section "^; Checks" "^; " "$partial2" + # Parse all tests to perform + # Extract the checks options section from the second partial file + extract_section "^; Checks" "^; " "$partial2" - read_check_option () { - # Find the line for the given check option - local line=$(find_string "^$1=") - # Get only the value - local value=$(echo "$line" | cut -d '=' -f2) - # And return this value - if [ "${value:0:1}" = "1" ] - then - echo 1 - elif [ "${value:0:1}" = "0" ] - then - echo 0 + read_check_option () { + # Find the line for the given check option + local line=$(find_string "^$1=") + # Get only the value + local value=$(echo "$line" | cut -d '=' -f2) + # And return this value + if [ "${value:0:1}" = "1" ] + then + echo 1 + elif [ "${value:0:1}" = "0" ] + then + echo 0 else echo -1 - fi - } + fi + } - count_test () { - # Increase the number of test, if this test is set at 1. - test "$1" -eq 1 && all_test=$((all_test+1)) - } + count_test () { + # Increase the number of test, if this test is set at 1. + test "$1" -eq 1 && all_test=$((all_test+1)) + } - # Get standard options - pkg_linter=$(read_check_option pkg_linter) - count_test $pkg_linter - setup_sub_dir=$(read_check_option setup_sub_dir) - count_test $setup_sub_dir - setup_root=$(read_check_option setup_root) - count_test $setup_root - setup_nourl=$(read_check_option setup_nourl) - count_test $setup_nourl - setup_private=$(read_check_option setup_private) - count_test $setup_private - setup_public=$(read_check_option setup_public) - count_test $setup_public - backup_restore=$(read_check_option backup_restore) - count_test $backup_restore - multi_instance=$(read_check_option multi_instance) - count_test $multi_instance - incorrect_path=0 - count_test $incorrect_path - port_already_use=$(read_check_option port_already_use) - count_test $port_already_use - change_url=$(read_check_option change_url) - count_test $change_url - actions=$(read_check_option actions) - count_test $actions - config_panel=$(read_check_option config_panel) - count_test $config_panel + # Get standard options + pkg_linter=$(read_check_option pkg_linter) + count_test $pkg_linter + setup_sub_dir=$(read_check_option setup_sub_dir) + count_test $setup_sub_dir + setup_root=$(read_check_option setup_root) + count_test $setup_root + setup_nourl=$(read_check_option setup_nourl) + count_test $setup_nourl + setup_private=$(read_check_option setup_private) + count_test $setup_private + setup_public=$(read_check_option setup_public) + count_test $setup_public + backup_restore=$(read_check_option backup_restore) + count_test $backup_restore + multi_instance=$(read_check_option multi_instance) + count_test $multi_instance + incorrect_path=0 + count_test $incorrect_path + port_already_use=$(read_check_option port_already_use) + count_test $port_already_use + change_url=$(read_check_option change_url) + count_test $change_url + actions=$(read_check_option actions) + count_test $actions + config_panel=$(read_check_option config_panel) + count_test $config_panel - # For port_already_use, check if there is also a port number - if [ $port_already_use -eq 1 ] - then - line=$(find_string "^port_already_use=") - # If there is port number - if echo "$line" | grep -q "([0-9]*)" - then - # Store the port number in port_arg and prefix it by # to means that not really a manifest arg - port_arg="#$(echo "$line" | cut -d '(' -f2 | cut -d ')' -f1)" - fi - fi + # For port_already_use, check if there is also a port number + if [ $port_already_use -eq 1 ] + then + line=$(find_string "^port_already_use=") + # If there is port number + if echo "$line" | grep -q "([0-9]*)" + then + # Store the port number in port_arg and prefix it by # to means that not really a manifest arg + port_arg="#$(echo "$line" | cut -d '(' -f2 | cut -d ')' -f1)" + fi + fi - # Clean the upgrade list - > "$script_dir/upgrade_list" - # Get multiples lines for upgrade option. - while $(grep --quiet "^upgrade=" "$partial_check_process") - do - # Get the value for the first upgrade test. - temp_upgrade=$(read_check_option upgrade) - count_test $temp_upgrade - # Set upgrade to 1, but never to 0. - if [ "$upgrade" != "1" ]; then - upgrade=$temp_upgrade - fi - # Get this line to find if there an option. - line=$(find_string "^upgrade=") - if echo "$line" | grep --quiet "from_commit=" - then - # Add the commit to the upgrade list - line="${line##*from_commit=}" + # Clean the upgrade list + > "$script_dir/upgrade_list" + # Get multiples lines for upgrade option. + while $(grep --quiet "^upgrade=" "$partial_check_process") + do + # Get the value for the first upgrade test. + temp_upgrade=$(read_check_option upgrade) + count_test $temp_upgrade + # Set upgrade to 1, but never to 0. + if [ "$upgrade" != "1" ]; then + upgrade=$temp_upgrade + fi + # Get this line to find if there an option. + line=$(find_string "^upgrade=") + if echo "$line" | grep --quiet "from_commit=" + then + # Add the commit to the upgrade list + line="${line##*from_commit=}" # Add the upgrade to the list only if the test is set to 1 if [ $temp_upgrade -eq 1 ]; then echo "$line" >> "$script_dir/upgrade_list" fi - elif [ $temp_upgrade -eq 1 ]; then - # Or simply 'current' for a standard upgrade. - echo "current" >> "$script_dir/upgrade_list" - fi - # Remove this line from the check_process - sed --in-place "\|${line}$|d" "$partial_check_process" - done + elif [ $temp_upgrade -eq 1 ]; then + # Or simply 'current' for a standard upgrade. + echo "current" >> "$script_dir/upgrade_list" + fi + # Remove this line from the check_process + sed --in-place "\|${line}$|d" "$partial_check_process" + done - # Launch all tests successively - TESTING_PROCESS - # Print the final results of the tests - TEST_RESULTS + # Launch all tests successively + TESTING_PROCESS + # Print the final results of the tests + TEST_RESULTS - # Set snap0 as the current snapshot - current_snapshot=snap0 - # And clean temporary snapshots - unset root_snapshot - unset subpath_snapshot + # Set snap0 as the current snapshot + current_snapshot=snap0 + # And clean temporary snapshots + unset root_snapshot + unset subpath_snapshot - done 3<<< "$(grep "^;; " "$check_process")" + done 3<<< "$(grep "^;; " "$check_process")" -# No check_process file. Try to parse the manifest. + # No check_process file. Try to parse the manifest. else - # Initialize the values for this serie of tests - initialize_values + # Initialize the values for this serie of tests + initialize_values - manifest_extract="$script_dir/manifest_extract" + manifest_extract="$script_dir/manifest_extract" - # Extract the informations from the manifest with the Bram's sly snake script. - python "$script_dir/sub_scripts/manifest_parsing.py" "$package_path/manifest.json" > "$manifest_extract" + # Extract the informations from the manifest with the Bram's sly snake script. + python "$script_dir/sub_scripts/manifest_parsing.py" "$package_path/manifest.json" > "$manifest_extract" - # Default tests - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - upgrade=1 - setup_private=1 - setup_public=1 - backup_restore=1 - multi_instance=1 - incorrect_path=0 - port_already_use=0 - change_url=0 - all_test=$((all_test+9)) + # Default tests + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + upgrade=1 + setup_private=1 + setup_public=1 + backup_restore=1 + multi_instance=1 + incorrect_path=0 + port_already_use=0 + change_url=0 + all_test=$((all_test+9)) - # Read each arguments and store them - while read line - do - # Read each argument and pick up the first value. Then replace : by = - add_arg="$(echo $line | cut -d ':' -f1,2 | sed s/:/=/)" - # Then add this argument and follow it by & - manifest_arguments="${manifest_arguments}${add_arg}&" - done < "$manifest_extract" + # Read each arguments and store them + while read line + do + # Read each argument and pick up the first value. Then replace : by = + add_arg="$(echo $line | cut -d ':' -f1,2 | sed s/:/=/)" + # Then add this argument and follow it by & + manifest_arguments="${manifest_arguments}${add_arg}&" + done < "$manifest_extract" - # Search a string in the partial check_process - find_string () { - echo $(grep "$1" "$manifest_extract") - } + # Search a string in the partial check_process + find_string () { + echo $(grep "$1" "$manifest_extract") + } - # Try to find all specific arguments needed for the tests - keep_name_arg_only () { - # Find the line for the given argument - local argument=$(find_string "$1") - # If a line exist for this argument - if [ -n "$argument" ]; then - # Keep only the name of the argument - echo "$(echo "$argument" | cut -d ':' -f1)" - fi - } - domain_arg=$(keep_name_arg_only ":ynh.local") - path_arg=$(keep_name_arg_only "path:") - user_arg=$(keep_name_arg_only "user:\|admin:") - public_arg=$(keep_name_arg_only "is_public:") - # Find the values for public and private - if [ -n "$public_arg" ] - then - line=$(find_string "is_public:") - # Assume the first value is public and the second is private. - public_public_arg=$(echo "$line" | cut -d ":" -f2) - public_private_arg=$(echo "$line" | cut -d ":" -f3) - fi + # Try to find all specific arguments needed for the tests + keep_name_arg_only () { + # Find the line for the given argument + local argument=$(find_string "$1") + # If a line exist for this argument + if [ -n "$argument" ]; then + # Keep only the name of the argument + echo "$(echo "$argument" | cut -d ':' -f1)" + fi + } + domain_arg=$(keep_name_arg_only ":ynh.local") + path_arg=$(keep_name_arg_only "path:") + user_arg=$(keep_name_arg_only "user:\|admin:") + public_arg=$(keep_name_arg_only "is_public:") + # Find the values for public and private + if [ -n "$public_arg" ] + then + line=$(find_string "is_public:") + # Assume the first value is public and the second is private. + public_public_arg=$(echo "$line" | cut -d ":" -f2) + public_private_arg=$(echo "$line" | cut -d ":" -f3) + fi - count_test () { - # Decrease the number of test, if this test is not already removed. - if [ $1 -eq 1 ]; then - all_test=$((all_test-1)) - return 1 - fi - } + count_test () { + # Decrease the number of test, if this test is not already removed. + if [ $1 -eq 1 ]; then + all_test=$((all_test-1)) + return 1 + fi + } - # Disable some tests if the manifest key doesn't be found - if [ -z "$domain_arg" ] - then - ECHO_FORMAT "The manifest key for domain didn't be find.\n" "lyellow" - setup_sub_dir=0 - count_test "$setup_root" || setup_root=0 - count_test "$multi_instance" || multi_instance=0 - count_test "$incorrect_path" || incorrect_path=0 - setup_nourl=1 - fi - if [ -z "$path_arg" ] - then - ECHO_FORMAT "The manifest key for path didn't be find.\n" "lyellow" - count_test "$setup_root" || setup_root=0 - count_test "$multi_instance" || multi_instance=0 - count_test "$incorrect_path" || incorrect_path=0 - fi - if [ -z "$public_arg" ] - then - ECHO_FORMAT "The manifest key for public didn't be find.\n" "lyellow" - setup_private=0 - setup_public=0 - all_test=$((all_test-2)) - fi - # Remove the multi-instance test if this parameter is set at false in the manifest. - if grep multi_instance "$package_path/manifest.json" | grep -q false - then - count_test "$multi_instance" || multi_instance=0 - fi + # Disable some tests if the manifest key doesn't be found + if [ -z "$domain_arg" ] + then + error "The manifest key for domain was not found." + setup_sub_dir=0 + count_test "$setup_root" || setup_root=0 + count_test "$multi_instance" || multi_instance=0 + count_test "$incorrect_path" || incorrect_path=0 + setup_nourl=1 + fi + if [ -z "$path_arg" ] + then + error "The manifest key for path was not found." + count_test "$setup_root" || setup_root=0 + count_test "$multi_instance" || multi_instance=0 + count_test "$incorrect_path" || incorrect_path=0 + fi + if [ -z "$public_arg" ] + then + error "The manifest key for public was not found." + setup_private=0 + setup_public=0 + all_test=$((all_test-2)) + fi + # Remove the multi-instance test if this parameter is set at false in the manifest. + if grep multi_instance "$package_path/manifest.json" | grep -q false + then + count_test "$multi_instance" || multi_instance=0 + fi - # Launch all tests successively - TESTING_PROCESS - # Print the final results of the tests - TEST_RESULTS + # Launch all tests successively + TESTING_PROCESS + # Print the final results of the tests + TEST_RESULTS fi echo "You can find the complete log of these tests in $complete_log" @@ -1369,35 +1344,35 @@ stop_timer 3 #================================================= notif_grade () { - # Check the level of notification from the check_process. - # Echo 1 if the grade is reached + # Check the level of notification from the check_process. + # Echo 1 if the grade is reached - compare_grade () - { - if echo "$notification_grade" | grep -q "$1"; then - echo 1 - else - echo 0 - fi - } + compare_grade () + { + if echo "$notification_grade" | grep -q "$1"; then + echo 1 + else + echo 0 + fi + } - case "$1" in - all) - # If 'all' is needed, only a grade of notification at 'all' can match - compare_grade "^all$" - ;; - change) - # If 'change' is needed, notification at 'all' or 'change' can match - compare_grade "^all$\|^change$" - ;; - down) - # If 'down' is needed, notification at 'all', 'change' or 'down' match - compare_grade "^all$\|^change$\|^down$" - ;; - *) - echo 0 - ;; - esac + case "$1" in + all) + # If 'all' is needed, only a grade of notification at 'all' can match + compare_grade "^all$" + ;; + change) + # If 'change' is needed, notification at 'all' or 'change' can match + compare_grade "^all$\|^change$" + ;; + down) + # If 'down' is needed, notification at 'all', 'change' or 'down' match + compare_grade "^all$\|^change$\|^down$" + ;; + *) + echo 0 + ;; + esac } #================================================= @@ -1414,86 +1389,86 @@ app_name=${package_dir%_ynh_check} if [ $type_exec_env -eq 2 ] then - # Get the job name, stored in the work_list - job=$(head -n1 "$script_dir/../work_list" | cut -d ';' -f 3) + # Get the job name, stored in the work_list + job=$(head -n1 "$script_dir/../work_list" | cut -d ';' -f 3) - # Identify the type of test, stable (0), testing (1) or unstable (2) - # Default stable - test_type=0 - message="" - if echo "$job" | grep -q "(testing)" - then - message="(TESTING) " - test_type=1 - elif echo "$job" | grep -q "(unstable)" - then - message="(UNSTABLE) " - test_type=2 - fi + # Identify the type of test, stable (0), testing (1) or unstable (2) + # Default stable + test_type=0 + message="" + if echo "$job" | grep -q "(testing)" + then + message="(TESTING) " + test_type=1 + elif echo "$job" | grep -q "(unstable)" + then + message="(UNSTABLE) " + test_type=2 + fi - # Build the log path (and replace all space by %20 in the job name) - if [ -n "$job" ]; then - if systemctl list-units | grep --quiet jenkins - then - job_log="/job/${job// /%20}/lastBuild/console" - elif systemctl list-units | grep --quiet yunorunner - then - # Get the directory of YunoRunner - ci_dir="$(grep WorkingDirectory= /etc/systemd/system/yunorunner.service | cut -d= -f2)" - # List the jobs from YunoRunner and grep the job (without Community or Official). - job_id="$(cd "$ci_dir"; ve3/bin/python ciclic list | grep ${job%% *} | head -n1)" - # Keep only the id of the job, by removing everything after - - job_id="${job_id%% -*}" - # And remove any space before the id. - job_id="${job_id##* }" - job_log="/job/$job_id" - fi - fi + # Build the log path (and replace all space by %20 in the job name) + if [ -n "$job" ]; then + if systemctl list-units | grep --quiet jenkins + then + job_log="/job/${job// /%20}/lastBuild/console" + elif systemctl list-units | grep --quiet yunorunner + then + # Get the directory of YunoRunner + ci_dir="$(grep WorkingDirectory= /etc/systemd/system/yunorunner.service | cut -d= -f2)" + # List the jobs from YunoRunner and grep the job (without Community or Official). + job_id="$(cd "$ci_dir"; ve3/bin/python ciclic list | grep ${job%% *} | head -n1)" + # Keep only the id of the job, by removing everything after - + job_id="${job_id%% -*}" + # And remove any space before the id. + job_id="${job_id##* }" + job_log="/job/$job_id" + fi + fi - # If it's a test on testing or unstable - if [ $test_type -gt 0 ] - then - # Remove unstable or testing of the job name to find its stable version in the level list - job="${job% (*)}" - fi + # If it's a test on testing or unstable + if [ $test_type -gt 0 ] + then + # Remove unstable or testing of the job name to find its stable version in the level list + job="${job% (*)}" + fi - # Get the previous level, found in the file list_level_stable - previous_level=$(grep "^$job:" "$script_dir/../auto_build/list_level_stable" | cut -d: -f2) + # Get the previous level, found in the file list_level_stable + previous_level=$(grep "^$job:" "$script_dir/../auto_build/list_level_stable" | cut -d: -f2) - # Print the variation of the level. If this level is different than 0 - if [ $global_level -gt 0 ] - then - message="${message}Application $app_name" - # If non previous level was found - if [ -z "$previous_level" ]; then - message="$message just reach the level $global_level" - send_mail=$(notif_grade all) - # If the level stays the same - elif [ $global_level -eq $previous_level ]; then - message="$message stays at level $global_level" - # Need notification at 'all' to notify by email - send_mail=$(notif_grade all) - # If the level go up - elif [ $global_level -gt $previous_level ]; then - message="$message rise from level $previous_level to level $global_level" - # Need notification at 'change' to notify by email - send_mail=$(notif_grade change) - # If the level go down - elif [ $global_level -lt $previous_level ]; then - message="$message go down from level $previous_level to level $global_level" - # Need notification at 'down' to notify by email - send_mail=$(notif_grade down) - fi - fi + # Print the variation of the level. If this level is different than 0 + if [ $global_level -gt 0 ] + then + message="${message}Application $app_name" + # If non previous level was found + if [ -z "$previous_level" ]; then + message="$message just reach the level $global_level" + send_mail=$(notif_grade all) + # If the level stays the same + elif [ $global_level -eq $previous_level ]; then + message="$message stays at level $global_level" + # Need notification at 'all' to notify by email + send_mail=$(notif_grade all) + # If the level go up + elif [ $global_level -gt $previous_level ]; then + message="$message rise from level $previous_level to level $global_level" + # Need notification at 'change' to notify by email + send_mail=$(notif_grade change) + # If the level go down + elif [ $global_level -lt $previous_level ]; then + message="$message go down from level $previous_level to level $global_level" + # Need notification at 'down' to notify by email + send_mail=$(notif_grade down) + fi + fi fi # If the app completely failed and obtained 0 if [ $global_level -eq 0 ] then - message="${message}Application $app_name has completely failed the continuous integration tests" + message="${message}Application $app_name has completely failed the continuous integration tests" - # Always send an email if the app failed - send_mail=1 + # Always send an email if the app failed + send_mail=1 fi # The mail subject is the message to send, before any logs informations @@ -1505,18 +1480,18 @@ subject="[YunoHost] $message" if [ $type_exec_env -eq 2 ] then - # Build the address of the server from auto.conf - ci_path=$(grep "DOMAIN=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2)/$(grep "CI_PATH=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2) + # Build the address of the server from auto.conf + ci_path=$(grep "DOMAIN=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2)/$(grep "CI_PATH=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2) - # Add the log adress to the message - message="$message on https://$ci_path$job_log" + # Add the log adress to the message + message="$message on https://$ci_path$job_log" - # Send a xmpp notification on the chat room "apps" - # Only for a test with the stable version of YunoHost - if [ $test_type -eq 0 ] - then - "$script_dir/../auto_build/xmpp_bot/xmpp_post.sh" "$message" > /dev/null 2>&1 - fi + # Send a xmpp notification on the chat room "apps" + # Only for a test with the stable version of YunoHost + if [ $test_type -eq 0 ] + then + "$script_dir/../auto_build/xmpp_bot/xmpp_post.sh" "$message" > /dev/null 2>&1 + fi fi # Send a mail to main maintainer according to notification option in the check_process. @@ -1524,21 +1499,21 @@ fi if [ $type_exec_env -ge 1 ] && [ $send_mail -eq 1 ] then - # Add a 'from' header for the official CI only. -# Apparently, this trick is not needed anymore !? -# if [ $type_exec_env -eq 2 ]; then -# from_yuno="-a \"From: yunohost@yunohost.org\"" -# fi + # Add a 'from' header for the official CI only. + # Apparently, this trick is not needed anymore !? + # if [ $type_exec_env -eq 2 ]; then + # from_yuno="-a \"From: yunohost@yunohost.org\"" + # fi - # Get the maintainer email from the manifest. If it doesn't found if the check_process - if [ -z "$dest" ]; then - dest=$(grep '\"email\": ' "$package_path/manifest.json" | cut -d '"' -f 4) - fi + # Get the maintainer email from the manifest. If it doesn't found if the check_process + if [ -z "$dest" ]; then + dest=$(grep '\"email\": ' "$package_path/manifest.json" | cut -d '"' -f 4) + fi - # Send the message by mail, if a address has been find - if [ -n "$dest" ]; then - mail $from_yuno -s "$subject" "$dest" <<< "$message" - fi + # Send the message by mail, if a address has been find + if [ -n "$dest" ]; then + mail $from_yuno -s "$subject" "$dest" <<< "$message" + fi fi #================================================= diff --git a/sub_scripts/common.sh b/sub_scripts/common.sh new file mode 100755 index 0000000..dedfe40 --- /dev/null +++ b/sub_scripts/common.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +readonly NORMAL=$(printf '\033[0m') +readonly BOLD=$(printf '\033[1m') +readonly faint=$(printf '\033[2m') +readonly UNDERLINE=$(printf '\033[4m') +readonly NEGATIVE=$(printf '\033[7m') +readonly RED=$(printf '\033[31m') +readonly GREEN=$(printf '\033[32m') +readonly ORANGE=$(printf '\033[33m') +readonly BLUE=$(printf '\033[34m') +readonly YELLOW=$(printf '\033[93m') +readonly WHITE=$(printf '\033[39m') + +function title() +{ + cat << EOF | tee -a "$complete_log" +${BOLD} + =================================== + $1 + =================================== +${NORMAL} +EOF +} + +function small_title() +{ + echo -e "\n${BOLD} > ${1}${NORMAL}\n" | tee -a "$complete_log" +} + + +function debug() +{ + echo "$1" >> "$complete_log" +} + +function info() +{ + echo "${1}" | tee -a "$complete_log" +} + +function success() +{ + echo "${BOLD}${GREEN}Success: ${1}${NORMAL}" | tee -a "$complete_log" +} + +function warning() +{ + echo "${BOLD}${ORANGE}Warning: ${1}${NORMAL}" | tee -a "$complete_log" 2>&1 +} + +function error() +{ + echo "${BOLD}${RED}Error: ${1}${NORMAL}" | tee -a "$complete_log" 2>&1 +} + +function critical() +{ + echo "${BOLD}${RED}Critical: ${1}${NORMAL}" | tee -a "$complete_log" 2>&1 +} + +function report_test_success () { + echo -e "\n${BOLD}${GREEN}--- SUCCESS ---${NORMAL}\n" | tee -a "$complete_log" 2>&1 +} + +function report_test_warning () { + echo -e "\n${BOLD}${ORANGE}--- WARNING ---${NORMAL}\n" | tee -a "$complete_log" 2>&1 +} + +function report_test_failed () { + echo -e "\n${BOLD}${RED}--- FAIL ---${NORMAL}\n" | tee -a "$complete_log" 2>&1 +} diff --git a/sub_scripts/launcher.sh b/sub_scripts/launcher.sh index 38e0bc3..d497e68 100755 --- a/sub_scripts/launcher.sh +++ b/sub_scripts/launcher.sh @@ -6,7 +6,8 @@ echo -e "Loads functions from launcher.sh" # Globals variables #================================================= -arg_ssh="-tt" +# -q aims to disable the display of 'Debian GNU/Linux' each time a command is ran +arg_ssh="-tt -q" snapshot_path="/var/lib/lxcsnaps/$lxc_name" current_snapshot=snap0 @@ -15,47 +16,47 @@ current_snapshot=snap0 #================================================= start_timer () { - # Set the beginning of the timer - starttime=$(date +%s) + # Set the beginning of the timer + starttime=$(date +%s) } stop_timer () { - # Ending the timer - # $1 = Type of querying + # Ending the timer + # $1 = Type of querying - local finishtime=$(date +%s) - # Calculate the gap between the starting and the ending of the timer - local elapsedtime=$(echo $(( $finishtime - $starttime ))) - # Extract the number of hour - local hours=$(echo $(( $elapsedtime / 3600 ))) - local elapsedtime=$(echo $(( $elapsedtime - ( 3600 * $hours) ))) - # Minutes - local minutes=$(echo $(( $elapsedtime / 60 ))) - # And seconds - local seconds=$(echo $(( $elapsedtime - ( 60 * $minutes) ))) + local finishtime=$(date +%s) + # Calculate the gap between the starting and the ending of the timer + local elapsedtime=$(echo $(( $finishtime - $starttime ))) + # Extract the number of hour + local hours=$(echo $(( $elapsedtime / 3600 ))) + local elapsedtime=$(echo $(( $elapsedtime - ( 3600 * $hours) ))) + # Minutes + local minutes=$(echo $(( $elapsedtime / 60 ))) + # And seconds + local seconds=$(echo $(( $elapsedtime - ( 60 * $minutes) ))) - local phours="" - local pminutes="" - local pseconds="" + local phours="" + local pminutes="" + local pseconds="" - # Avoid null values - [ $hours -eq 0 ] || phours="$hours hour" - [ $minutes -eq 0 ] || pminutes="$minutes minute" - [ $seconds -eq 0 ] || pseconds="$seconds second" + # Avoid null values + [ $hours -eq 0 ] || phours="$hours hour" + [ $minutes -eq 0 ] || pminutes="$minutes minute" + [ $seconds -eq 0 ] || pseconds="$seconds second" - # Add a 's' for plural values - [ $hours -eq 1 ] && phours="${phours}, " || test -z "$phours" || phours="${phours}s, " - [ $minutes -eq 1 ] && pminutes="${pminutes}, " || test -z "$pminutes" || pminutes="${pminutes}s, " - [ $seconds -gt 1 ] && pseconds="${pseconds}s" + # Add a 's' for plural values + [ $hours -eq 1 ] && phours="${phours}, " || test -z "$phours" || phours="${phours}s, " + [ $minutes -eq 1 ] && pminutes="${pminutes}, " || test -z "$pminutes" || pminutes="${pminutes}s, " + [ $seconds -gt 1 ] && pseconds="${pseconds}s" - if [ $1 -eq 2 ]; then - ECHO_FORMAT "Working time for this test: " "blue" - elif [ $1 -eq 3 ]; then - ECHO_FORMAT "Global working time for all tests: " "blue" - else - ECHO_FORMAT "Working time: " "blue" - fi - ECHO_FORMAT "${phours}${pminutes}${pseconds} ($(date '+%T')).\n" "blue" + time="${phours}${pminutes}${pseconds} ($(date '+%T'))" + if [ $1 -eq 2 ]; then + info "Working time for this test: $time" + elif [ $1 -eq 3 ]; then + info "Global working time for all tests: $time" + else + info "Working time: $time" >/dev/null + fi } #================================================= @@ -63,322 +64,317 @@ stop_timer () { #================================================= create_temp_backup () { - # Create a temporary snapshot + # Create a temporary snapshot - # snap1 for subpath or snap2 for root install - snap_number=$1 + # snap1 for subpath or snap2 for root install + snap_number=$1 - start_timer - # Check all the witness files, to verify if them still here - check_witness_files >&2 + start_timer + # Check all the witness files, to verify if them still here + check_witness_files >&2 - # Stop the container, before its snapshot - sudo lxc-stop --name $lxc_name >&2 + # Stop the container, before its snapshot + sudo lxc-stop --name $lxc_name >&2 - # Remove swap files to avoid killing the CI with huge snapshots. - local swap_file="/var/lib/lxc/$lxc_name/rootfs/swap_$ynh_app_id" - if sudo test -e "$swap_file" - then - sudo swapoff "$swap_file" - sudo rm "$swap_file" - fi + # Remove swap files to avoid killing the CI with huge snapshots. + local swap_file="/var/lib/lxc/$lxc_name/rootfs/swap_$ynh_app_id" + if sudo test -e "$swap_file" + then + sudo swapoff "$swap_file" + sudo rm "$swap_file" + fi - # Check if the snapshot already exist - if [ ! -e "$snapshot_path/snap$snap_number" ] - then - echo "snap$snap_number doesn't exist, its first creation can takes a little while." >&2 - # Create the snapshot. - sudo lxc-snapshot --name $lxc_name >> "$test_result" 2>&1 + # Check if the snapshot already exist + if [ ! -e "$snapshot_path/snap$snap_number" ] + then + echo "snap$snap_number doesn't exist, its first creation can takes a little while." >&2 + # Create the snapshot. + sudo lxc-snapshot --name $lxc_name >> "$complete_log" 2>&1 - # lxc always creates the first snapshot it can creates. - # So if snap1 doesn't exist and you try to create snap2, it will be named snap1. - if [ "$snap_number" == "2" ] && [ ! -e "$snapshot_path/snap2" ] - then - # Rename snap1 to snap2 - sudo mv "$snapshot_path/snap1" "$snapshot_path/snap2" - fi - fi + # lxc always creates the first snapshot it can creates. + # So if snap1 doesn't exist and you try to create snap2, it will be named snap1. + if [ "$snap_number" == "2" ] && [ ! -e "$snapshot_path/snap2" ] + then + # Rename snap1 to snap2 + sudo mv "$snapshot_path/snap1" "$snapshot_path/snap2" + fi + fi - # Update the snapshot with rsync to clone the current lxc state - sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "/var/lib/lxc/$lxc_name/rootfs/" "$snapshot_path/snap$snap_number/rootfs/" > /dev/null 2>> "$test_result" + # Update the snapshot with rsync to clone the current lxc state + sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "/var/lib/lxc/$lxc_name/rootfs/" "$snapshot_path/snap$snap_number/rootfs/" > /dev/null 2>> "$complete_log" - # Set this snapshot as the current snapshot - current_snapshot=snap$snap_number + # Set this snapshot as the current snapshot + current_snapshot=snap$snap_number - stop_timer 1 >> $complete_log + stop_timer 1 - # Restart the container, after the snapshot - LXC_START "true" >&2 + # Restart the container, after the snapshot + LXC_START "true" >&2 } use_temp_snapshot () { - # Use a temporary snapshot, if it already exists - # $1 = Name of the snapshot to use - current_snapshot=$1 + # Use a temporary snapshot, if it already exists + # $1 = Name of the snapshot to use + current_snapshot=$1 - start_timer - # Fix the missing hostname in the hosts file... - echo "127.0.0.1 $lxc_name" | sudo tee --append "$snapshot_path/$current_snapshot/rootfs/etc/hosts" > /dev/null + start_timer + # Fix the missing hostname in the hosts file... + echo "127.0.0.1 $lxc_name" | sudo tee --append "$snapshot_path/$current_snapshot/rootfs/etc/hosts" > /dev/null - # Restore this snapshot. - sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/$current_snapshot/rootfs/" "/var/lib/lxc/$lxc_name/rootfs/" > /dev/null 2>> "$test_result" + # Restore this snapshot. + sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/$current_snapshot/rootfs/" "/var/lib/lxc/$lxc_name/rootfs/" > /dev/null 2>> "$complete_log" - stop_timer 1 >> "$complete_log" + stop_timer 1 - # Retrieve the app id in the log. To manage the app after - ynh_app_id=$(sudo tac "$yunohost_log" | grep --only-matching --max-count=1 "YNH_APP_INSTANCE_NAME=[^ ]*" | cut --delimiter='=' --fields=2) + # Retrieve the app id in the log. To manage the app after + ynh_app_id=$(sudo tac "$yunohost_log" | grep --only-matching --max-count=1 "YNH_APP_INSTANCE_NAME=[^ ]*" | cut --delimiter='=' --fields=2) - # Fake the yunohost_result return code of the installation - yunohost_result=0 + # Fake the yunohost_result return code of the installation + yunohost_result=0 } #================================================= is_lxc_running () { - sudo lxc-info --name=$lxc_name | grep --quiet "RUNNING" + sudo lxc-info --name=$lxc_name | grep --quiet "RUNNING" } LXC_INIT () { - # Clean previous remaining swap files - sudo swapoff /var/lib/lxc/$lxc_name/rootfs/swap_* 2>/dev/null - sudo rm --force /var/lib/lxc/$lxc_name/rootfs/swap_* - sudo swapoff /var/lib/lxcsnaps/$lxc_name/snap0/rootfs/swap_* 2>/dev/null - sudo rm --force /var/lib/lxcsnaps/$lxc_name/snap0/rootfs/swap_* - sudo swapoff /var/lib/lxcsnaps/$lxc_name/snap1/rootfs/swap_* 2>/dev/null - sudo rm --force /var/lib/lxcsnaps/$lxc_name/snap1/rootfs/swap_* - sudo swapoff /var/lib/lxcsnaps/$lxc_name/snap2/rootfs/swap_* 2>/dev/null - sudo rm --force /var/lib/lxcsnaps/$lxc_name/snap2/rootfs/swap_* + # Clean previous remaining swap files + sudo swapoff /var/lib/lxc/$lxc_name/rootfs/swap_* 2>/dev/null + sudo rm --force /var/lib/lxc/$lxc_name/rootfs/swap_* + sudo swapoff /var/lib/lxcsnaps/$lxc_name/snap0/rootfs/swap_* 2>/dev/null + sudo rm --force /var/lib/lxcsnaps/$lxc_name/snap0/rootfs/swap_* + sudo swapoff /var/lib/lxcsnaps/$lxc_name/snap1/rootfs/swap_* 2>/dev/null + sudo rm --force /var/lib/lxcsnaps/$lxc_name/snap1/rootfs/swap_* + sudo swapoff /var/lib/lxcsnaps/$lxc_name/snap2/rootfs/swap_* 2>/dev/null + sudo rm --force /var/lib/lxcsnaps/$lxc_name/snap2/rootfs/swap_* - # Initialize LXC network + # Initialize LXC network - # Activate the bridge - echo "Initialize network for LXC." - sudo ifup $lxc_bridge --interfaces=/etc/network/interfaces.d/$lxc_bridge | tee --append "$test_result" 2>&1 + # Activate the bridge + echo "Initialize network for LXC." + sudo ifup $lxc_bridge --interfaces=/etc/network/interfaces.d/$lxc_bridge | tee --append "$complete_log" 2>&1 - # Activate iptables rules - echo "Activate iptables rules." - sudo iptables --append FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT | tee --append "$test_result" 2>&1 - sudo iptables --append FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT | tee --append "$test_result" 2>&1 - sudo iptables --table nat --append POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1 + # Activate iptables rules + echo "Activate iptables rules." + sudo iptables --append FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT | tee --append "$complete_log" 2>&1 + sudo iptables --append FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT | tee --append "$complete_log" 2>&1 + sudo iptables --table nat --append POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$complete_log" 2>&1 } LXC_START () { - # Start the lxc container and execute the given command in it - # $1 = Command to execute in the container + # Start the lxc container and execute the given command in it + # $1 = Command to execute in the container - start_timer - # Try to start the container 3 times. - local max_try=3 - local i=0 - while [ $i -lt $max_try ] - do - i=$(( $i +1 )) - # Start the container and log the booting process in $script_dir/lxc_boot.log - # Try to start only if the container is not already started - if ! is_lxc_running; then - echo -n "Start the LXC container" >> "$test_result" - sudo lxc-start --name=$lxc_name --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$test_result" 2>&1 - local avoid_witness=0 - else - echo -n "A LXC container is already running" >> "$test_result" - local avoid_witness=1 - fi + start_timer + # Try to start the container 3 times. + local max_try=3 + local i=0 + while [ $i -lt $max_try ] + do + i=$(( $i +1 )) + # Start the container and log the booting process in $script_dir/lxc_boot.log + # Try to start only if the container is not already started + if ! is_lxc_running; then + debug "Start the LXC container" >> "$complete_log" + sudo lxc-start --name=$lxc_name --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$complete_log" 2>&1 + local avoid_witness=0 + else + debug "A LXC container is already running" + local avoid_witness=1 + fi - # Try to connect 5 times - local j=0 - for j in `seq 1 5` - do - echo -n . >> "$test_result" - # Try to connect with ssh to check if the container is ready to work. - if ssh $arg_ssh -o ConnectTimeout=10 $lxc_name "exit 0" > /dev/null 2>&1; then - # Break the for loop if the container is ready. - break - fi - sleep 1 - done - echo "" - if [ "$(uname -m)" == "aarch64" ] - then - sleep 30 - fi - - local failstart=0 - # Check if the container is running - if ! is_lxc_running; then - ECHO_FORMAT "The LXC container didn't start...\n" "red" "bold" - failstart=1 - if [ $i -ne $max_try ]; then - ECHO_FORMAT "Rebooting the container...\n" "red" "bold" - fi - LXC_STOP # Stop the LXC container - elif ! ssh $arg_ssh -o ConnectTimeout=60 $lxc_name "sudo ping -q -c 2 security.debian.org > /dev/null 2>&1; exit \$?" >> "$test_result" 2>&1 - then - # Try to ping security.debian.org to check the connectivity from the container - ECHO_FORMAT "The container failed to connect to internet...\n" "red" "bold" - failstart=1 - if [ $i -ne $max_try ]; then - ECHO_FORMAT "Rebooting the container...\n" "red" "bold" - fi - LXC_STOP # Stop the LXC container - else - # Create files to check if the remove script does not remove them accidentally - [ $avoid_witness -eq 0 ] && set_witness_files + # Try to connect 5 times + local j=0 + for j in `seq 1 5` + do + debug "." >> "$complete_log" + # Try to connect with ssh to check if the container is ready to work. + if ssh $arg_ssh -o ConnectTimeout=10 $lxc_name "exit 0" > /dev/null 2>&1; then + # Break the for loop if the container is ready. + break + fi + sleep 1 + done + echo "" + if [ "$(uname -m)" == "aarch64" ] + then + sleep 30 + fi - # Break the for loop if the container is ready. - break - fi + local failstart=0 + # Check if the container is running + if ! is_lxc_running; then + critical "The LXC container didn't start..." + failstart=1 + if [ $i -ne $max_try ]; then + info "Rebooting the container..." + fi + LXC_STOP + # Try to ping security.debian.org to check the connectivity from the container + elif ! ssh $arg_ssh -o ConnectTimeout=60 $lxc_name "sudo ping -q -c 2 security.debian.org > /dev/null 2>&1; exit \$?" >> "$complete_log" 2>&1 + then + critical "The container failed to connect to internet..." + failstart=1 + if [ $i -ne $max_try ]; then + info "Rebooting the container..." + fi + LXC_STOP + # Create files to check if the remove script does not remove them accidentally + else + [ $avoid_witness -eq 0 ] && set_witness_files - # Fail if the container failed to start - if [ $i -eq $max_try ] && [ $failstart -eq 1 ] - then - send_email () { - # Send an email only if it's a CI environment - if [ $type_exec_env -ne 0 ] - then - ci_path=$(grep "CI_URL=" "$script_dir/../config" | cut -d= -f2) - local subject="[YunoHost] Container in trouble on $ci_path." - local message="The container failed to start $max_try times on $ci_path. -$lxc_check_result + # Break the for loop if the container is ready. + break + fi -Please have a look to the log of lxc_check: -$(cat "$script_dir/lxc_check.log")" - if [ $lxc_check -eq 2 ]; then - # Add the log of lxc_build - message="$message + # Fail if the container failed to start + if [ $i -eq $max_try ] && [ $failstart -eq 1 ] + then + send_email () { + # Send an email only if it's a CI environment + if [ $type_exec_env -ne 0 ] + then + ci_path=$(grep "CI_URL=" "$script_dir/../config" | cut -d= -f2) + local subject="[YunoHost] Container in trouble on $ci_path." + local message="The container failed to start $max_try times on $ci_path. + $lxc_check_result -Here the log of lxc_build: -$(cat "$script_dir/sub_scripts/Build_lxc.log")" - fi + Please have a look to the log of lxc_check: + $(cat "$script_dir/lxc_check.log")" + if [ $lxc_check -eq 2 ]; then + # Add the log of lxc_build + message="$message - dest=$(grep 'dest=' "$script_dir/../config" | cut -d= -f2) - mail -s "$subject" "$dest" <<< "$message" - fi - } + Here the log of lxc_build: + $(cat "$script_dir/sub_scripts/Build_lxc.log")" + fi - ECHO_FORMAT "The container failed to start $max_try times...\n" "red" "bold" - ECHO_FORMAT "Boot log:\n" clog - cat "$script_dir/lxc_boot.log" | tee --append "$test_result" - ECHO_FORMAT "lxc_check will try to fix the container...\n" "red" "bold" - $script_dir/sub_scripts/lxc_check.sh --no-lock | tee "$script_dir/lxc_check.log" - # PIPESTATUS is an array with the exit code of each command followed by a pipe - local lxc_check=${PIPESTATUS[0]} - LXC_INIT - if [ $lxc_check -eq 0 ]; then - local lxc_check_result="The container seems to be ok, according to lxc_check." - ECHO_FORMAT "$lxc_check_result\n" "lgreen" "bold" - send_email - i=0 - elif [ $lxc_check -eq 1 ]; then - local lxc_check_result="An error has happened with the host. Please check the configuration." - ECHO_FORMAT "$lxc_check_result\n" "red" "bold" - send_email - stop_timer 1 >> "$complete_log" - return 1 - elif [ $lxc_check -eq 2 ]; then - local lxc_check_result="The container is broken, it will be rebuilt." - ECHO_FORMAT "$lxc_check_result\n" "red" "bold" - $script_dir/sub_scripts/lxc_build.sh - LXC_INIT - send_email - i=0 - elif [ $lxc_check -eq 3 ]; then - local lxc_check_result="The container has been fixed by lxc_check." - ECHO_FORMAT "$lxc_check_result\n" "lgreen" "bold" - send_email - i=0 - fi - fi - done - stop_timer 1 >> "$complete_log" - start_timer + dest=$(grep 'dest=' "$script_dir/../config" | cut -d= -f2) + mail -s "$subject" "$dest" <<< "$message" + fi + } - # Count the number of lines of the current yunohost log file. - COPY_LOG 1 + critical "The container failed to start $max_try times..." + info "Boot log:\n" + cat "$script_dir/lxc_boot.log" | tee --append "$complete_log" + info "lxc_check will try to fix the container..." + $script_dir/sub_scripts/lxc_check.sh --no-lock | tee "$script_dir/lxc_check.log" + # PIPESTATUS is an array with the exit code of each command followed by a pipe + local lxc_check=${PIPESTATUS[0]} + LXC_INIT + if [ $lxc_check -eq 0 ]; then + local lxc_check_result="The container seems to be ok, according to lxc_check." + success "$lxc_check_result" + send_email + i=0 + elif [ $lxc_check -eq 1 ]; then + local lxc_check_result="An error has happened with the host. Please check the configuration." + critical "$lxc_check_result" + send_email + stop_timer 1 + return 1 + elif [ $lxc_check -eq 2 ]; then + local lxc_check_result="The container is broken, it will be rebuilt." + critical "$lxc_check_result" + $script_dir/sub_scripts/lxc_build.sh + LXC_INIT + send_email + i=0 + elif [ $lxc_check -eq 3 ]; then + local lxc_check_result="The container has been fixed by lxc_check." + success "$lxc_check_result" + send_email + i=0 + fi + fi + done + stop_timer 1 + start_timer - # Copy the package into the container. - rsync -rq --delete "$package_path" "$lxc_name": >> "$test_result" 2>&1 + # Copy the package into the container. + rsync -rq --delete "$package_path" "$lxc_name": >> "$complete_log" 2>&1 - # Execute the command given in argument in the container and log its results. - ssh $arg_ssh $lxc_name "$1 > /dev/null 2>> temp_yunohost-cli.log; exit \$?" >> "$test_result" 2>&1 - # Store the return code of the command - local returncode=$? + # Execute the command given in argument in the container and log its results. + ssh $arg_ssh $lxc_name "$1; exit $?" | tee -a "$complete_log" - # Retrieve the log of the previous command and copy its content in the temporary log - sudo cat "/var/lib/lxc/$lxc_name/rootfs/home/pchecker/temp_yunohost-cli.log" >> "$temp_log" + # Store the return code of the command + local returncode=${PIPESTATUS[0]} - stop_timer 1 >> "$complete_log" - # Return the exit code of the ssh command - return $returncode + stop_timer 1 + # Return the exit code of the ssh command + return $returncode } LXC_STOP () { - # Stop and restore the LXC container + # Stop and restore the LXC container - start_timer - # Stop the LXC container - if is_lxc_running; then - echo "Stop the LXC container" >> "$test_result" - sudo lxc-stop --name=$lxc_name | tee --append "$test_result" 2>&1 - fi + start_timer + # Stop the LXC container + if is_lxc_running; then + debug "Stop the LXC container" + sudo lxc-stop --name=$lxc_name | tee --append "$complete_log" 2>&1 + fi - # Fix the missing hostname in the hosts file - # If the hostname is missing in /etc/hosts inside the snapshot - if ! sudo grep --quiet "$lxc_name" "$snapshot_path/$current_snapshot/rootfs/etc/hosts" - then - # If the hostname was replaced by name of the snapshot, fix it - if sudo grep --quiet "$current_snapshot" "$snapshot_path/$current_snapshot/rootfs/etc/hosts" - then - # Replace snapX by the real hostname - sudo sed --in-place "s/$current_snapshot/$lxc_name/" "$snapshot_path/$current_snapshot/rootfs/etc/hosts" - else - # Otherwise, simply add the hostname - echo "127.0.0.1 $lxc_name" | sudo tee --append "$snapshot_path/$current_snapshot/rootfs/etc/hosts" > /dev/null - fi - fi + # Fix the missing hostname in the hosts file + # If the hostname is missing in /etc/hosts inside the snapshot + if ! sudo grep --quiet "$lxc_name" "$snapshot_path/$current_snapshot/rootfs/etc/hosts" + then + # If the hostname was replaced by name of the snapshot, fix it + if sudo grep --quiet "$current_snapshot" "$snapshot_path/$current_snapshot/rootfs/etc/hosts" + then + # Replace snapX by the real hostname + sudo sed --in-place "s/$current_snapshot/$lxc_name/" "$snapshot_path/$current_snapshot/rootfs/etc/hosts" + else + # Otherwise, simply add the hostname + echo "127.0.0.1 $lxc_name" | sudo tee --append "$snapshot_path/$current_snapshot/rootfs/etc/hosts" > /dev/null + fi + fi - # Restore the snapshot. - echo "Restore the previous snapshot." >> "$test_result" - sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/$current_snapshot/rootfs/" "/var/lib/lxc/$lxc_name/rootfs/" > /dev/null 2>> "$test_result" - stop_timer 1 >> "$complete_log" + # Restore the snapshot. + debug "Restore the previous snapshot." + sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/$current_snapshot/rootfs/" "/var/lib/lxc/$lxc_name/rootfs/" > /dev/null 2>> "$complete_log" + stop_timer 1 } LXC_TURNOFF () { - # Disable LXC network + # Disable LXC network - echo "Disable iptables rules." - if sudo iptables --check FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT 2> /dev/null - then - sudo iptables --delete FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT >> "$test_result" 2>&1 - fi - if sudo iptables --check FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT 2> /dev/null - then - sudo iptables --delete FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT | tee --append "$test_result" 2>&1 - fi - if sudo iptables --table nat --check POSTROUTING --source $ip_range.0/24 --jump MASQUERADE 2> /dev/null - then - sudo iptables --table nat --delete POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1 - fi + echo "Disable iptables rules." + if sudo iptables --check FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT 2> /dev/null + then + sudo iptables --delete FORWARD --in-interface $lxc_bridge --out-interface $main_iface --jump ACCEPT >> "$complete_log" 2>&1 + fi + if sudo iptables --check FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT 2> /dev/null + then + sudo iptables --delete FORWARD --in-interface $main_iface --out-interface $lxc_bridge --jump ACCEPT | tee --append "$complete_log" 2>&1 + fi + if sudo iptables --table nat --check POSTROUTING --source $ip_range.0/24 --jump MASQUERADE 2> /dev/null + then + sudo iptables --table nat --delete POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$complete_log" 2>&1 + fi - echo "Disable the network bridge." - if sudo ifquery $lxc_bridge --state > /dev/null - then - sudo ifdown --force $lxc_bridge | tee --append "$test_result" 2>&1 - fi + echo "Disable the network bridge." + if sudo ifquery $lxc_bridge --state > /dev/null + then + sudo ifdown --force $lxc_bridge | tee --append "$complete_log" 2>&1 + fi - # Set snap0 as the current snapshot - current_snapshot=snap0 + # Set snap0 as the current snapshot + current_snapshot=snap0 } LXC_CONNECT_INFO () { - # Print access information + # Print access information - echo "> To access the container:" - echo "To execute one command:" - echo -e "\e[1msudo lxc-attach -n $lxc_name -- command\e[0m" + echo "> To access the container:" + echo "To execute one command:" + echo -e "\e[1msudo lxc-attach -n $lxc_name -- command\e[0m" - echo "To establish a ssh connection:" - if [ $(cat "$script_dir/sub_scripts/setup_user") = "root" ]; then - echo -ne "\e[1msudo " - fi - echo -e "\e[1mssh $arg_ssh $lxc_name\e[0m" + echo "To establish a ssh connection:" + if [ $(cat "$script_dir/sub_scripts/setup_user") = "root" ]; then + echo -ne "\e[1msudo " + fi + echo -e "\e[1mssh $arg_ssh $lxc_name\e[0m" } diff --git a/sub_scripts/log_extractor.sh b/sub_scripts/log_extractor.sh deleted file mode 100755 index 0c32493..0000000 --- a/sub_scripts/log_extractor.sh +++ /dev/null @@ -1,166 +0,0 @@ -#!/bin/bash - -echo "Loads functions from log_extractor.sh" - -ECHO_FORMAT () { - # Simply an echo with color and typo - # $2 = color - # $3 = typo - # Last arg = clog - - if [ "$2" == "red" ]; then - echo -en "\e[91m" - fi - if [ "$2" == "lyellow" ]; then - echo -en "\e[93m" - fi - if [ "$2" == "lgreen" ]; then - echo -en "\e[92m" - fi - if [ "$2" == "blue" ]; then - echo -en "\e[94m" - fi - if [ "$2" == "white" ]; then - echo -en "\e[97m" - fi - if [ "$3" == "bold" ]; then - echo -en "\e[1m" - fi - if [ "$3" == "underlined" ]; then - echo -en "\e[4m" - fi - local copy_log=-- - # If 'clog' is given as argument, the echo command will be duplicated into the complete log. - if [ "$2" == "clog" ] || [ "$3" == "clog" ] || [ "$4" == "clog" ]; then - copy_log="$complete_log" - fi - echo -en "$1" | tee -a "$test_result" "$copy_log" - echo -en "\e[0m" -} - -COPY_LOG () { - # Extract A small part of $yunohost_log. - # $1 = 1 or 2. If '1', count the number of line of the current log file. - # If '2', copy the log from the last read line. - - if [ $1 -eq 1 ]; then - # Count the number of lines in YunoHost log - log_line=$(sudo wc --lines "$yunohost_log" | cut --delimiter=' ' --fields=1) - # Ignore the first line, it's duplicated of the previous log - log_line=$(( $log_line + 1 )) - # Erase the temporary log - > "$temp_log" - fi - if [ $1 -eq 2 ]; then - # Copy the log from the last read line - sudo tail --lines=+$log_line "$yunohost_log" >> "$temp_log" - fi -} - -FALSE_ERRORS_DETECTION () { - # Detect false positive errors. - false_positive_error=0 - - # Detect network error - if grep --quiet "Network is unreachable" "$temp_result" - then - false_positive_error=1 - false_positive_error_cond="network" - fi - - # Detect DNS error - if grep --quiet "Temporary failure resolving" "$temp_result" - then - false_positive_error=1 - false_positive_error_cond="DNS failure" - fi - if grep --quiet "unable to resolve host address" "$temp_result" - then - false_positive_error=1 - false_positive_error_cond="DNS failure" - fi - - # Detect Corrupt source - if grep --quiet "Corrupt source" "$temp_result" - then - false_positive_error=1 - false_positive_error_cond="corrupt source" - fi -} - -PARSE_LOG () { - # Print all errors and warning found in the log. - - while read log_read_line - do - if echo "$log_read_line" | grep --quiet "^>ERROR: "; then - # Print a red "Error" - ECHO_FORMAT "Error:" "red" "underlined" - # And print the error itself - ECHO_FORMAT " $(echo "$log_read_line\n" | sed 's/^>ERROR: //')" "red" - YUNOHOST_RESULT=1 - YUNOHOST_REMOVE=1 - fi - if echo "$log_read_line" | grep --quiet "^>WARNING: "; then - # Print a yellow "Warning:" - ECHO_FORMAT "Warning:" "lyellow" "underlined" - # And print the warning itself - ECHO_FORMAT " $(echo "$log_read_line\n" | sed 's/^>WARNING: //')" "lyellow" - fi - if echo "$log_read_line" | grep --quiet "^>INFO: "; then - # Print a white "Info:" - ECHO_FORMAT "Info:" "white" "underlined" - # And print the info itself - ECHO_FORMAT " $(echo "$log_read_line\n" | sed 's/^>INFO: //')" "white" - fi - done < "$temp_result" -} - -CLEAR_LOG () { - # Remove all knew useless warning lines. - - # Useless warnings from wget - sed --in-place '/^>WARNING: yunohost\.hook - \[[[:digit:].]*\] *$/d' "$temp_result" # Empty line foregoing wget progression - sed --in-place '/^>WARNING: yunohost\.hook - \[[[:digit:].]*\] *[[:digit:]]*K \.* /d' "$temp_result" # Wget progression - sed --in-place '/% Total % Received % Xferd/d' "$temp_result" # Wget statistics - sed --in-place '/Dload Upload Total Spent/d' "$temp_result" # Wget statistics (again) - sed --in-place '/--:--:-- --:--:-- --:--:--/d' "$temp_result" # Wget statistics (Yes, again...) - - # Useless warning from yunohost backup. - sed --in-place '/^>WARNING: yunohost.backup backup_restore - \[[[:digit:].]*\] YunoHost est déjà installé$/d' "$temp_result" - - # "processing action" INFO lines - sed --in-place '/^>INFO: .* - processing action/d' "$temp_result" - # Clean INFO lines - sed --in-place 's/^\(>INFO: \)yunohost\.hook - \[[[:digit:].]*\]/\1/g' "$temp_result" - - # "This feature is experimental" - sed --in-place '/^>WARNING: .* This feature is experimental and not considered stable/d' "$temp_result" - - # "moulinette.core translate" - sed --in-place '/^>ERROR: moulinette.core translate/d' "$temp_result" - - # Empty lines - sed --in-place '/^$/d' "$temp_result" -} - -LOG_EXTRACTOR () { - # Analyse the log to extract "warning" and "error" lines - - # Copy the log from the last read line. - COPY_LOG 2 - - # Erase the temporary result file - > "$temp_result" - # Duplicate the part of the yunohost log into the complete log. - cat "$temp_log" >> "$complete_log" - # Find all errors, warnings and infos in the log file - grep --extended-regexp " ERROR | WARNING | INFO |yunohost.*: error:" "$temp_log" >> "$temp_result" - sed -i 's/^.* ERROR */>ERROR: /' "$temp_result" - sed -i 's/^.* WARNING */>WARNING: /' "$temp_result" - sed -i 's/^.* INFO */>INFO: /' "$temp_result" - - CLEAR_LOG # Remove all knew useless warning lines. - PARSE_LOG # Print all errors and warning found in the log. - FALSE_ERRORS_DETECTION # Detect if there's a temporary error that shouldn't impact the test. -} diff --git a/sub_scripts/lxc_build.sh b/sub_scripts/lxc_build.sh index e4c6ef7..a836712 100755 --- a/sub_scripts/lxc_build.sh +++ b/sub_scripts/lxc_build.sh @@ -83,7 +83,7 @@ sudo apt-get update >> "$LOG_BUILD_LXC" 2>&1 sudo apt-get install -y lxc lxctl >> "$LOG_BUILD_LXC" 2>&1 echo -e "\e[1m> Install git, curl and lynx\e[0m" | tee -a "$LOG_BUILD_LXC" -sudo apt-get install -y git curl lynx jq python3-pip >> "$LOG_BUILD_LXC" 2>&1 +sudo apt-get install -y git curl lynx jq python3-pip boxes >> "$LOG_BUILD_LXC" 2>&1 # For those who have disabled APT::Install-Recommends we need to manually install the following packages. sudo apt-get install -y debootstrap rsync bridge-utils >> "$LOG_BUILD_LXC" 2>&1 diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index 33a8d24..5ac461a 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -12,135 +12,124 @@ backup_hooks="conf_ssowat data_home conf_ynh_firewall conf_cron" #================================================= break_before_continue () { - # Make a break if auto_remove is set + # Make a break if auto_remove is set - if [ $auto_remove -eq 0 ] && [ $bash_mode -ne 1 ] - then - LXC_CONNECT_INFO # Print access information - read -p "Press a key to delete the application and continue...." < /dev/tty - fi -} - -check_false_positive_error () { - # Check if FALSE_ERRORS_DETECTION has detected an false positive error. - - # We will use - # check_false_positive_error || return $? - # to check the result of the function of propagate the result to parent functions. - - if [ $false_positive_error -eq 1 ] && [ $false_positive_error_loop -lt $max_false_positive_error_loop ]; then - # Return 75, for EX_TEMPFAIL from sysexits.h - return 75 + if [ $auto_remove -eq 0 ] && [ $bash_mode -ne 1 ] + then + LXC_CONNECT_INFO # Print access information + read -p "Press a key to delete the application and continue...." < /dev/tty fi } + #================================================= PRINT_YUNOHOST_VERSION () { - ECHO_FORMAT ">> YunoHost versions:\n" "white" "bold" clog - # Be sure that the container is running - LXC_START "true" - # Print the version of YunoHost from the LXC container - ssh $arg_ssh $lxc_name "sudo yunohost --version" + small_title "YunoHost versions" - # Get the version of YunoHost from the LXC container - ynh_version=$(ssh -q $lxc_name "sudo yunohost --version --output-as plain | grep -A4 moulinette | tail -n1 | sed 's@\.@@g' | cut -d+ -f1") + # Print the version of YunoHost from the LXC container + LXC_START "sudo yunohost --version" + + # Get the version of YunoHost from the LXC container + ynh_version=$(ssh -q $lxc_name "sudo yunohost --version --output-as json | jq '.yunohost.version' | tr -d '\"'") } #================================================= # Install and remove an app #================================================= +run_yunohost() { + + # --output-as none is to disable the json-like output for some commands like backup create + LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --output-as none --debug $1" \ + | grep -v --extended-regexp '^[0-9]+\s+.{1,15}DEBUG' \ + | grep -v 'processing action' + + returncode=${PIPESTATUS[0]} + check_witness_files + return $returncode +} + + SETUP_APP () { - # Install an application in a LXC container + # Install an application in a LXC container - # Uses the default snapshot - current_snapshot=snap0 + # 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 + # Exec the pre-install instruction, if there one + if [ -n "$pre_install" ] + then + small_title "Pre installation request" + # 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" | tee -a "$complete_log" + fi - # Install the application in a LXC container - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app install --force \"$package_dir\" -a \"$manifest_args_mod\"" + # Install the application in a LXC container + run_yunohost "app install --force '$package_dir' -a '$manifest_args_mod'" - # yunohost_result gets the return code of the installation - yunohost_result=$? + # yunohost_result gets the return code of the installation + yunohost_result=$? - # Print the result of the install command - if [ $yunohost_result -eq 0 ]; then - ECHO_FORMAT "Installation successful. ($yunohost_result)\n" "white" clog - else - ECHO_FORMAT "Installation failed. ($yunohost_result)\n" "white" clog - fi + # Print the result of the install command + if [ $yunohost_result -eq 0 ]; then + debug "Installation successful." + else + error "Installation failed. ($yunohost_result)" + fi - # Check all the witness files, to verify if them still here - check_witness_files - - # Retrieve the app id in the log. To manage the app after - ynh_app_id=$(sudo tac "$yunohost_log" | grep --only-matching --max-count=1 "YNH_APP_INSTANCE_NAME=[^ ]*" | cut --delimiter='=' --fields=2) - - # Analyse the log to extract "warning" and "error" lines - LOG_EXTRACTOR - check_false_positive_error || return $? + # Retrieve the app id in the log. To manage the app after + ynh_app_id=$(sudo tac "$yunohost_log" | grep --only-matching --max-count=1 "YNH_APP_INSTANCE_NAME=[^ ]*" | cut --delimiter='=' --fields=2) } STANDARD_SETUP_APP () { - # Try to find an existing snapshot for this install, or make an install + # Try to find an existing snapshot for this install, or make an install - # If it's a root install - if [ "$check_path" = "/" ] - then - # Check if a snapshot already exist for this install - if [ -z "$root_snapshot" ] - then - # Make an installation - SETUP_APP - check_false_positive_error || return $? + # If it's a root install + if [ "$check_path" = "/" ] + then + # Check if a snapshot already exist for this install + if [ -z "$root_snapshot" ] + then + # Make an installation + SETUP_APP - # Create a snapshot for this installation, to be able to reuse it instead of a new installation. - # But only if this installation has worked fine - if [ $yunohost_result -eq 0 ]; then - # Check if a snapshot already exist for a root install - if [ -z "$root_snapshot" ] - then - ECHO_FORMAT "\nCreate a snapshot for root installation.\n" "white" clog >> $complete_log - create_temp_backup 2 - root_snapshot=snap2 - fi + # Create a snapshot for this installation, to be able to reuse it instead of a new installation. + # But only if this installation has worked fine + if [ $yunohost_result -eq 0 ]; then + # Check if a snapshot already exist for a root install + if [ -z "$root_snapshot" ] + then + debug "Creating a snapshot for root installation." + create_temp_backup 2 + root_snapshot=snap2 fi - else - # Or uses an existing snapshot - ECHO_FORMAT "Uses an existing snapshot for root installation.\n" "white" clog >> $complete_log - use_temp_snapshot $root_snapshot - fi + fi + else + # Or uses an existing snapshot + debug "Reusing an existing snapshot for root installation." + use_temp_snapshot $root_snapshot + fi - # In case of sub path install, use another snapshot - else - # Check if a snapshot already exist for this install - if [ -z "$subpath_snapshot" ] - then - # Make an installation - SETUP_APP - check_false_positive_error || return $? + # In case of sub path install, use another snapshot + else + # Check if a snapshot already exist for this install + if [ -z "$subpath_snapshot" ] + then + # Make an installation + SETUP_APP # Create a snapshot for this installation, to be able to reuse it instead of a new installation. # But only if this installation has worked fine @@ -148,375 +137,359 @@ STANDARD_SETUP_APP () { # Check if a snapshot already exist for a subpath (or no_url) install if [ -z "$subpath_snapshot" ] then - ECHO_FORMAT "\nCreate a snapshot for sub path installation.\n" "white" clog >> $complete_log + debug "Creating a snapshot for sub path installation." create_temp_backup 1 root_snapshot=snap1 - fi fi - else - # Or uses an existing snapshot - ECHO_FORMAT "Uses an existing snapshot for sub path installation.\n" "white" clog >> $complete_log - use_temp_snapshot $subpath_snapshot - fi - fi + fi + else + # Or uses an existing snapshot + debug "Reusing an existing snapshot for sub path installation." + use_temp_snapshot $subpath_snapshot + fi + fi } REMOVE_APP () { - # Remove an application + # Remove an application - # Make a break if auto_remove is set - break_before_continue + # Make a break if auto_remove is set + break_before_continue - ECHO_FORMAT "\nRemoving the app...\n" "white" "bold" clog + small_title "Removing the app..." - # Remove the application from the LXC container - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app remove \"$ynh_app_id\"" + # Remove the application from the LXC container + run_yunohost "app remove '$ynh_app_id'" - # yunohost_remove gets the return code of the deletion - yunohost_remove=$? + # yunohost_remove gets the return code of the deletion + yunohost_remove=$? - # Print the result of the remove command - if [ "$yunohost_remove" -eq 0 ]; then - ECHO_FORMAT "Remove successful. ($yunohost_remove)\n" "white" clog - else - ECHO_FORMAT "Remove failed. ($yunohost_remove)\n" "white" clog - fi - - # Check all the witness files, to verify if them still here - check_witness_files + # Print the result of the remove command + if [ "$yunohost_remove" -eq 0 ]; then + debug "Remove successful." + else + error "Remove failed. ($yunohost_remove)" + fi } #================================================= # Try to access the app by its url #================================================= -CHECK_URL () { - # Try to access the app by its url +VALIDATE_THAT_APP_CAN_BE_ACCESSED () { - if [ $use_curl -eq 1 ] - then - ECHO_FORMAT "\nTry to access by url...\n" "white" "bold" + # Not checking this if this ain't relevant for the current test / app + if [ $use_curl -ne 1 ] + then + curl_error=0 + yuno_portal=0 + return + fi - # Force a skipped_uris if public mode is not set - if [ "$install_type" != "private" ] && [ "$install_type" != "public" ] && [ -z "$public_arg" ] - then - # Add a skipped_uris on / for the app - LXC_START "sudo yunohost app setting \"$ynh_app_id\" skipped_uris -v \"/\"" - # Regen the config of sso - LXC_START "sudo yunohost app ssowatconf" - ECHO_FORMAT "Public access forced by a skipped_uris to check.\n" "lyellow" "bold" - fi + small_title "Validating that the app can (or cannot) be accessed with its url..." - # Inform /etc/hosts with the IP of LXC to resolve the domain. - # This is set only here and not before to prevent to help the app's scripts - echo -e "$ip_range.2 $main_domain #package_check\n$ip_range.2 $sub_domain #package_check" | sudo tee --append /etc/hosts > /dev/null + # Force a skipped_uris if public mode is not set + if [ "$install_type" != "private" ] && [ "$install_type" != "public" ] && [ -z "$public_arg" ] + then + warning "Forcing public access using a skipped_uris setting" + # Add a skipped_uris on / for the app + run_yunohost "app setting '$ynh_app_id' skipped_uris -v \"/\"" + # Regen the config of sso + run_yunohost "app ssowatconf" + fi - # Try to resolv the domain during 10 seconds maximum. - local i=0 - for i in `seq 1 10`; do - curl --location --insecure $check_domain > /dev/null 2>&1 - # If curl return 6, it's an error "Could not resolve host" - if [ $? -ne 6 ]; then - # If not, curl is ready to work. - break - fi - echo -n . - sleep 1 - done + # Inform /etc/hosts with the IP of LXC to resolve the domain. + # This is set only here and not before to prevent to help the app's scripts + echo -e "$ip_range.2 $main_domain #package_check\n$ip_range.2 $sub_domain #package_check" | sudo tee --append /etc/hosts > /dev/null - # curl_error indicate the result of curl test - curl_error=0 - # 503 Service Unavailable can would have some time to work. - local http503=0 - # yuno_portal equal 1 if the test fall on the portal - yuno_portal=0 + # Try to resolv the domain during 10 seconds maximum. + local i=0 + for i in `seq 1 10`; do + curl --location --insecure $check_domain > /dev/null 2>&1 + # If curl return 6, it's an error "Could not resolve host" + if [ $? -ne 6 ]; then + # If not, curl is ready to work. + break + fi + echo -n . + sleep 1 + done - # Try to access to the url in 2 times, with a final / and without - i=1; while [ $i -ne 3 ] - do + # curl_error indicate the result of curl test + curl_error=0 + # 503 Service Unavailable can would have some time to work. + local http503=0 + # yuno_portal equal 1 if the test fall on the portal + yuno_portal=0 - # First time, try without final / - if [ $i -eq 1 ] - then - # If the last character is / - if [ "${check_path: -1}" = "/" ] - then - # Remove it - local curl_check_path="${check_path:0:${#check_path}-1}" - else - curl_check_path=$check_path - fi + # Try to access to the url in 2 times, with a final / and without + i=1; while [ $i -ne 3 ] + do - # The next loop will try the second test - i=2 - elif [ $i -eq 2 ] - then - # Second time, try with the final / + # First time, try without final / + if [ $i -eq 1 ] + then + # If the last character is / + if [ "${check_path: -1}" = "/" ] + then + # Remove it + local curl_check_path="${check_path:0:${#check_path}-1}" + else + curl_check_path=$check_path + fi - # If the last character isn't / - if [ "${check_path: -1}" != "/" ] - then - # Add it - curl_check_path="$check_path/" - else - curl_check_path=$check_path - fi + # The next loop will try the second test + i=2 + elif [ $i -eq 2 ] + then + # Second time, try with the final / - # The next loop will break the while loop - i=3 - fi + # If the last character isn't / + if [ "${check_path: -1}" != "/" ] + then + # Add it + curl_check_path="$check_path/" + else + curl_check_path=$check_path + fi - # Remove the previous curl output - rm -f "$script_dir/url_output" + # The next loop will break the while loop + i=3 + fi - # Call curl to try to access to the url of the app - curl --location --insecure --silent --show-error --write-out "%{http_code};%{url_effective}\n" $check_domain$curl_check_path --output "$script_dir/url_output" > "$script_dir/curl_print" + # Remove the previous curl output + rm -f "$script_dir/url_output" - # Analyze the result of curl command - if [ $? -ne 0 ] - then - ECHO_FORMAT "Connection error...\n" "red" "bold" - curl_error=1 - fi + # Call curl to try to access to the url of the app + curl --location --insecure --silent --show-error --write-out "%{http_code};%{url_effective}\n" $check_domain$curl_check_path --output "$script_dir/url_output" > "$script_dir/curl_print" - # Print informations about the connection - ECHO_FORMAT "Test url: $check_domain$curl_check_path\n" "white" - ECHO_FORMAT "Real url: $(cat "$script_dir/curl_print" | cut --delimiter=';' --fields=2)\n" "white" - local http_code=$(cat "$script_dir/curl_print" | cut -d ';' -f1) - ECHO_FORMAT "HTTP code: $http_code\n" "white" + # Analyze the result of curl command + if [ $? -ne 0 ] + then + error "Connection error..." + curl_error=1 + fi - # Analyze the http code - if [ "${http_code:0:1}" = "0" ] || [ "${http_code:0:1}" = "4" ] || [ "${http_code:0:1}" = "5" ] - then - # If the http code is a 0xx 4xx or 5xx, it's an error code. - curl_error=1 + # Print informations about the connection + local http_code=$(cat "$script_dir/curl_print" | cut -d ';' -f1) + test_url_details=" + Test url: $check_domain$curl_check_path + Real url: $(cat "$script_dir/curl_print" | cut --delimiter=';' --fields=2) + HTTP code: $http_code" + debug "$test_url_details" - # 401 is "Unauthorized", so is a answer of the server. So, it works! - test "${http_code}" = "401" && curl_error=0 + # Analyze the http code + if [ "${http_code:0:1}" = "0" ] || [ "${http_code:0:1}" = "4" ] || [ "${http_code:0:1}" = "5" ] + then + # If the http code is a 0xx 4xx or 5xx, it's an error code. + curl_error=1 - # 503 is Service Unavailable, it's a temporary error. - if [ "${http_code}" = "503" ] - then - curl_error=0 - ECHO_FORMAT "Service temporarily unavailable\n" "lyellow" "bold" - # 3 successive error are allowed - http503=$(( http503 + 1 )) - if [ $http503 -ge 3 ]; then - # Over 3, it's definitively an error - curl_error=1 - else - # Below 3 times, retry. - # Decrease the value of 'i' to retry the same test - i=$(( i - 1 )) - # Wait 1 second to let's some time to the 503 error - sleep 1 - # And retry immediately - continue - fi - fi + # 401 is "Unauthorized", so is a answer of the server. So, it works! + test "${http_code}" = "401" && curl_error=0 - if [ $curl_error -eq 1 ]; then - ECHO_FORMAT "The HTTP code show an error.\n" "white" "bold" clog - fi - fi + # 503 is Service Unavailable, it's a temporary error. + if [ "${http_code}" = "503" ] + then + curl_error=0 + warning "Service temporarily unavailable" + # 3 successive error are allowed + http503=$(( http503 + 1 )) + if [ $http503 -ge 3 ]; then + # Over 3, it's definitively an error + curl_error=1 + else + # Below 3 times, retry. + # Decrease the value of 'i' to retry the same test + i=$(( i - 1 )) + # Wait 1 second to let's some time to the 503 error + sleep 1 + # And retry immediately + continue + fi + fi - # Analyze the output of curl - if [ -e "$script_dir/url_output" ] - then - # Print the title of the page - local url_title=$(grep "" "$script_dir/url_output" | cut --delimiter='>' --fields=2 | cut --delimiter='<' --fields=1) - ECHO_FORMAT "Title of the page: $url_title\n" "white" + if [ $curl_error -eq 1 ]; then + error "The HTTP code shows an error." + fi + fi - # Check if the page title is neither the YunoHost portail or default nginx page - if [ "$url_title" = "YunoHost Portal" ] - then - ECHO_FORMAT "The connection attempt fall on the YunoHost portal.\n" "white" "bold" clog - yuno_portal=1 - else - yuno_portal=0 - if [ "$url_title" = "Welcome to nginx on Debian!" ] - then - # Falling on nginx default page is an error. - curl_error=1 - ECHO_FORMAT "The connection attempt fall on nginx default page.\n" "white" "bold" clog - fi + # Analyze the output of curl + if [ -e "$script_dir/url_output" ] + then + # Print the title of the page + local page_title=$(grep "<title>" "$script_dir/url_output" | cut --delimiter='>' --fields=2 | cut --delimiter='<' --fields=1) + debug "Title of the page: $page_title" - # Print the first 20 lines of the page - ECHO_FORMAT "Extract of the page:\n" "white" >> "$test_result" - echo -en "\e[37m" # Write in 'light grey' - lynx -dump -force_html "$script_dir/url_output" | head --lines 20 >> "$test_result" - echo -e "\e[0m" + # Check if the page title is neither the YunoHost portail or default nginx page + if [ "$page_title" = "YunoHost Portal" ] + then + debug "The connection attempt fall on the YunoHost portal." + yuno_portal=1 + else + yuno_portal=0 + if [ "$page_title" = "Welcome to nginx on Debian!" ] + then + # Falling on nginx default page is an error. + curl_error=1 + error "The connection attempt fall on nginx default page." + fi - if [ $show_resources -eq 1 ] - then - # Get all the resources for the main page of the app. - local HTTP_return - local moved=0 - local ignored=0 - while read HTTP_return - do - # Ignore robots.txt and ynhpanel.js. They always redirect to the portal. - if echo "$HTTP_return" | grep --quiet "$check_domain/robots.txt\|$check_domain/ynhpanel.js"; then - ECHO_FORMAT "Ressource ignored:" "white" - ECHO_FORMAT " ${HTTP_return##*http*://}\n" - ignored=1 - fi + # Print the first 20 lines of the page + debug "Extract of the page:" + page_extract=$(lynx -dump -force_html "$script_dir/url_output" | head --lines 20 | tee -a "$complete_log") - # If it's the line with the resource to get - if echo "$HTTP_return" | grep --quiet "^--.*-- http" - then - # Get only the resource itself. - local resource=${HTTP_return##*http*://} + if [ $show_resources -eq 1 ] + then + # Get all the resources for the main page of the app. + local HTTP_return + local moved=0 + local ignored=0 + while read HTTP_return + do + # Ignore robots.txt and ynhpanel.js. They always redirect to the portal. + if echo "$HTTP_return" | grep --quiet "$check_domain/robots.txt\|$check_domain/ynhpanel.js"; then + debug "Ressource ignored: ${HTTP_return##*http*://}" + ignored=1 + fi + # If it's the line with the resource to get + if echo "$HTTP_return" | grep --quiet "^--.*-- http" + then + # Get only the resource itself. + local resource=${HTTP_return##*http*://} # Else, if would be the HTTP return code. - else - # If the return code is different than 200. - if ! echo "$HTTP_return" | grep --quiet "200 OK$" + else + # If the return code is different than 200. + if ! echo "$HTTP_return" | grep --quiet "200 OK$" + then + # Skipped the check of ignored ressources. + if [ $ignored -eq 1 ] then - # Skipped the check of ignored ressources. - if [ $ignored -eq 1 ] - then - ignored=0 - continue - fi - # Isolate the http return code. - http_code="${HTTP_return##*awaiting response... }" - http_code="${http_code:0:3}" - # If the return code is 301 or 302, let's check the redirection. - if echo "$HTTP_return" | grep --quiet "30[12] Moved" - then - ECHO_FORMAT "Ressource moved:" "white" - ECHO_FORMAT " $resource\n" - moved=1 - else - ECHO_FORMAT "Resource unreachable (Code $http_code)" "red" "bold" - ECHO_FORMAT " $resource\n" -# curl_error=1 - moved=0 - fi + ignored=0 + continue + fi + # Isolate the http return code. + http_code="${HTTP_return##*awaiting response... }" + http_code="${http_code:0:3}" + # If the return code is 301 or 302, let's check the redirection. + if echo "$HTTP_return" | grep --quiet "30[12] Moved" + then + debug "Ressource moved: $resource" + moved=1 else - if [ $moved -eq 1 ] - then - if echo "$resource" | grep --quiet "/yunohost/sso/" - then - ECHO_FORMAT "The previous resource is redirected to the YunoHost portal\n" "red" -# curl_error=1 - fi - fi + error "Resource unreachable (Code $http_code) $resource" + #curl_error=1 moved=0 fi + else + if [ $moved -eq 1 ] + then + if echo "$resource" | grep --quiet "/yunohost/sso/" + then + error "The previous resource is redirected to the YunoHost portal" + #curl_error=1 + fi + fi + moved=0 fi - done <<< "$(cd "$package_path"; LC_ALL=C wget --adjust-extension --page-requisites --no-check-certificate $check_domain$curl_check_path 2>&1 | grep "^--.*-- http\|^HTTP request sent")" - fi - echo "" - fi - fi - done + fi + done <<< "$(cd "$package_path"; LC_ALL=C wget --adjust-extension --page-requisites --no-check-certificate $check_domain$curl_check_path 2>&1 | grep "^--.*-- http\|^HTTP request sent")" + fi + fi + fi + done - # Detect the issue alias_traversal, https://github.com/yandex/gixy/blob/master/docs/en/plugins/aliastraversal.md + if [[ curl_error -ne 0 ]] + then + warning "$test_url_details" + warning "Page title: $page_title" + warning "Page extract: $page_extract" + fi - # Create a file to get for alias_traversal - echo "<!DOCTYPE html><html><head> -<title>alias_traversal test -

alias_traversal test

-If you see this page, you have failed the test for alias_traversal issue." \ - | sudo tee /var/lib/lxc/$lxc_name/rootfs/var/www/html/alias_traversal.html > /dev/null + # Detect the issue alias_traversal, https://github.com/yandex/gixy/blob/master/docs/en/plugins/aliastraversal.md - curl --location --insecure --silent $check_domain$check_path../html/alias_traversal.html \ - | grep "title" | grep --quiet "alias_traversal test" \ - && ECHO_FORMAT "Issue alias_traversal detected ! Please see here https://github.com/YunoHost/example_ynh/pull/45 to fix that.\n" "red" "bold" && RESULT_alias_traversal=1 + # Create a file to get for alias_traversal + echo " + alias_traversal test +

alias_traversal test

+ If you see this page, you have failed the test for alias_traversal issue." \ + | sudo tee /var/lib/lxc/$lxc_name/rootfs/var/www/html/alias_traversal.html > /dev/null - # Remove the entries in /etc/hosts for the test domain - sudo sed --in-place '/#package_check/d' /etc/hosts - else - # If use_curl is set to 0, the url will not tried - ECHO_FORMAT "Connexion attempt aborted.\n" "white" - curl_error=0 - yuno_portal=0 - fi + curl --location --insecure --silent $check_domain$check_path../html/alias_traversal.html \ + | grep "title" | grep --quiet "alias_traversal test" \ + && error "Issue alias_traversal detected ! Please see here https://github.com/YunoHost/example_ynh/pull/45 to fix that." && RESULT_alias_traversal=1 + + # Remove the entries in /etc/hosts for the test domain + sudo sed --in-place '/#package_check/d' /etc/hosts } #================================================= # Generic functions for unit tests #================================================= -unit_test_title () { - # Print a title for the test - # $1 = Name of the test +start_test () { - ECHO_FORMAT "\n\n##########################################\n" "white" "bold" clog - ECHO_FORMAT "# >> $1 [Test $cur_test/$all_test]\n" "white" "bold" clog - ECHO_FORMAT "##########################################\n" "white" "bold" clog + title "$1 [Test $cur_test/$all_test]" - # Increment the value of the current test - cur_test=$((cur_test+1)) + # Increment the value of the current test + cur_test=$((cur_test+1)) } check_manifest_key () { - # Check if a manifest key is set - # $1 = manifest key + # Check if a manifest key is set + # $1 = manifest key - if [ -z "${1}_arg" ] - then - ECHO_FORMAT "Unable to find a manifest key for '${1,,}' in the check_process file. Impossible to perform this test\n" "red" clog - return 1 - fi + if [ -z "${1}_arg" ] # FIXME : How can this ever be true ? wtf ? + then + error "Unable to find a manifest key for '${1,,}' in the check_process file. therefore this test cannot be performed" + return 1 + fi } replace_manifest_key () { - # Replace a generic manifest key by another - # $1 = Manifest key - # $2 = Replacement value + # Replace a generic manifest key by another + # $1 = Manifest key + # $2 = Replacement value - # Build the variable name by concatenate $1 and _arg - local manifest_key=$(eval echo \$${1}_arg) + # Build the variable name by concatenate $1 and _arg + local manifest_key=$(eval echo \$${1}_arg) - if [ -n "$manifest_key" ] - then - manifest_args_mod=$(echo $manifest_args_mod | sed "s@$manifest_key=[^&]*\&@${manifest_key}=${2}\&@") - fi -} - -check_success () { - ECHO_FORMAT "--- SUCCESS ---\n" "lgreen" "bold" -} - -check_warning () { - ECHO_FORMAT "--- WARNING ---\n" "lyellow" "bold" -} - -check_failed () { - ECHO_FORMAT "--- FAIL ---\n" "red" "bold" + if [ -n "$manifest_key" ] + then + manifest_args_mod=$(echo $manifest_args_mod | sed "s@$manifest_key=[^&]*\&@${manifest_key}=${2}\&@") + fi } check_test_result () { - # Check the result and print SUCCESS or FAIL - if [ $yunohost_result -eq 0 ] && [ $curl_error -eq 0 ] && [ $yuno_portal -eq 0 ] - then - check_success - return 0 - else - check_failed - return 1 - fi + # Check the result and print SUCCESS or FAIL + + if [ $yunohost_result -eq 0 ] && [ $curl_error -eq 0 ] && [ $yuno_portal -eq 0 ] + then + report_test_success + return 0 + else + report_test_failed + return 1 + fi } check_test_result_remove () { - # Check the result of a remove and print SUCCESS or FAIL - if [ $yunohost_remove -eq 0 ] - then - check_success - return 0 - else - check_failed - return 1 - fi + # Check the result of a remove and print SUCCESS or FAIL + + if [ $yunohost_remove -eq 0 ] + then + report_test_success + return 0 + else + report_test_failed + return 1 + fi } is_install_failed () { - # Check if an install have previously work + # Check if an install have previously work # If the test for install in sub dir isn't desactivated sub_dir_install=0 @@ -551,9 +524,9 @@ is_install_failed () { if [ $sub_dir_install -eq 0 ] && [ $root_install -eq 0 ] then - ECHO_FORMAT "All installs have failed, impossible to perform this test...\n" "red" clog - return 1 - fi + error "All installs failed, therefore this test cannot be performed..." + return 1 + fi } #================================================= @@ -561,248 +534,234 @@ is_install_failed () { #================================================= CHECK_SETUP () { - # Try to install in a sub path, on root or without url access - # $1 = install type + # Try to install in a sub path, on root or without url access + # $1 = install type - local install_type=$1 - if [ "$install_type" = "subdir" ]; then - unit_test_title "Installation in a sub path..." - elif [ "$install_type" = "root" ]; then - unit_test_title "Installation on the root..." - else - unit_test_title "Installation without url access..." - # Disable the curl test - use_curl=0 - fi + local install_type=$1 + if [ "$install_type" = "subdir" ]; then + start_test "Installation in a sub path" + elif [ "$install_type" = "root" ]; then + start_test "Installation on the root" + else + start_test "Installation without url access" + # Disable the curl test + use_curl=0 + fi - # Check if the needed manifest key are set or abort the test - if [ "$install_type" != "no_url" ]; then - check_manifest_key "domain" || return - check_manifest_key "path" || return - fi + # Check if the needed manifest key are set or abort the test + if [ "$install_type" != "no_url" ]; then + check_manifest_key "domain" || return + check_manifest_key "path" || return + fi - # Copy original arguments - local manifest_args_mod="$manifest_arguments" + # Copy original arguments + local manifest_args_mod="$manifest_arguments" - # Replace manifest key for the test - check_domain=$sub_domain - replace_manifest_key "domain" "$check_domain" - if [ "$install_type" = "subdir" ]; then - local check_path=$test_path - elif [ "$install_type" = "root" ]; then - local check_path=/ - fi - replace_manifest_key "path" "$check_path" - replace_manifest_key "user" "$test_user" - replace_manifest_key "public" "$public_public_arg" + # Replace manifest key for the test + check_domain=$sub_domain + replace_manifest_key "domain" "$check_domain" + if [ "$install_type" = "subdir" ]; then + local check_path=$test_path + elif [ "$install_type" = "root" ]; then + local check_path=/ + fi + replace_manifest_key "path" "$check_path" + replace_manifest_key "user" "$test_user" + replace_manifest_key "public" "$public_public_arg" - # Install the application in a LXC container - SETUP_APP - check_false_positive_error || return $? + # Install the application in a LXC container + SETUP_APP - # Try to access the app by its url - CHECK_URL + # Try to access the app by its url + VALIDATE_THAT_APP_CAN_BE_ACCESSED - # Check the result and print SUCCESS or FAIL - if check_test_result - then # Success - RESULT_global_setup=1 # Installation succeed - local check_result_setup=1 # Installation succeed - else # Fail - # The global success for a installation can't be failed if another installation succeed - if [ $RESULT_global_setup -ne 1 ]; then - RESULT_global_setup=-1 # Installation failed - fi - local check_result_setup=-1 # Installation failed - fi + # Check the result and print SUCCESS or FAIL + if check_test_result + then # Success + RESULT_global_setup=1 # Installation succeed + local check_result_setup=1 # Installation succeed + else # Fail + # The global success for a installation can't be failed if another installation succeed + if [ $RESULT_global_setup -ne 1 ]; then + RESULT_global_setup=-1 # Installation failed + fi + local check_result_setup=-1 # Installation failed + fi - # Create a snapshot for this installation, to be able to reuse it instead of a new installation. - # But only if this installation has worked fine - if [ $check_result_setup -eq 1 ]; then - if [ "$check_path" = "/" ] - then - # Check if a snapshot already exist for a root install - if [ -z "$root_snapshot" ] - then - ECHO_FORMAT "Create a snapshot for root installation.\n" "white" clog >> $complete_log - create_temp_backup 2 - root_snapshot=snap2 - fi - else - # Check if a snapshot already exist for a subpath (or no_url) install - if [ -z "$subpath_snapshot" ] - then - # Then create a snapshot - ECHO_FORMAT "Create a snapshot for sub path installation.\n" "white" clog >> $complete_log - create_temp_backup 1 - subpath_snapshot=snap1 - fi - fi - fi + # Create a snapshot for this installation, to be able to reuse it instead of a new installation. + # But only if this installation has worked fine + if [ $check_result_setup -eq 1 ]; then + if [ "$check_path" = "/" ] + then + # Check if a snapshot already exist for a root install + if [ -z "$root_snapshot" ] + then + debug "Create a snapshot for root installation." + create_temp_backup 2 + root_snapshot=snap2 + fi + else + # Check if a snapshot already exist for a subpath (or no_url) install + if [ -z "$subpath_snapshot" ] + then + # Then create a snapshot + debug "Create a snapshot for sub path installation." + create_temp_backup 1 + subpath_snapshot=snap1 + fi + fi + fi - # Remove the application - REMOVE_APP + # Remove the application + REMOVE_APP - # Analyse the log to extract "warning" and "error" lines - LOG_EXTRACTOR - check_false_positive_error || return $? + # Check the result and print SUCCESS or FAIL + if check_test_result_remove + then # Success + local check_result_remove=1 # Remove in sub path succeed + RESULT_global_remove=1 # Remove succeed + else # Fail + # The global success for a deletion can't be failed if another remove succeed + if [ $RESULT_global_remove -ne 1 ]; + then + RESULT_global_remove=-1 # Remove failed + fi + local check_result_remove=-1 # Remove in sub path failed + fi - # Check the result and print SUCCESS or FAIL - if check_test_result_remove - then # Success - local check_result_remove=1 # Remove in sub path succeed - RESULT_global_remove=1 # Remove succeed - else # Fail - # The global success for a deletion can't be failed if another remove succeed - if [ $RESULT_global_remove -ne 1 ]; then - RESULT_global_remove=-1 # Remove failed - fi - local check_result_remove=-1 # Remove in sub path failed - fi + # Reinstall the application after the removing + # Try to resintall only if the first install is a success. + if [ $check_result_setup -eq 1 ] + then + small_title "Reinstall the application after a removing." - # Reinstall the application after the removing - # Try to resintall only if the first install is a success. - if [ $check_result_setup -eq 1 ] - then - ECHO_FORMAT "\nReinstall the application after a removing.\n" "white" "bold" clog - - SETUP_APP - check_false_positive_error || return $? + SETUP_APP - # Try to access the app by its url - CHECK_URL + # Try to access the app by its url + VALIDATE_THAT_APP_CAN_BE_ACCESSED - # Check the result and print SUCCESS or FAIL - if check_test_result - then # Success - local check_result_setup=1 # Installation succeed - else # Fail - local check_result_setup=-1 # Installation failed - fi - fi + # Check the result and print SUCCESS or FAIL + if check_test_result + then # Success + local check_result_setup=1 # Installation succeed + else # Fail + local check_result_setup=-1 # Installation failed + fi + fi - # Fill the correct variable depend on the type of test - if [ "$install_type" = "subdir" ] - then - RESULT_check_sub_dir=$check_result_setup - RESULT_check_remove_sub_dir=$check_result_remove - else # root and no_url - RESULT_check_root=$check_result_setup - RESULT_check_remove_root=$check_result_remove - fi + # Fill the correct variable depend on the type of test + if [ "$install_type" = "subdir" ] + then + RESULT_check_sub_dir=$check_result_setup + RESULT_check_remove_sub_dir=$check_result_remove + else # root and no_url + RESULT_check_root=$check_result_setup + RESULT_check_remove_root=$check_result_remove + fi - # Make a break if auto_remove is set - break_before_continue + # Make a break if auto_remove is set + break_before_continue } CHECK_UPGRADE () { - # Try the upgrade script + # Try the upgrade script - # Do an upgrade test for each commit in the upgrade list - while read <&4 commit - do - if [ "$commit" == "current" ] - then - unit_test_title "Upgrade from the same version..." - else - # Get the specific section for this upgrade from the check_process - extract_section "^; commit=$commit" "^;" "$check_process" - # Get the name for this upgrade. - upgrade_name=$(grep "^name=" "$partial_check_process" | cut -d'=' -f2) - # Or use the commit if there's no name. - if [ -z "$upgrade_name" ]; then - unit_test_title "Upgrade from the commit $commit..." - else - unit_test_title "Upgrade from $upgrade_name..." - fi - fi - - # Check if an install have previously work - # Abort if none install worked - is_install_failed || return - - # Copy original arguments - local manifest_args_mod="$manifest_arguments" - - # Replace manifest key for the test - check_domain=$sub_domain - replace_manifest_key "domain" "$check_domain" - # Use a path according to previous succeeded installs - if [ $sub_dir_install -eq 1 ]; then - local check_path=$test_path + # Do an upgrade test for each commit in the upgrade list + while read <&4 commit + do + if [ "$commit" == "current" ] + then + start_test "Upgrade from the same version" else - local check_path=/ - fi - replace_manifest_key "path" "$check_path" - replace_manifest_key "user" "$test_user" - replace_manifest_key "public" "$public_public_arg" + # Get the specific section for this upgrade from the check_process + extract_section "^; commit=$commit" "^;" "$check_process" + # Get the name for this upgrade. + upgrade_name=$(grep "^name=" "$partial_check_process" | cut -d'=' -f2) + # Or use the commit if there's no name. + if [ -z "$upgrade_name" ]; then + start_test "Upgrade from the commit $commit" + else + start_test "Upgrade from $upgrade_name" + fi + fi - # Install the application in a LXC container - ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog - if [ "$commit" == "current" ] - then - # If no commit is specified, use the current version. - STANDARD_SETUP_APP - check_false_positive_error || return $? - else - # Otherwise, use a specific commit - # Backup the modified arguments - update_manifest_args="$manifest_args_mod" - # Get the arguments of the manifest for this upgrade. - manifest_args_mod="$(grep "^manifest_arg=" "$partial_check_process" | cut -d'=' -f2-)" - if [ -z "$manifest_args_mod" ]; then - # If there's no specific arguments, use the previous one. - manifest_args_mod="$update_manifest_args" - else - # Otherwise, keep the new arguments, and replace the variables. - manifest_args_mod="${manifest_args_mod//DOMAIN/$check_domain}" - manifest_args_mod="${manifest_args_mod//PATH/$check_path}" - manifest_args_mod="${manifest_args_mod//USER/$test_user}" - fi - # Make a backup of the directory - sudo cp -a "$package_path" "${package_path}_back" - # Change to the specified commit - (cd "$package_path"; git checkout --force --quiet "$commit") - # Install the application - SETUP_APP - check_false_positive_error || return $? - # Then replace the backup - sudo rm -r "$package_path" - sudo mv "${package_path}_back" "$package_path" - # And restore the arguments for the manifest - manifest_args_mod="$update_manifest_args" - fi + # Check if an install have previously work + # Abort if none install worked + is_install_failed || return - # Check if the install had work - if [ $yunohost_result -ne 0 ] - then - ECHO_FORMAT "\nInstallation failed...\n" "red" "bold" - ECHO_FORMAT "\nUpgrade test ignored...\n" "red" "bold" - else - ECHO_FORMAT "\nUpgrade...\n" "white" "bold" clog + # Copy original arguments + local manifest_args_mod="$manifest_arguments" - # Upgrade the application in a LXC container - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app upgrade $ynh_app_id -f \"$package_dir\"" + # Replace manifest key for the test + check_domain=$sub_domain + replace_manifest_key "domain" "$check_domain" + # Use a path according to previous succeeded installs + if [ $sub_dir_install -eq 1 ]; then + local check_path=$test_path + else + local check_path=/ + fi + replace_manifest_key "path" "$check_path" + replace_manifest_key "user" "$test_user" + replace_manifest_key "public" "$public_public_arg" - # yunohost_result gets the return code of the upgrade - yunohost_result=$? + # Install the application in a LXC container + small_title "Preliminary install..." + if [ "$commit" == "current" ] + then + # If no commit is specified, use the current version. + STANDARD_SETUP_APP + else + # Otherwise, use a specific commit + # Backup the modified arguments + update_manifest_args="$manifest_args_mod" + # Get the arguments of the manifest for this upgrade. + manifest_args_mod="$(grep "^manifest_arg=" "$partial_check_process" | cut -d'=' -f2-)" + if [ -z "$manifest_args_mod" ]; then + # If there's no specific arguments, use the previous one. + manifest_args_mod="$update_manifest_args" + else + # Otherwise, keep the new arguments, and replace the variables. + manifest_args_mod="${manifest_args_mod//DOMAIN/$check_domain}" + manifest_args_mod="${manifest_args_mod//PATH/$check_path}" + manifest_args_mod="${manifest_args_mod//USER/$test_user}" + fi + # Make a backup of the directory + sudo cp -a "$package_path" "${package_path}_back" + # Change to the specified commit + (cd "$package_path"; git checkout --force --quiet "$commit") + # Install the application + SETUP_APP + # Then replace the backup + sudo rm -r "$package_path" + sudo mv "${package_path}_back" "$package_path" + # And restore the arguments for the manifest + manifest_args_mod="$update_manifest_args" + fi - # Print the result of the upgrade command - if [ $yunohost_result -eq 0 ]; then - ECHO_FORMAT "Upgrade successful. ($yunohost_result)\n" "white" clog - else - ECHO_FORMAT "Upgrade failed. ($yunohost_result)\n" "white" clog - fi + # Check if the install had work + if [ $yunohost_result -ne 0 ] + then + error "Installation failed..." + error "Upgrade test ignored..." + else + small_title "Upgrade..." - # Check all the witness files, to verify if them still here - check_witness_files + # Upgrade the application in a LXC container + run_yunohost "app upgrade $ynh_app_id -f '$package_dir'" - # Analyse the log to extract "warning" and "error" lines - LOG_EXTRACTOR - check_false_positive_error || return $? + # yunohost_result gets the return code of the upgrade + yunohost_result=$? - # Try to access the app by its url - CHECK_URL + # Print the result of the upgrade command + if [ $yunohost_result -eq 0 ]; then + debug "Upgrade successful." + else + error "Upgrade failed. ($yunohost_result)" + fi + + # Try to access the app by its url + VALIDATE_THAT_APP_CAN_BE_ACCESSED # Check the result and print SUCCESS or FAIL if check_test_result @@ -817,683 +776,657 @@ CHECK_UPGRADE () { # Remove the application REMOVE_APP - fi + fi - # Uses the default snapshot - current_snapshot=snap0 - # Stop and restore the LXC container - LXC_STOP >> $complete_log - done 4< "$script_dir/upgrade_list" + # Uses the default snapshot + current_snapshot=snap0 + # Stop and restore the LXC container + LXC_STOP >> $complete_log + done 4< "$script_dir/upgrade_list" } CHECK_PUBLIC_PRIVATE () { - # Try to install in public or private mode - # $1 = install type + # Try to install in public or private mode + # $1 = install type - local install_type=$1 - if [ "$install_type" = "private" ]; then - unit_test_title "Installation in private mode..." - else [ "$install_type" = "public" ] - unit_test_title "Installation in public mode..." - fi + local install_type=$1 + if [ "$install_type" = "private" ]; then + start_test "Installation in private mode" + else [ "$install_type" = "public" ] + start_test "Installation in public mode" + fi - # Check if the needed manifest key are set or abort the test - check_manifest_key "public" || return - check_manifest_key "public_public" || return - check_manifest_key "public_private" || return + # Check if the needed manifest key are set or abort the test + check_manifest_key "public" || return + check_manifest_key "public_public" || return + check_manifest_key "public_private" || return - # Check if an install have previously work - is_install_failed || return + # Check if an install have previously work + is_install_failed || return - # Copy original arguments - local manifest_args_mod="$manifest_arguments" + # Copy original arguments + local manifest_args_mod="$manifest_arguments" - # Replace manifest key for the test - check_domain=$sub_domain - replace_manifest_key "domain" "$check_domain" - replace_manifest_key "user" "$test_user" - # Set public or private according to type of test requested - if [ "$install_type" = "private" ]; then - replace_manifest_key "public" "$public_private_arg" - elif [ "$install_type" = "public" ]; then - replace_manifest_key "public" "$public_public_arg" - fi + # Replace manifest key for the test + check_domain=$sub_domain + replace_manifest_key "domain" "$check_domain" + replace_manifest_key "user" "$test_user" + # Set public or private according to type of test requested + if [ "$install_type" = "private" ]; then + replace_manifest_key "public" "$public_private_arg" + elif [ "$install_type" = "public" ]; then + replace_manifest_key "public" "$public_public_arg" + fi - # Initialize the value - local check_result_public_private=0 + # Initialize the value + local check_result_public_private=0 - # Try in 2 times, first in root and second in sub path. - local i=0 - for i in 0 1 - do - # First, try with a root install - if [ $i -eq 0 ] - then - # Check if root installation worked - if [ $root_install -eq 1 ] - then - # Replace manifest key for path - local check_path=/ - replace_manifest_key "path" "$check_path" - else - # Jump to the second path if this check cannot be do - ECHO_FORMAT "Root install failed, impossible to perform this test...\n" "lyellow" clog - continue - fi + # Try in 2 times, first in root and second in sub path. + local i=0 + for i in 0 1 + do + # First, try with a root install + if [ $i -eq 0 ] + then + # Check if root installation worked + if [ $root_install -eq 1 ] + then + # Replace manifest key for path + local check_path=/ + replace_manifest_key "path" "$check_path" + else + # Jump to the second path if this check cannot be do + warning "Root install failed, therefore this test cannot be performed..." + continue + fi - # Second, try with a sub path install - elif [ $i -eq 1 ] - then - # Check if sub path installation worked, or if force_install_ok is setted. - if [ $sub_dir_install -eq 1 ] - then - # Replace manifest key for path - local check_path=$test_path - replace_manifest_key "path" "$check_path" - else - # Jump to the second path if this check cannot be do - ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "lyellow" clog - return - fi - fi + # Second, try with a sub path install + elif [ $i -eq 1 ] + then + # Check if sub path installation worked, or if force_install_ok is setted. + if [ $sub_dir_install -eq 1 ] + then + # Replace manifest key for path + local check_path=$test_path + replace_manifest_key "path" "$check_path" + else + # Jump to the second path if this check cannot be do + warning "Sub path install failed, therefore this test cannot be performed..." + return + fi + fi - # Install the application in a LXC container - SETUP_APP - check_false_positive_error || return $? + # Install the application in a LXC container + SETUP_APP - # Try to access the app by its url - CHECK_URL + # Try to access the app by its url + VALIDATE_THAT_APP_CAN_BE_ACCESSED - # Change the result according to the results of the curl test - if [ "$install_type" = "private" ] - then - # In private mode, if curl doesn't fell on the ynh portal, it's a fail. - if [ $yuno_portal -eq 0 ]; then - ECHO_FORMAT "App is not private: it should redirect to the Yunohost portal, but is publicly accessible instead\n" "lyellow" clog - yunohost_result=1 - fi - elif [ "$install_type" = "public" ] - then - # In public mode, if curl fell on the ynh portal, it's a fail. - if [ $yuno_portal -eq 1 ]; then - ECHO_FORMAT "App page is not public: it should be publicly accessible, but redirects to the Yunohost portal instead\n" "lyellow" clog - yunohost_result=1 - fi - fi + # Change the result according to the results of the curl test + if [ "$install_type" = "private" ] + then + # In private mode, if curl doesn't fell on the ynh portal, it's a fail. + if [ $yuno_portal -eq 0 ]; then + error "App is not private: it should redirect to the Yunohost portal, but is publicly accessible instead" + yunohost_result=1 + fi + elif [ "$install_type" = "public" ] + then + # In public mode, if curl fell on the ynh portal, it's a fail. + if [ $yuno_portal -eq 1 ]; then + error "App page is not public: it should be publicly accessible, but redirects to the Yunohost portal instead" + yunohost_result=1 + fi + fi - # Check the result and print SUCCESS or FAIL - if [ $yunohost_result -eq 0 ] && [ $curl_error -eq 0 ] - then # Success - check_success - # The global success for public/private mode can't be a success if another installation failed - if [ $check_result_public_private -ne -1 ]; then - check_result_public_private=1 # Installation succeed - fi - else # Fail - check_failed - check_result_public_private=-1 # Installation failed - fi + # Check the result and print SUCCESS or FAIL + if [ $yunohost_result -eq 0 ] && [ $curl_error -eq 0 ] + then + report_test_success + # The global success for public/private mode can't be a success if another installation failed + if [ $check_result_public_private -ne -1 ]; then + check_result_public_private=1 # Installation succeed + fi + else + report_test_failed + check_result_public_private=-1 # Installation failed + fi - # Fill the correct variable depend on the type of test - if [ "$install_type" = "private" ] - then - RESULT_check_private=$check_result_public_private - else # public - RESULT_check_public=$check_result_public_private - fi + # Fill the correct variable depend on the type of test + if [ "$install_type" = "private" ] + then + RESULT_check_private=$check_result_public_private + else # public + RESULT_check_public=$check_result_public_private + fi - # Make a break if auto_remove is set - break_before_continue + # Make a break if auto_remove is set + break_before_continue - # Stop and restore the LXC container - LXC_STOP >> $complete_log - done + # Stop and restore the LXC container + LXC_STOP >> $complete_log + done } CHECK_MULTI_INSTANCE () { - # Try multi-instance installations + # Try multi-instance installations - unit_test_title "Multi-instance installations..." + start_test "Multi-instance installations" - # Check if an install have previously work - is_install_failed || return + # Check if an install have previously work + is_install_failed || return - # Copy original arguments - local manifest_args_mod="$manifest_arguments" + # Copy original arguments + local manifest_args_mod="$manifest_arguments" - # Replace manifest key for the test - if [ $sub_dir_install -eq 1 ]; then - local check_path=$test_path - else - local check_path=/ - fi - replace_manifest_key "path" "$check_path" + # Replace manifest key for the test + if [ $sub_dir_install -eq 1 ]; then + local check_path=$test_path + else + local check_path=/ + fi + replace_manifest_key "path" "$check_path" - replace_manifest_key "user" "$test_user" - replace_manifest_key "public" "$public_public_arg" + replace_manifest_key "user" "$test_user" + replace_manifest_key "public" "$public_public_arg" - # Install 2 times the same app - local i=0 - for i in 1 2 - do - # First installation - if [ $i -eq 1 ] - then - check_domain=$main_domain - ECHO_FORMAT "First installation: path=$check_domain$check_path\n" clog - # Second installation - elif [ $i -eq 2 ] - then - check_domain=$sub_domain - ECHO_FORMAT "Second installation: path=$check_domain$check_path\n" clog - fi + # Install 2 times the same app + local i=0 + for i in 1 2 + do + # First installation + if [ $i -eq 1 ] + then + check_domain=$main_domain + small_title "First installation: path=$check_domain$check_path" + # Second installation + elif [ $i -eq 2 ] + then + check_domain=$sub_domain + small_title "Second installation: path=$check_domain$check_path" + fi - # Replace path and domain manifest keys for the test - replace_manifest_key "domain" "$check_domain" + # Replace path and domain manifest keys for the test + replace_manifest_key "domain" "$check_domain" - # Install the application in a LXC container - SETUP_APP - check_false_positive_error || return $? + # Install the application in a LXC container + SETUP_APP - # Store the result in the correct variable - # First installation - if [ $i -eq 1 ] - then - local multi_yunohost_result_1=$yunohost_result - local ynh_app_id_1=$ynh_app_id - # Second installation - elif [ $i -eq 2 ] - then - local multi_yunohost_result_2=$yunohost_result - local ynh_app_id_2=$ynh_app_id - fi - done + # Store the result in the correct variable + # First installation + if [ $i -eq 1 ] + then + local multi_yunohost_result_1=$yunohost_result + local ynh_app_id_1=$ynh_app_id + # Second installation + elif [ $i -eq 2 ] + then + local multi_yunohost_result_2=$yunohost_result + local ynh_app_id_2=$ynh_app_id + fi + done - # Try to access to the 2 apps by theirs url - for i in 1 2 - do - # First app - if [ $i -eq 1 ] - then - check_domain=$main_domain - ynh_app_id=$ynh_app_id_1 - # Second app - elif [ $i -eq 2 ] - then - check_domain=$sub_domain - ynh_app_id=$ynh_app_id_2 - fi + # Try to access to the 2 apps by theirs url + for i in 1 2 + do + # First app + if [ $i -eq 1 ] + then + check_domain=$main_domain + ynh_app_id=$ynh_app_id_1 + # Second app + elif [ $i -eq 2 ] + then + check_domain=$sub_domain + ynh_app_id=$ynh_app_id_2 + fi - # Try to access the app by its url - CHECK_URL + # Try to access the app by its url + VALIDATE_THAT_APP_CAN_BE_ACCESSED - # Check the result of curl test - if [ $curl_error -ne 0 ] || [ $yuno_portal -ne 0 ] - then - # The test failed if curl fell on ynh portal or had an error. - # First app - if [ $i -eq 1 ] - then - multi_yunohost_result_1=1 - # Second app - elif [ $i -eq 2 ] - then - multi_yunohost_result_2=1 - fi - fi - done + # Check the result of curl test + if [ $curl_error -ne 0 ] || [ $yuno_portal -ne 0 ] + then + # The test failed if curl fell on ynh portal or had an error. + # First app + if [ $i -eq 1 ] + then + multi_yunohost_result_1=1 + # Second app + elif [ $i -eq 2 ] + then + multi_yunohost_result_2=1 + fi + fi + done - # Check the result and print SUCCESS or FAIL - # Succeed if the 2 installations work; - if [ $multi_yunohost_result_1 -eq 0 ] && [ $multi_yunohost_result_2 -eq 0 ] - then # Success - check_success - RESULT_check_multi_instance=1 - else # Fail - check_failed - RESULT_check_multi_instance=-1 - fi + # Check the result and print SUCCESS or FAIL + # Succeed if the 2 installations work; + if [ $multi_yunohost_result_1 -eq 0 ] && [ $multi_yunohost_result_2 -eq 0 ] + then # Success + report_test_success + RESULT_check_multi_instance=1 + else # Fail + report_test_failed + RESULT_check_multi_instance=-1 + fi - # Make a break if auto_remove is set - break_before_continue + # Make a break if auto_remove is set + break_before_continue } CHECK_COMMON_ERROR () { - # Try to install with specific complications - # $1 = install type + # Try to install with specific complications + # $1 = install type - local install_type=$1 - if [ "$install_type" = "incorrect_path" ]; then - unit_test_title "Malformed path..." - # Check if the needed manifest key are set or abort the test - check_manifest_key "path" || return - else [ "$install_type" = "port_already_use" ] - unit_test_title "Port already used..." - # Check if the needed manifest key are set or abort the test - check_manifest_key "port" || return - fi + local install_type=$1 + if [ "$install_type" = "incorrect_path" ]; then + start_test "Malformed path" + # Check if the needed manifest key are set or abort the test + check_manifest_key "path" || return + else [ "$install_type" = "port_already_use" ] + start_test "Port already used" + # Check if the needed manifest key are set or abort the test + check_manifest_key "port" || return + fi - # Check if an install have previously work - is_install_failed || return + # Check if an install have previously work + is_install_failed || return - # Copy original arguments - local manifest_args_mod="$manifest_arguments" + # Copy original arguments + local manifest_args_mod="$manifest_arguments" - # Replace manifest key for the test - check_domain=$sub_domain - replace_manifest_key "domain" "$check_domain" - replace_manifest_key "user" "$test_user" - replace_manifest_key "public" "$public_public_arg" + # Replace manifest key for the test + check_domain=$sub_domain + replace_manifest_key "domain" "$check_domain" + replace_manifest_key "user" "$test_user" + replace_manifest_key "public" "$public_public_arg" - # Replace path manifest key for the test - if [ "$install_type" = "incorrect_path" ]; then - # Change the path from /path to path/ - local wrong_path=${test_path#/}/ - # Use this wrong path only for the arguments that will give to yunohost for installation. - replace_manifest_key "path" "$wrong_path" - local check_path=$test_path - else [ "$install_type" = "port_already_use" ] - # Use a path according to previous succeeded installs - if [ $sub_dir_install -eq 1 ]; then - local check_path=$test_path - else - local check_path=/ - fi - replace_manifest_key "path" "$check_path" - fi + # Replace path manifest key for the test + if [ "$install_type" = "incorrect_path" ]; then + # Change the path from /path to path/ + local wrong_path=${test_path#/}/ + # Use this wrong path only for the arguments that will give to yunohost for installation. + replace_manifest_key "path" "$wrong_path" + local check_path=$test_path + else [ "$install_type" = "port_already_use" ] + # Use a path according to previous succeeded installs + if [ $sub_dir_install -eq 1 ]; then + local check_path=$test_path + else + local check_path=/ + fi + replace_manifest_key "path" "$check_path" + fi - # Open the specified port to force the script to find another - if [ "$install_type" = "port_already_use" ] - then + # Open the specified port to force the script to find another + if [ "$install_type" = "port_already_use" ] + then - # If the first character is a #, that means it this port number is not in the manifest - if [ "${port_arg:0:1}" = "#" ] - then - # Retrieve the port number - local check_port="${port_arg:1}" + # If the first character is a #, that means it this port number is not in the manifest + if [ "${port_arg:0:1}" = "#" ] + then + # Retrieve the port number + local check_port="${port_arg:1}" - # Else, the port number is in the manifest. So the port number is set at a fixed value. - else - local check_port=6660 - # Replace port manifest key for the test - replace_manifest_key "port" "$check_port" - fi + # Else, the port number is in the manifest. So the port number is set at a fixed value. + else + local check_port=6660 + # Replace port manifest key for the test + replace_manifest_key "port" "$check_port" + fi - # Build a service with netcat for use this port before the app. - echo -e "[Service]\nExecStart=/bin/netcat -l -k -p $check_port\n - [Install]\nWantedBy=multi-user.target" | \ - sudo tee "/var/lib/lxc/$lxc_name/rootfs/etc/systemd/system/netcat.service" \ - > /dev/null + # Build a service with netcat for use this port before the app. + echo -e "[Service]\nExecStart=/bin/netcat -l -k -p $check_port\n + [Install]\nWantedBy=multi-user.target" | \ + sudo tee "/var/lib/lxc/$lxc_name/rootfs/etc/systemd/system/netcat.service" \ + > /dev/null - # Then start this service to block this port. - LXC_START "sudo systemctl enable netcat & sudo systemctl start netcat" - fi + # Then start this service to block this port. + LXC_START "sudo systemctl enable netcat & sudo systemctl start netcat" + fi - # Install the application in a LXC container - SETUP_APP - check_false_positive_error || return $? + # Install the application in a LXC container + SETUP_APP - # Try to access the app by its url - CHECK_URL + # Try to access the app by its url + VALIDATE_THAT_APP_CAN_BE_ACCESSED - # Check the result and print SUCCESS or FAIL - if check_test_result - then # Success - local check_result_setup=1 - else # Fail - local check_result_setup=-1 - fi + # Check the result and print SUCCESS or FAIL + if check_test_result + then # Success + local check_result_setup=1 + else # Fail + local check_result_setup=-1 + fi - # Fill the correct variable depend on the type of test - if [ "$install_type" = "incorrect_path" ] - then - RESULT_check_path=$check_result_setup - elif [ "$install_type" = "port_already_use" ]; then - RESULT_check_port=$check_result_setup - fi + # Fill the correct variable depend on the type of test + if [ "$install_type" = "incorrect_path" ] + then + RESULT_check_path=$check_result_setup + elif [ "$install_type" = "port_already_use" ]; then + RESULT_check_port=$check_result_setup + fi - # Make a break if auto_remove is set - break_before_continue + # Make a break if auto_remove is set + break_before_continue } CHECK_BACKUP_RESTORE () { - # Try to backup then restore the app + # Try to backup then restore the app - unit_test_title "Backup/Restore..." + start_test "Backup/Restore" - # Check if an install have previously work - is_install_failed || return + # Check if an install have previously work + is_install_failed || return - # Copy original arguments - local manifest_args_mod="$manifest_arguments" + # Copy original arguments + local manifest_args_mod="$manifest_arguments" - # Replace manifest key for the test - check_domain=$sub_domain - replace_manifest_key "domain" "$check_domain" - replace_manifest_key "user" "$test_user" - replace_manifest_key "public" "$public_public_arg" + # Replace manifest key for the test + check_domain=$sub_domain + replace_manifest_key "domain" "$check_domain" + replace_manifest_key "user" "$test_user" + replace_manifest_key "public" "$public_public_arg" - # Try in 2 times, first in root and second in sub path. - local i=0 - for i in 0 1 - do - # First, try with a root install - if [ $i -eq 0 ] - then - # Check if root installation worked, or if force_install_ok is setted. - if [ $root_install -eq 1 ] - then - # Replace manifest key for path - local check_path=/ - replace_manifest_key "path" "$check_path" - ECHO_FORMAT "\nPreliminary installation on the root...\n" "white" "bold" clog - else - # Jump to the second path if this check cannot be do - ECHO_FORMAT "Root install failed, impossible to perform this test...\n" "lyellow" clog - continue - fi + # Try in 2 times, first in root and second in sub path. + local i=0 + for i in 0 1 + do + # First, try with a root install + if [ $i -eq 0 ] + then + # Check if root installation worked, or if force_install_ok is setted. + if [ $root_install -eq 1 ] + then + # Replace manifest key for path + local check_path=/ + replace_manifest_key "path" "$check_path" + small_title "Preliminary installation on the root..." + else + # Jump to the second path if this check cannot be do + warning "Root install failed, therefore this test cannot be performed..." + continue + fi - # Second, try with a sub path install - elif [ $i -eq 1 ] - then - # Check if sub path installation worked, or if force_install_ok is setted. - if [ $sub_dir_install -eq 1 ] - then - # Replace manifest key for path - local check_path=$test_path - replace_manifest_key "path" "$check_path" - ECHO_FORMAT "\nPreliminary installation in a sub path...\n" "white" "bold" clog - else - # Jump to the second path if this check cannot be do - ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "lyellow" clog - return - fi - fi + # Second, try with a sub path install + elif [ $i -eq 1 ] + then + # Check if sub path installation worked, or if force_install_ok is setted. + if [ $sub_dir_install -eq 1 ] + then + # Replace manifest key for path + local check_path=$test_path + replace_manifest_key "path" "$check_path" + small_title "Preliminary installation in a sub path..." "white" "bold" clog + else + # Jump to the second path if this check cannot be do + warning "Sub path install failed, therefore this test cannot be performed..." + return + fi + fi - # Install the application in a LXC container - STANDARD_SETUP_APP - check_false_positive_error || return $? + # Install the application in a LXC container + STANDARD_SETUP_APP - # Remove the previous residual backups - sudo rm -rf /var/lib/lxc/$lxc_name/rootfs/home/yunohost.backup/archives - sudo rm -rf /var/lib/lxcsnaps/$lxc_name/$current_snapshot/rootfs/home/yunohost.backup/archives + # Remove the previous residual backups + sudo rm -rf /var/lib/lxc/$lxc_name/rootfs/home/yunohost.backup/archives + sudo rm -rf /var/lib/lxcsnaps/$lxc_name/$current_snapshot/rootfs/home/yunohost.backup/archives - # BACKUP - # Made a backup if the installation succeed - if [ $yunohost_result -ne 0 ] - then - ECHO_FORMAT "\nInstallation failed...\n" "red" "bold" - else - ECHO_FORMAT "\nBackup of the application...\n" "white" "bold" clog + # BACKUP + # Made a backup if the installation succeed + if [ $yunohost_result -ne 0 ] + then + error "Installation failed..." + else + small_title "Backup of the application..." - # Made a backup of the application - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug backup create -n Backup_test --apps $ynh_app_id --system $backup_hooks" + # Made a backup of the application + run_yunohost "backup create -n Backup_test --apps $ynh_app_id --system $backup_hooks" - # yunohost_result gets the return code of the backup - yunohost_result=$? + # yunohost_result gets the return code of the backup + yunohost_result=$? - # Print the result of the backup command - if [ $yunohost_result -eq 0 ]; then - ECHO_FORMAT "Backup successful. ($yunohost_result)\n" "white" clog - else - ECHO_FORMAT "Backup failed. ($yunohost_result)\n" "white" clog - fi + # Print the result of the backup command + if [ $yunohost_result -eq 0 ]; then + debug "Backup successful" + else + error "Backup failed. ($yunohost_result)" + fi + fi - # Check all the witness files, to verify if them still here - check_witness_files + # Check the result and print SUCCESS or FAIL + if [ $yunohost_result -eq 0 ] + then # Success + report_test_success + # The global success for a backup can't be a success if another backup failed + if [ $RESULT_check_backup -ne -1 ]; then + RESULT_check_backup=1 # Backup succeed + fi + else # Fail + report_test_failed + RESULT_check_backup=-1 # Backup failed + fi - # Analyse the log to extract "warning" and "error" lines - LOG_EXTRACTOR - check_false_positive_error || return $? - fi + # Grab the backup archive into the LXC container, and keep a copy + sudo cp -a /var/lib/lxc/$lxc_name/rootfs/home/yunohost.backup/archives ./ - # Check the result and print SUCCESS or FAIL - if [ $yunohost_result -eq 0 ] - then # Success - check_success - # The global success for a backup can't be a success if another backup failed - if [ $RESULT_check_backup -ne -1 ]; then - RESULT_check_backup=1 # Backup succeed - fi - else # Fail - check_failed - RESULT_check_backup=-1 # Backup failed - fi + # RESTORE + # Try the restore process in 2 times, first after removing the app, second after a restore of the container. + local j=0 + for j in 0 1 + do + # First, simply remove the application + if [ $j -eq 0 ] + then + # Remove the application + REMOVE_APP - # Grab the backup archive into the LXC container, and keep a copy - sudo cp -a /var/lib/lxc/$lxc_name/rootfs/home/yunohost.backup/archives ./ + small_title "Restore after removing the application..." - # RESTORE - # Try the restore process in 2 times, first after removing the app, second after a restore of the container. - local j=0 - for j in 0 1 - do - # First, simply remove the application - if [ $j -eq 0 ] - then - # Remove the application - REMOVE_APP + # Second, restore the whole container to remove completely the application + elif [ $j -eq 1 ] + then + # Uses the default snapshot + current_snapshot=snap0 - ECHO_FORMAT "\nRestore after removing the application...\n" "white" "bold" clog + # Remove the previous residual backups + sudo rm -rf /var/lib/lxcsnaps/$lxc_name/$current_snapshot/rootfs/home/yunohost.backup/archives - # Second, restore the whole container to remove completely the application - elif [ $j -eq 1 ] - then - # Uses the default snapshot - current_snapshot=snap0 + # Place the copy of the backup archive in the container. + sudo mv -f ./archives /var/lib/lxcsnaps/$lxc_name/$current_snapshot/rootfs/home/yunohost.backup/ - # Remove the previous residual backups - sudo rm -rf /var/lib/lxcsnaps/$lxc_name/$current_snapshot/rootfs/home/yunohost.backup/archives + # Stop and restore the LXC container + LXC_STOP >> $complete_log - # Place the copy of the backup archive in the container. - sudo mv -f ./archives /var/lib/lxcsnaps/$lxc_name/$current_snapshot/rootfs/home/yunohost.backup/ + small_title "Restore on a clean YunoHost system..." + fi - # Stop and restore the LXC container - LXC_STOP >> $complete_log + # Restore the application from the previous backup + run_yunohost "backup restore Backup_test --force --apps $ynh_app_id" - ECHO_FORMAT "\nRestore on a clean YunoHost system...\n" "white" "bold" clog - fi + # yunohost_result gets the return code of the restore + yunohost_result=$? - # Restore the application from the previous backup - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug backup restore Backup_test --force --apps $ynh_app_id" + # Print the result of the backup command + if [ $yunohost_result -eq 0 ]; then + debug "Restore successful." + else + error "Restore failed. ($yunohost_result)" + fi - # yunohost_result gets the return code of the restore - yunohost_result=$? + # Try to access the app by its url + VALIDATE_THAT_APP_CAN_BE_ACCESSED - # Print the result of the backup command - if [ $yunohost_result -eq 0 ]; then - ECHO_FORMAT "Restore successful. ($yunohost_result)\n" "white" clog - else - ECHO_FORMAT "Restore failed. ($yunohost_result)\n" "white" clog - fi + # Check the result and print SUCCESS or FAIL + if check_test_result + then # Success + # The global success for a restore can't be a success if another restore failed + if [ $RESULT_check_restore -ne -1 ]; then + RESULT_check_restore=1 # Restore succeed + fi + else # Fail + RESULT_check_restore=-1 # Restore failed + fi - # Check all the witness files, to verify if them still here - check_witness_files + # Make a break if auto_remove is set + break_before_continue - # Analyse the log to extract "warning" and "error" lines - LOG_EXTRACTOR - check_false_positive_error || return $? - - # Try to access the app by its url - CHECK_URL - - # Check the result and print SUCCESS or FAIL - if check_test_result - then # Success - # The global success for a restore can't be a success if another restore failed - if [ $RESULT_check_restore -ne -1 ]; then - RESULT_check_restore=1 # Restore succeed - fi - else # Fail - RESULT_check_restore=-1 # Restore failed - fi - - # Make a break if auto_remove is set - break_before_continue - - # Stop and restore the LXC container - LXC_STOP >> $complete_log - done - done + # Stop and restore the LXC container + LXC_STOP >> $complete_log + done + done } CHECK_CHANGE_URL () { - # Try the change_url script + # Try the change_url script - unit_test_title "Change URL..." + start_test "Change URL" - # Check if the needed manifest key are set or abort the test - check_manifest_key "domain" || return + # Check if the needed manifest key are set or abort the test + check_manifest_key "domain" || return - # Check if an install have previously work - is_install_failed || return + # Check if an install have previously work + is_install_failed || return - # Copy original arguments - local manifest_args_mod="$manifest_arguments" + # Copy original arguments + local manifest_args_mod="$manifest_arguments" - # Replace manifest key for the test - check_domain=$sub_domain - replace_manifest_key "domain" "$check_domain" - replace_manifest_key "user" "$test_user" - replace_manifest_key "public" "$public_public_arg" + # Replace manifest key for the test + check_domain=$sub_domain + replace_manifest_key "domain" "$check_domain" + replace_manifest_key "user" "$test_user" + replace_manifest_key "public" "$public_public_arg" - # Try in 6 times ! - # Without modify the domain, root to path, path to path and path to root. - # And then, same with a domain change - local i=0 - for i in `seq 1 7` - do - if [ $i -eq 1 ]; then - # Same domain, root to path - check_path=/ - local new_path=$test_path - local new_domain=$sub_domain - elif [ $i -eq 2 ]; then - # Same domain, path to path - check_path=$test_path - local new_path=${test_path}_2 - local new_domain=$sub_domain - elif [ $i -eq 3 ]; then - # Same domain, path to root - check_path=$test_path - local new_path=/ - local new_domain=$sub_domain + # Try in 6 times ! + # Without modify the domain, root to path, path to path and path to root. + # And then, same with a domain change + local i=0 + for i in `seq 1 7` + do + if [ $i -eq 1 ]; then + # Same domain, root to path + check_path=/ + local new_path=$test_path + local new_domain=$sub_domain + elif [ $i -eq 2 ]; then + # Same domain, path to path + check_path=$test_path + local new_path=${test_path}_2 + local new_domain=$sub_domain + elif [ $i -eq 3 ]; then + # Same domain, path to root + check_path=$test_path + local new_path=/ + local new_domain=$sub_domain - elif [ $i -eq 4 ]; then - # Other domain, root to path - check_path=/ - local new_path=$test_path - local new_domain=$main_domain - elif [ $i -eq 5 ]; then - # Other domain, path to path - check_path=$test_path - local new_path=${test_path}_2 - local new_domain=$main_domain - elif [ $i -eq 6 ]; then - # Other domain, path to root - check_path=$test_path - local new_path=/ - local new_domain=$main_domain - elif [ $i -eq 7 ]; then - # Other domain, root to root - check_path=/ - local new_path=/ - local new_domain=$main_domain - fi - replace_manifest_key "path" "$check_path" + elif [ $i -eq 4 ]; then + # Other domain, root to path + check_path=/ + local new_path=$test_path + local new_domain=$main_domain + elif [ $i -eq 5 ]; then + # Other domain, path to path + check_path=$test_path + local new_path=${test_path}_2 + local new_domain=$main_domain + elif [ $i -eq 6 ]; then + # Other domain, path to root + check_path=$test_path + local new_path=/ + local new_domain=$main_domain + elif [ $i -eq 7 ]; then + # Other domain, root to root + check_path=/ + local new_path=/ + local new_domain=$main_domain + fi + replace_manifest_key "path" "$check_path" # Ignore the test if it tries to move to the same address if [ "$check_path" == "$new_path" ] && [ "$new_domain" == "$sub_domain" ]; then continue fi - # Check if root or subpath installation worked, or if force_install_ok is setted. + # Check if root or subpath installation worked, or if force_install_ok is setted. # Try with a sub path install if [ "$check_path" = "/" ] then if [ $root_install -eq 0 ] then - # Jump this test - ECHO_FORMAT "Root install failed, impossible to perform this test...\n" "lyellow" clog + # Skip this test + warning "Root install failed, therefore this test cannot be performed..." continue elif [ "$new_path" != "/" ] && [ $sub_dir_install -eq 0 ] then - # Jump this test - ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "lyellow" clog + # Skip this test + warning "Sub path install failed, therefore this test cannot be performed..." continue fi # And with a sub path install else if [ $sub_dir_install -eq 0 ] then - # Jump this test - ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "lyellow" clog + # Skip this test + warning "Sub path install failed, therefore this test cannot be performed..." continue elif [ "$new_path" = "/" ] && [ $root_install -eq 0 ] then - # Jump this test - ECHO_FORMAT "Root install failed, impossible to perform this test...\n" "lyellow" clog + # Skip this test + warning "Root install failed, therefore this test cannot be performed..." continue fi fi - # Install the application in a LXC container - ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog - STANDARD_SETUP_APP - check_false_positive_error || return $? + # Install the application in a LXC container + small_title "Preliminary install..." + STANDARD_SETUP_APP - # Check if the install had work - if [ $yunohost_result -ne 0 ] - then - ECHO_FORMAT "Installation failed...\n" "red" "bold" - else - ECHO_FORMAT "Change the url from $sub_domain$check_path to $new_domain$new_path...\n" "white" "bold" clog + # Check if the install had work + if [ $yunohost_result -ne 0 ] + then + error "Installation failed..." + else + small_title "Change the url from $sub_domain$check_path to $new_domain$new_path..." - # Change the url - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app change-url $ynh_app_id -d \"$new_domain\" -p \"$new_path\"" + # Change the url + run_yunohost "app change-url $ynh_app_id -d '$new_domain' -p '$new_path'" - # yunohost_result gets the return code of the change-url script - yunohost_result=$? + # yunohost_result gets the return code of the change-url script + yunohost_result=$? - # Print the result of the change_url command - if [ $yunohost_result -eq 0 ]; then - ECHO_FORMAT "Change_url script successful. ($yunohost_result)\n" "white" clog - else - ECHO_FORMAT "Change_url script failed. ($yunohost_result)\n" "white" clog - fi + # Print the result of the change_url command + if [ $yunohost_result -eq 0 ]; then + debug "Change_url script successful" + else + error "Change_url script failed. ($yunohost_result)" + fi - # Check all the witness files, to verify if them still here - check_witness_files + # Try to access the app by its url + check_path=$new_path + check_domain=$new_domain + VALIDATE_THAT_APP_CAN_BE_ACCESSED + fi - # Analyse the log to extract "warning" and "error" lines - LOG_EXTRACTOR - check_false_positive_error || return $? + # Check the result and print SUCCESS or FAIL + if check_test_result + then # Success + # The global success for a change_url can't be a success if another change_url failed + if [ $RESULT_change_url -ne -1 ]; then + RESULT_change_url=1 # Change_url succeed + fi + else # Fail + RESULT_change_url=-1 # Change_url failed + fi - # Try to access the app by its url - check_path=$new_path - check_domain=$new_domain - CHECK_URL - fi + # Make a break if auto_remove is set + break_before_continue - # Check the result and print SUCCESS or FAIL - if check_test_result - then # Success - # The global success for a change_url can't be a success if another change_url failed - if [ $RESULT_change_url -ne -1 ]; then - RESULT_change_url=1 # Change_url succeed - fi - else # Fail - RESULT_change_url=-1 # Change_url failed - fi - - # Make a break if auto_remove is set - break_before_continue - - # Uses the default snapshot - current_snapshot=snap0 - # Stop and restore the LXC container - LXC_STOP >> $complete_log - done + # Uses the default snapshot + current_snapshot=snap0 + # Stop and restore the LXC container + LXC_STOP >> $complete_log + done } # Define a function to split a file in multiple parts. Used for actions and config-panel toml @@ -1538,23 +1471,23 @@ ACTIONS_CONFIG_PANEL () { test_type=$1 if [ "$test_type" == "actions" ] then - unit_test_title "Actions..." + start_test "Actions" toml_file="$package_path/actions.toml" if [ ! -e "$toml_file" ] then - ECHO_FORMAT "\nNo actions.toml found !\n" "red" "bold" + error "No actions.toml found !" return 1 fi elif [ "$test_type" == "config_panel" ] then - unit_test_title "Config-panel..." + start_test "Config-panel" toml_file="$package_path/config_panel.toml" if [ ! -e "$toml_file" ] then - ECHO_FORMAT "\nNo config_panel.toml found !\n" "red" "bold" + error "No config_panel.toml found !" return 1 fi fi @@ -1582,9 +1515,8 @@ ACTIONS_CONFIG_PANEL () { replace_manifest_key "path" "$check_path" # Install the application in a LXC container - ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog + small_title "Preliminary install..." STANDARD_SETUP_APP - check_false_positive_error || return $? validate_action_config_panel() { @@ -1595,18 +1527,11 @@ ACTIONS_CONFIG_PANEL () { # Print the result of the command if [ $yunohost_result -eq 0 ]; then - ECHO_FORMAT "$message succeed. ($yunohost_result)\n" "white" clog + debug "$message succeed." else - ECHO_FORMAT "$message failed. ($yunohost_result)\n" "white" clog + error "$message failed. ($yunohost_result)" fi - # Check all the witness files, to verify if they're still there - check_witness_files - - # Analyse the log to extract "warning" and "error" lines - LOG_EXTRACTOR - check_false_positive_error || return $? - # Check the result and print SUCCESS or FAIL if check_test_result then # Success @@ -1616,7 +1541,7 @@ ACTIONS_CONFIG_PANEL () { fi else # Fail RESULT_action_config_panel=-1 # Actions failed - fi + fi # Make a break if auto_remove is set break_before_continue @@ -1629,181 +1554,184 @@ ACTIONS_CONFIG_PANEL () { # Do a test if the installation succeed if [ $yunohost_result -ne 0 ] then - ECHO_FORMAT "\nThe previous test has failed...\n" "red" "bold" - else - if [ $i -eq 1 ] + error "The previous test has failed..." + continue + fi + + if [ $i -eq 1 ] + then + if [ "$test_type" == "actions" ] then - if [ "$test_type" == "actions" ] - then - ECHO_FORMAT "\n> List the available actions...\n" "white" "bold" clog + info "> List the available actions..." - # List the actions - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app action list $ynh_app_id" + # List the actions + run_yunohost "app action list $ynh_app_id" - validate_action_config_panel "yunohost app action list" - elif [ "$test_type" == "config_panel" ] - then - ECHO_FORMAT "\n> Show the config panel...\n" "white" "bold" clog - - # Show the config-panel - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app config show-panel $ynh_app_id" - validate_action_config_panel "yunohost app config show-panel" - fi - elif [ $i -eq 2 ] + validate_action_config_panel "yunohost app action list" + elif [ "$test_type" == "config_panel" ] then - local parts - if [ "$test_type" == "actions" ] - then - ECHO_FORMAT "\n> Execute the actions...\n" "white" "bold" clog + info "> Show the config panel..." - # Split the actions.toml file to separate each actions - splitterAA "^[[:blank:]]*\[[^.]*\]" "$toml_file" - elif [ "$test_type" == "config_panel" ] - then - ECHO_FORMAT "\n> Apply configurations...\n" "white" "bold" clog + # Show the config-panel + run_yunohost "app config show-panel $ynh_app_id" + validate_action_config_panel "yunohost app config show-panel" + fi + elif [ $i -eq 2 ] + then + local parts + if [ "$test_type" == "actions" ] + then + info "> Execute the actions..." - # Split the config_panel.toml file to separate each configurations - splitterAA "^[[:blank:]]*\[.*\]" "$toml_file" + # Split the actions.toml file to separate each actions + splitterAA "^[[:blank:]]*\[[^.]*\]" "$toml_file" + elif [ "$test_type" == "config_panel" ] + then + info "> Apply configurations..." + + # Split the config_panel.toml file to separate each configurations + splitterAA "^[[:blank:]]*\[.*\]" "$toml_file" + fi + + # Read each part, each action, one by one + for part in $(seq 0 $(( ${#parts[@]} -1 ))) + do + local action_config_argument_name="" + local action_config_argument_type="" + local action_config_argument_default="" + local actions_config_arguments_specifics="" + local nb_actions_config_arguments_specifics=1 + + # Ignore part of the config_panel which are only titles + if [ "$test_type" == "config_panel" ] + then + # A real config_panel part should have a `ask = ` line. Ignore the part if not. + if ! echo "${parts[$part]}" | grep --quiet --extended-regexp "^[[:blank:]]*ask =" + then + continue + fi + # Get the name of the config. ask = "Config ?" + local action_config_name="$(echo "${parts[$part]}" | grep "ask *= *" | sed 's/^.* = \"\(.*\)\"/\1/')" + + # Get the config argument name "YNH_CONFIG_part1_part2.part3.partx" + local action_config_argument_name="$(echo "${parts[$part]}" | grep "^[[:blank:]]*\[.*\]$")" + # Remove [] + action_config_argument_name="${action_config_argument_name//[\[\]]/}" + # And remove spaces + action_config_argument_name="${action_config_argument_name// /}" + + elif [ "$test_type" == "actions" ] + then + # Get the name of the action. name = "Name of the action" + local action_config_name="$(echo "${parts[$part]}" | grep "name" | sed 's/^.* = \"\(.*\)\"/\1/')" + + # Get the action. [action] + local action_config_action="$(echo "${parts[$part]}" | grep "^\[.*\]$" | sed 's/\[\(.*\)\]/\1/')" fi - # Read each part, each action, one by one - for part in $(seq 0 $(( ${#parts[@]} -1 ))) - do - local action_config_argument_name="" - local action_config_argument_type="" - local action_config_argument_default="" - local actions_config_arguments_specifics="" - local nb_actions_config_arguments_specifics=1 + # Check if there's any [action.arguments] + # config_panel always have arguments. + if echo "${parts[$part]}" | grep --quiet "$action_config_action\.arguments" || [ "$test_type" == "config_panel" ] + then local action_config_has_arguments=1 + else local action_config_has_arguments=0 + fi + + # If there's arguments for this action. + if [ $action_config_has_arguments -eq 1 ] + then + if [ "$test_type" == "actions" ] + then + # Get the argument [action.arguments.name_of_the_argument] + action_config_argument_name="$(echo "${parts[$part]}" | grep "$action_config_action\.arguments\." | sed 's/.*\.\(.*\)]/\1/')" + fi + + # Get the type of the argument. type = "type" + action_config_argument_type="$(echo "${parts[$part]}" | grep "type" | sed 's/^.* = \"\(.*\)\"/\1/')" + # Get the default value of this argument. default = true + action_config_argument_default="$(echo "${parts[$part]}" | grep "default" | sed 's/^.* = \(.*\)/\1/')" + # Do not use true or false, use 1/0 instead + if [ "$action_config_argument_default" == "true" ] && [ "$action_config_argument_type" == "boolean" ]; then + action_config_argument_default=1 + elif [ "$action_config_argument_default" == "false" ] && [ "$action_config_argument_type" == "boolean" ]; then + action_config_argument_default=0 + fi - # Ignore part of the config_panel which are only titles if [ "$test_type" == "config_panel" ] then - # A real config_panel part should have a `ask = ` line. Ignore the part if not. - if ! echo "${parts[$part]}" | grep --quiet --extended-regexp "^[[:blank:]]*ask =" - then - continue - fi - # Get the name of the config. ask = "Config ?" - local action_config_name="$(echo "${parts[$part]}" | grep "ask *= *" | sed 's/^.* = \"\(.*\)\"/\1/')" - - # Get the config argument name "YNH_CONFIG_part1_part2.part3.partx" - local action_config_argument_name="$(echo "${parts[$part]}" | grep "^[[:blank:]]*\[.*\]$")" - # Remove [] - action_config_argument_name="${action_config_argument_name//[\[\]]/}" - # And remove spaces - action_config_argument_name="${action_config_argument_name// /}" - + local check_process_arguments="$config_panel_arguments" elif [ "$test_type" == "actions" ] then - # Get the name of the action. name = "Name of the action" - local action_config_name="$(echo "${parts[$part]}" | grep "name" | sed 's/^.* = \"\(.*\)\"/\1/')" - - # Get the action. [action] - local action_config_action="$(echo "${parts[$part]}" | grep "^\[.*\]$" | sed 's/\[\(.*\)\]/\1/')" + local check_process_arguments="$actions_arguments" + fi + # Look for arguments into the check_process + if echo "$check_process_arguments" | grep --quiet "$action_config_argument_name" + then + # If there's arguments for this actions into the check_process + # Isolate the values + actions_config_arguments_specifics="$(echo "$check_process_arguments" | sed "s/.*$action_config_argument_name=\(.*\)/\1/")" + # And remove values of the following action + actions_config_arguments_specifics="${actions_config_arguments_specifics%%\:*}" + nb_actions_config_arguments_specifics=$(( $(echo "$actions_config_arguments_specifics" | tr --complement --delete "|" | wc --chars) + 1 )) fi - # Check if there's any [action.arguments] - # config_panel always have arguments. - if echo "${parts[$part]}" | grep --quiet "$action_config_action\.arguments" || [ "$test_type" == "config_panel" ] - then local action_config_has_arguments=1 - else local action_config_has_arguments=0 + if [ "$test_type" == "config_panel" ] + then + # Finish to format the name + # Remove . by _ + action_config_argument_name="${action_config_argument_name//./_}" + # Move all characters to uppercase + action_config_argument_name="${action_config_argument_name^^}" + # Add YNH_CONFIG_ + action_config_argument_name="YNH_CONFIG_$action_config_argument_name" fi - # If there's arguments for this action. + fi + + # Loop on the number of values into the check_process. + # Or loop once for the default value + for j in `seq 1 $nb_actions_config_arguments_specifics` + do + local action_config_argument_built="" if [ $action_config_has_arguments -eq 1 ] then - if [ "$test_type" == "actions" ] + # If there's values into the check_process + if [ -n "$actions_config_arguments_specifics" ] then - # Get the argument [action.arguments.name_of_the_argument] - action_config_argument_name="$(echo "${parts[$part]}" | grep "$action_config_action\.arguments\." | sed 's/.*\.\(.*\)]/\1/')" - fi - - # Get the type of the argument. type = "type" - action_config_argument_type="$(echo "${parts[$part]}" | grep "type" | sed 's/^.* = \"\(.*\)\"/\1/')" - # Get the default value of this argument. default = true - action_config_argument_default="$(echo "${parts[$part]}" | grep "default" | sed 's/^.* = \(.*\)/\1/')" - # Do not use true or false, use 1/0 instead - if [ "$action_config_argument_default" == "true" ] && [ "$action_config_argument_type" == "boolean" ]; then - action_config_argument_default=1 - elif [ "$action_config_argument_default" == "false" ] && [ "$action_config_argument_type" == "boolean" ]; then - action_config_argument_default=0 + # Build the argument from a value from the check_process + local action_config_actual_argument="$(echo "$actions_config_arguments_specifics" | cut -d'|' -f $j)" + action_config_argument_built="--args $action_config_argument_name=\"$action_config_actual_argument\"" + elif [ -n "$action_config_argument_default" ] + then + # Build the argument from the default value + local action_config_actual_argument="$action_config_argument_default" + action_config_argument_built="--args $action_config_argument_name=\"$action_config_actual_argument\"" + else + warning "> No argument into the check_process to use or default argument for \"$action_config_name\"..." + action_config_actual_argument="" fi if [ "$test_type" == "config_panel" ] then - local check_process_arguments="$config_panel_arguments" + info "> Apply the configuration for \"$action_config_name\" with the argument \"$action_config_actual_argument\"..." elif [ "$test_type" == "actions" ] then - local check_process_arguments="$actions_arguments" - fi - # Look for arguments into the check_process - if echo "$check_process_arguments" | grep --quiet "$action_config_argument_name" - then - # If there's arguments for this actions into the check_process - # Isolate the values - actions_config_arguments_specifics="$(echo "$check_process_arguments" | sed "s/.*$action_config_argument_name=\(.*\)/\1/")" - # And remove values of the following action - actions_config_arguments_specifics="${actions_config_arguments_specifics%%\:*}" - nb_actions_config_arguments_specifics=$(( $(echo "$actions_config_arguments_specifics" | tr --complement --delete "|" | wc --chars) + 1 )) - fi - - if [ "$test_type" == "config_panel" ] - then - # Finish to format the name - # Remove . by _ - action_config_argument_name="${action_config_argument_name//./_}" - # Move all characters to uppercase - action_config_argument_name="${action_config_argument_name^^}" - # Add YNH_CONFIG_ - action_config_argument_name="YNH_CONFIG_$action_config_argument_name" + info "> Execute the action \"$action_config_name\" with the argument \"$action_config_actual_argument\"..." fi + else + info "> Execute the action \"$action_config_name\"..." fi - # Loop on the number of values into the check_process. - # Or loop once for the default value - for j in `seq 1 $nb_actions_config_arguments_specifics` - do - local action_config_argument_built="" - if [ $action_config_has_arguments -eq 1 ] - then - # If there's values into the check_process - if [ -n "$actions_config_arguments_specifics" ] - then - # Build the argument from a value from the check_process - local action_config_actual_argument="$(echo "$actions_config_arguments_specifics" | cut -d'|' -f $j)" - action_config_argument_built="--args $action_config_argument_name=\"$action_config_actual_argument\"" - elif [ -n "$action_config_argument_default" ] - then - # Build the argument from the default value - local action_config_actual_argument="$action_config_argument_default" - action_config_argument_built="--args $action_config_argument_name=\"$action_config_actual_argument\"" - else - ECHO_FORMAT "\n> No argument into the check_process to use or default argument for \"$action_config_name\"..." "lyellow" "bold" clog - action_config_actual_argument="" - fi - if [ "$test_type" == "config_panel" ] - then - ECHO_FORMAT "\n> Apply the configuration for \"$action_config_name\" with the argument \"$action_config_actual_argument\"...\n" "white" "bold" clog - elif [ "$test_type" == "actions" ] - then - ECHO_FORMAT "\n> Execute the action \"$action_config_name\" with the argument \"$action_config_actual_argument\"...\n" "white" "bold" clog - fi - else - ECHO_FORMAT "\n> Execute the action \"$action_config_name\"...\n" "white" "bold" clog - fi - - if [ "$test_type" == "config_panel" ] - then - # Aply a configuration - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app config apply $ynh_app_id $action_config_action $action_config_argument_built" - elif [ "$test_type" == "actions" ] - then - # Execute an action - LXC_START "sudo PACKAGE_CHECK_EXEC=1 yunohost --debug app action run $ynh_app_id $action_config_action $action_config_argument_built" - fi - validate_action_config_panel "yunohost action $action_config_action" - done + if [ "$test_type" == "config_panel" ] + then + # Aply a configuration + run_yunohost "app config apply $ynh_app_id $action_config_action $action_config_argument_built" + elif [ "$test_type" == "actions" ] + then + # Execute an action + run_yunohost "app action run $ynh_app_id $action_config_action $action_config_argument_built" + fi + validate_action_config_panel "yunohost action $action_config_action" done - fi + done fi done @@ -1814,70 +1742,70 @@ ACTIONS_CONFIG_PANEL () { } PACKAGE_LINTER () { - # Package linter + # Package linter - unit_test_title "Package linter..." + start_test "Package linter" - # Execute package linter and linter_result gets the return code of the package linter - "$script_dir/package_linter/package_linter.py" "$package_path" > "$script_dir/temp_linter_result.log" - "$script_dir/package_linter/package_linter.py" "$package_path" --json > "$script_dir/temp_linter_result.json" + # Execute package linter and linter_result gets the return code of the package linter + "$script_dir/package_linter/package_linter.py" "$package_path" > "$script_dir/temp_linter_result.log" + "$script_dir/package_linter/package_linter.py" "$package_path" --json > "$script_dir/temp_linter_result.json" - # Print the results of package linter and copy these result in the complete log - cat "$script_dir/temp_linter_result.log" | tee --append "$complete_log" - cat "$script_dir/temp_linter_result.json" >> "$complete_log" + # Print the results of package linter and copy these result in the complete log + cat "$script_dir/temp_linter_result.log" | tee --append "$complete_log" + cat "$script_dir/temp_linter_result.json" >> "$complete_log" - RESULT_linter_level_6=0 - RESULT_linter_level_7=0 - RESULT_linter_level_8=0 + RESULT_linter_level_6=0 + RESULT_linter_level_7=0 + RESULT_linter_level_8=0 - # Check we qualify for level 6, 7, 8 + # Check we qualify for level 6, 7, 8 # Linter will have a warning called "app_in_github_org" if app ain't in the # yunohost-apps org... - if ! cat "$script_dir/temp_linter_result.json" | jq ".warning" | grep -q "app_in_github_org" - then - RESULT_linter_level_6=1 + if ! cat "$script_dir/temp_linter_result.json" | jq ".warning" | grep -q "app_in_github_org" + then + RESULT_linter_level_6=1 fi - if cat "$script_dir/temp_linter_result.json" | jq ".success" | grep -q "qualify_for_level_7" - then - RESULT_linter_level_7=1 + if cat "$script_dir/temp_linter_result.json" | jq ".success" | grep -q "qualify_for_level_7" + then + RESULT_linter_level_7=1 fi - if cat "$script_dir/temp_linter_result.json" | jq ".success" | grep -q "qualify_for_level_8" - then - RESULT_linter_level_8=1 + if cat "$script_dir/temp_linter_result.json" | jq ".success" | grep -q "qualify_for_level_8" + then + RESULT_linter_level_8=1 fi # If there are any critical errors, we'll force level 0 if [[ -n "$(cat "$script_dir/temp_linter_result.json" | jq ".critical" | grep -v '\[\]')" ]] then - check_failed + report_test_failed RESULT_linter=-2 # If there are any regular errors, we'll cap to 4 elif [[ -n "$(cat "$script_dir/temp_linter_result.json" | jq ".error" | grep -v '\[\]')" ]] - then # FAil - check_failed + then + report_test_failed RESULT_linter=-1 - # Otherwise, test pass (we'll display a warning depending on if there are - # any remaning warnings or not) + # Otherwise, test pass (we'll display a warning depending on if there are + # any remaning warnings or not) else if [[ -n "$(cat "$script_dir/temp_linter_result.json" | jq ".warning" | grep -v '\[\]')" ]] - then - check_warning + then + report_test_warning RESULT_linter=1 else - check_success + report_test_success RESULT_linter=2 fi fi } TEST_LAUNCHER () { - # Abstract for test execution. - # $1 = Name of the function to execute - # $2 = Argument for the function + # Abstract for test execution. + # $1 = Name of the function to execute + # $2 = Argument for the function - # Intialize values - yunohost_result=-1 - yunohost_remove=-1 + # Intialize values + yunohost_result=-1 + yunohost_remove=-1 false_positive_error=0 max_false_positive_error_loop=3 @@ -1893,10 +1821,10 @@ TEST_LAUNCHER () { if [ $false_positive_error -eq 1 ] then - ECHO_FORMAT "This test was aborted because of a $false_positive_error_cond error.\n" "red" "bold" clog + error "This test was aborted because of a $false_positive_error_cond error." if [ $false_positive_error_loop -lt $max_false_positive_error_loop ] then - ECHO_FORMAT "The test will restart.\n" "lyellow" "bold" clog + warning "The test will restart." cur_test=$((cur_test-1)) fi fi @@ -1925,199 +1853,174 @@ TEST_LAUNCHER () { } set_witness_files () { - # Create files to check if the remove script does not remove them accidentally - echo "Create witness files..." >> "$test_result" + # Create files to check if the remove script does not remove them accidentally + echo "Create witness files..." >> "$complete_log" - lxc_dir="/var/lib/lxc/$lxc_name/rootfs" + lxc_dir="/var/lib/lxc/$lxc_name/rootfs" - create_witness_file () { - [ "$2" = "file" ] && local action="touch" || local action="mkdir -p" - sudo $action "${lxc_dir}${1}" - } + create_witness_file () { + [ "$2" = "file" ] && local action="touch" || local action="mkdir -p" + sudo $action "${lxc_dir}${1}" + } - # Nginx conf - create_witness_file "/etc/nginx/conf.d/$main_domain.d/witnessfile.conf" file - create_witness_file "/etc/nginx/conf.d/$sub_domain.d/witnessfile.conf" file + # Nginx conf + create_witness_file "/etc/nginx/conf.d/$main_domain.d/witnessfile.conf" file + create_witness_file "/etc/nginx/conf.d/$sub_domain.d/witnessfile.conf" file - # /etc - create_witness_file "/etc/witnessfile" file + # /etc + create_witness_file "/etc/witnessfile" file - # /opt directory - create_witness_file "/opt/witnessdir" directory + # /opt directory + create_witness_file "/opt/witnessdir" directory - # /var/www directory - create_witness_file "/var/www/witnessdir" directory + # /var/www directory + create_witness_file "/var/www/witnessdir" directory - # /home/yunohost.app/ - create_witness_file "/home/yunohost.app/witnessdir" directory + # /home/yunohost.app/ + create_witness_file "/home/yunohost.app/witnessdir" directory - # /var/log - create_witness_file "/var/log/witnessfile" file + # /var/log + create_witness_file "/var/log/witnessfile" file - # Config fpm - if [ -d "${lxc_dir}/etc/php5/fpm" ]; then - create_witness_file "/etc/php5/fpm/pool.d/witnessfile.conf" file - fi - if [ -d "${lxc_dir}/etc/php/7.0/fpm" ]; then - create_witness_file "/etc/php/7.0/fpm/pool.d/witnessfile.conf" file - fi + # Config fpm + if [ -d "${lxc_dir}/etc/php5/fpm" ]; then + create_witness_file "/etc/php5/fpm/pool.d/witnessfile.conf" file + fi + if [ -d "${lxc_dir}/etc/php/7.0/fpm" ]; then + create_witness_file "/etc/php/7.0/fpm/pool.d/witnessfile.conf" file + fi if [ -d "${lxc_dir}/etc/php/7.3/fpm" ]; then create_witness_file "/etc/php/7.3/fpm/pool.d/witnessfile.conf" file fi - # Config logrotate - create_witness_file "/etc/logrotate.d/witnessfile" file + # Config logrotate + create_witness_file "/etc/logrotate.d/witnessfile" file - # Config systemd - create_witness_file "/etc/systemd/system/witnessfile.service" file + # Config systemd + create_witness_file "/etc/systemd/system/witnessfile.service" file - # Database - sudo lxc-attach --name=$lxc_name -- mysqladmin --user=root --password=$(sudo cat "$lxc_dir/etc/yunohost/mysql") --wait status > /dev/null 2>&1 - sudo lxc-attach --name=$lxc_name -- mysql --user=root --password=$(sudo cat "$lxc_dir/etc/yunohost/mysql") --wait --execute="CREATE DATABASE witnessdb" > /dev/null 2>&1 + # Database + sudo lxc-attach --name=$lxc_name -- mysqladmin --user=root --password=$(sudo cat "$lxc_dir/etc/yunohost/mysql") --wait status > /dev/null 2>&1 + sudo lxc-attach --name=$lxc_name -- mysql --user=root --password=$(sudo cat "$lxc_dir/etc/yunohost/mysql") --wait --execute="CREATE DATABASE witnessdb" > /dev/null 2>&1 } check_witness_files () { - # Check all the witness files, to verify if them still here + # Check all the witness files, to verify if them still here - lxc_dir="/var/lib/lxc/$lxc_name/rootfs" + lxc_dir="/var/lib/lxc/$lxc_name/rootfs" - check_file_exist () { - if sudo test ! -e "${lxc_dir}${1}" - then - ECHO_FORMAT "The file $1 is missing ! Something gone wrong !\n" "red" "bold" - RESULT_witness=1 - fi - } + check_file_exist () { + if sudo test ! -e "${lxc_dir}${1}" + then + error "The file $1 is missing ! Something gone wrong !" + RESULT_witness=1 + fi + } - # Nginx conf - check_file_exist "/etc/nginx/conf.d/$main_domain.d/witnessfile.conf" - check_file_exist "/etc/nginx/conf.d/$sub_domain.d/witnessfile.conf" + # Nginx conf + check_file_exist "/etc/nginx/conf.d/$main_domain.d/witnessfile.conf" + check_file_exist "/etc/nginx/conf.d/$sub_domain.d/witnessfile.conf" - # /etc - check_file_exist "/etc/witnessfile" + # /etc + check_file_exist "/etc/witnessfile" - # /opt directory - check_file_exist "/opt/witnessdir" + # /opt directory + check_file_exist "/opt/witnessdir" - # /var/www directory - check_file_exist "/var/www/witnessdir" + # /var/www directory + check_file_exist "/var/www/witnessdir" - # /home/yunohost.app/ - check_file_exist "/home/yunohost.app/witnessdir" + # /home/yunohost.app/ + check_file_exist "/home/yunohost.app/witnessdir" - # /var/log - check_file_exist "/var/log/witnessfile" + # /var/log + check_file_exist "/var/log/witnessfile" - # Config fpm - if [ -d "${lxc_dir}/etc/php5/fpm" ]; then - check_file_exist "/etc/php5/fpm/pool.d/witnessfile.conf" file - fi - if [ -d "${lxc_dir}/etc/php/7.0/fpm" ]; then - check_file_exist "/etc/php/7.0/fpm/pool.d/witnessfile.conf" file - fi + # Config fpm + if [ -d "${lxc_dir}/etc/php5/fpm" ]; then + check_file_exist "/etc/php5/fpm/pool.d/witnessfile.conf" file + fi + if [ -d "${lxc_dir}/etc/php/7.0/fpm" ]; then + check_file_exist "/etc/php/7.0/fpm/pool.d/witnessfile.conf" file + fi if [ -d "${lxc_dir}/etc/php/7.3/fpm" ]; then check_file_exist "/etc/php/7.3/fpm/pool.d/witnessfile.conf" file fi - # Config logrotate - check_file_exist "/etc/logrotate.d/witnessfile" + # Config logrotate + check_file_exist "/etc/logrotate.d/witnessfile" - # Config systemd - check_file_exist "/etc/systemd/system/witnessfile.service" + # Config systemd + check_file_exist "/etc/systemd/system/witnessfile.service" - # Database - if ! sudo lxc-attach --name=$lxc_name -- mysqlshow --user=root --password=$(sudo cat "$lxc_dir/etc/yunohost/mysql") | grep --quiet '^| witnessdb' > /dev/null 2>&1 - then - ECHO_FORMAT "The database witnessdb is missing ! Something gone wrong !\n" "red" "bold" - RESULT_witness=1 - fi - if [ $RESULT_witness -eq 1 ] - then - yunohost_result=1 - yunohost_remove=1 - fi + # Database + if ! sudo lxc-attach --name=$lxc_name -- mysqlshow --user=root --password=$(sudo cat "$lxc_dir/etc/yunohost/mysql") | grep --quiet '^| witnessdb' > /dev/null 2>&1 + then + error "The database witnessdb is missing ! Something gone wrong !" + RESULT_witness=1 + fi + if [ $RESULT_witness -eq 1 ] + then + yunohost_result=1 + yunohost_remove=1 + fi } TESTING_PROCESS () { - # Launch all tests successively + # Launch all tests successively - ECHO_FORMAT "\nTests serie: ${tests_serie#;; }\n\n" "white" "underlined" clog + title "Tests serie: ${tests_serie#;; }" - PRINT_YUNOHOST_VERSION + # Be sure that the container is running + LXC_START "true" - # Init the value for the current test - cur_test=1 + PRINT_YUNOHOST_VERSION - # By default, all tests will try to access the app with curl - use_curl=1 + # Init the value for the current test + cur_test=1 - # Check the package with package linter - if [ $pkg_linter -eq 1 ]; then - PACKAGE_LINTER - fi + # By default, all tests will try to access the app with curl + use_curl=1 - # Try to install in a sub path - if [ $setup_sub_dir -eq 1 ]; then - TEST_LAUNCHER CHECK_SETUP subdir - fi + # Check the package with package linter + [ $pkg_linter -eq 1 ] && PACKAGE_LINTER - # Try to install on root - if [ $setup_root -eq 1 ]; then - TEST_LAUNCHER CHECK_SETUP root - fi + # Try to install in a sub path + [ $setup_sub_dir -eq 1 ] && TEST_LAUNCHER CHECK_SETUP subdir - # Try to install without url access - if [ $setup_nourl -eq 1 ]; then - TEST_LAUNCHER CHECK_SETUP no_url - fi + # Try to install on root + [ $setup_root -eq 1 ] && TEST_LAUNCHER CHECK_SETUP root - # Try the upgrade script - if [ $upgrade -eq 1 ]; then - TEST_LAUNCHER CHECK_UPGRADE - fi + # Try to install without url access + [ $setup_nourl -eq 1 ] && TEST_LAUNCHER CHECK_SETUP no_url - # Try to install in private mode - if [ $setup_private -eq 1 ]; then - TEST_LAUNCHER CHECK_PUBLIC_PRIVATE private - fi + # Try the upgrade script + [ $upgrade -eq 1 ] && TEST_LAUNCHER CHECK_UPGRADE - # Try to install in public mode - if [ $setup_public -eq 1 ]; then - TEST_LAUNCHER CHECK_PUBLIC_PRIVATE public - fi + # Try to install in private mode + [ $setup_private -eq 1 ] && TEST_LAUNCHER CHECK_PUBLIC_PRIVATE private - # Try multi-instance installations - if [ $multi_instance -eq 1 ]; then - TEST_LAUNCHER CHECK_MULTI_INSTANCE - fi + # Try to install in public mode + [ $setup_public -eq 1 ] && TEST_LAUNCHER CHECK_PUBLIC_PRIVATE public - # Try to install with an malformed path - if [ $incorrect_path -eq 1 ]; then - TEST_LAUNCHER CHECK_COMMON_ERROR incorrect_path - fi + # Try multi-instance installations + [ $multi_instance -eq 1 ] && TEST_LAUNCHER CHECK_MULTI_INSTANCE - # Try to install with a port already used - if [ $port_already_use -eq 1 ]; then - TEST_LAUNCHER CHECK_COMMON_ERROR port_already_use - fi + # Try to install with an malformed path + [ $incorrect_path -eq 1 ] && TEST_LAUNCHER CHECK_COMMON_ERROR incorrect_path - # Try to backup then restore the app - if [ $backup_restore -eq 1 ]; then - TEST_LAUNCHER CHECK_BACKUP_RESTORE - fi + # Try to install with a port already used + [ $port_already_use -eq 1 ] && TEST_LAUNCHER CHECK_COMMON_ERROR port_already_use - # Try the change_url script - if [ $change_url -eq 1 ]; then - TEST_LAUNCHER CHECK_CHANGE_URL - fi + # Try to backup then restore the app + [ $backup_restore -eq 1 ] && TEST_LAUNCHER CHECK_BACKUP_RESTORE - # Try the actions - if [ $actions -eq 1 ]; then - TEST_LAUNCHER ACTIONS_CONFIG_PANEL actions - fi + # Try the change_url script + [ $change_url -eq 1 ] && TEST_LAUNCHER CHECK_CHANGE_URL - # Try the config-panel - if [ $config_panel -eq 1 ]; then - TEST_LAUNCHER ACTIONS_CONFIG_PANEL config_panel - fi + # Try the actions + [ $actions -eq 1 ] && TEST_LAUNCHER ACTIONS_CONFIG_PANEL actions + + # Try the config-panel + [ $config_panel -eq 1 ] && TEST_LAUNCHER ACTIONS_CONFIG_PANEL config_panel }