From ba86a4fc01df5be36cabbb3a73d179aef6ecda6c Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 30 Mar 2017 16:28:27 +0200 Subject: [PATCH 01/10] Print LXC start Just somes echo to inform when LXC starting And a comment because Moul will hang me if I not do that ! --- sub_scripts/lxc_launcher.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sub_scripts/lxc_launcher.sh b/sub_scripts/lxc_launcher.sh index 21c5ea1..b9c0445 100755 --- a/sub_scripts/lxc_launcher.sh +++ b/sub_scripts/lxc_launcher.sh @@ -35,7 +35,10 @@ LXC_START () { # 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 "Start the LXC container" | tee --append "$test_result" sudo lxc-start --name=$LXC_NAME --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$test_result" 2>&1 + else + echo "An LXC container is already running" | tee --append "$test_result" fi # Check during 20 seconds if the container has finished to start. From 0b2bf64902e0f3218fc427b3985b9c4d40798710 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 30 Mar 2017 19:02:02 +0200 Subject: [PATCH 02/10] [ref] Check and read CLI arguments Refactoring of the block which read and parse the arguments --- package_check.sh | 173 ++++++++++++++++++++++++--------- sub_scripts/log_extractor.sh | 6 -- sub_scripts/lxc_launcher.sh | 9 +- sub_scripts/testing_process.sh | 8 +- 4 files changed, 138 insertions(+), 58 deletions(-) diff --git a/package_check.sh b/package_check.sh index d690e92..b46751d 100755 --- a/package_check.sh +++ b/package_check.sh @@ -1,65 +1,144 @@ #!/bin/bash -# Arguments du script -# --bash-mode Mode bash, le script est autonome. Il ignore la valeur de $auto_remove -# --build-lxc Installe lxc et créer la machine si nécessaire. -# --branch=nom-de-la-branche Teste une branche du dépôt, plutôt que tester master -# --force-install-ok Force la réussite des installations, même si elles échouent. Permet d'effectuer les tests qui suivent même si l'installation a échouée. -# --interrupt Force l'option auto_remove à 0. -# --no-lxc N'utilise pas la virtualisation en conteneur lxc. La virtualisation est utilisée par défaut si disponible. -# --help Affiche l'aide du script +#================================================= +# Grab the script directory +#================================================= + +if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(echo $PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi + +#================================================= +# Check and read CLI arguments +#================================================= echo "" +# Init arguments value +gitbranch=0 +force_install_ok=0 +interrupt=0 notice=0 +build_lxc=0 +bash_mode=0 + +# If no arguments provided if [ "$#" -eq 0 ] then - echo "Le script prend en argument le package à tester." + # Print the help and exit + notice=1 +else + # Reduce the arguments for getopts + arguments="$*" + arguments=${arguments//--branch=/-b } + arguments=${arguments//--force-install-ok/-f} + arguments=${arguments//--interrupt/-i} + arguments=${arguments//--help/-h} + arguments=${arguments//--build-lxc/-l} + arguments=${arguments//--bash-mode/-y} + + # Read and parse all the arguments + while [ $# -ne 0 ] + do + # Initialize getopts' index + OPTIND=1 + # Parse with getopts only if the argument begin by - + if [ ${1:0:1} = "-" ] + then + getopts ":b:fihly " parameter + case $parameter in + b) + # --branch=branch-name + gitbranch="$OPTARG" + ;; + f) + # --force-install-ok + force_install_ok=1 + ;; + i) + # --interrupt + interrupt=1 + ;; + h) + # --help + notice=1 + ;; + l) + # --build-lxc + build_lxc=1 + ;; + y) + # --bash-mode + bash_mode=1 + ;; + \?) + echo "Invalid argument: -$OPTARG" >&2 + notice=1 + ;; + :) + echo "-$OPTARG parameter requires an argument." >&2 + notice=1 + ;; + esac + else + other_args="$other_args $1" + fi + shift + done +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 fi -## Récupère les arguments -# --bash-mode -bash_mode=$(echo "$*" | grep -c -e "--bash-mode") # bash_mode vaut 1 si l'argument est présent. -# --no-lxc -no_lxc=$(echo "$*" | grep -c -e "--no-lxc") # no_lxc vaut 1 si l'argument est présent. -# --build-lxc -build_lxc=$(echo "$*" | grep -c -e "--build-lxc") # build_lxc vaut 1 si l'argument est présent. -# --force-install-ok -force_install_ok=$(echo "$*" | grep -c -e "--force-install-ok") # force-install-ok vaut 1 si l'argument est présent. -# --branch= -gitbranch=$(echo "$*" | grep -e "--branch") # gitbranch prend l'ensemble des arguments à partir de --branch -# --interrupt -interrupt=$(echo "$*" | grep -c -e "--interrupt") # interrupt vaut 1 si l'argument est présent. -if test -n "$gitbranch"; then - if ! echo "$gitbranch" | grep -q "branch=[[:alnum:]]"; then - notice=1 # Renvoi vers l'aide si la syntaxe est incorrecte - else - gitbranch="--branch $(echo "$gitbranch" | cut -d'=' -f2 | cut -d' ' -f1)" # Isole le nom de la branche entre le = et l'espace. Et ajoute l'argument de git clone - fi -fi -# --help -if [ "$notice" -eq 0 ]; then - notice=$(echo "$*" | grep -c -e "--help") # notice vaut 1 si l'argument est présent. Il affichera alors l'aide. -fi -arg_app=$(echo "$*" | sed 's/--bash-mode\|--no-lxc\|--build-lxc\|--force-install-ok\|--interrupt\|--branch=[[:alnum:]-]*//g' | sed 's/^ *\| *$//g') # Supprime les arguments déjà lu pour ne garder que l'app. Et supprime les espaces au début et à la fin -# echo "arg_app=$arg_app." +# Print help +if [ $notice -eq 1 ] +then + cat << EOF -if [ "$notice" -eq 1 ]; then - echo -e "\nUsage:" - echo "package_check.sh [--bash-mode] [--branch=] [--build-lxc] [--force-install-ok] [--no-lxc] [--help] \"package to check\"" - echo -e "\n\t--bash-mode\t\tDo not ask for continue check. Ignore auto_remove." - echo -e "\t--branch=branch-name\tSpecify a branch to check." - echo -e "\t--build-lxc\t\tInstall LXC and build the container if necessary." - echo -e "\t--force-install-ok\tForce following test even if all install are failed." - echo -e "\t--interrupt\tForce auto_remove value, break before each remove." - echo -e "\t--no-lxc\t\tDo not use a LXC container. You should use this option only on a test environnement." - echo -e "\t--help\t\t\tDisplay this notice." +Usage: +package_check.sh [OPTION]... PACKAGE_TO_CHECK + -b, --branch=BRANCH + Specify a branch to check. + -f, --force-install-ok + Force following test even if all install have failed. + -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. +EOF exit 0 fi -# Récupère le dossier du script -if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(echo $PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi + + + + + +#================================================= +# Globals variables +#================================================= + +complete_log="$script_dir/Complete.log" +temp_log="$script_dir/temp_yunohost-cli.log" +temp_result="$script_dir/temp_result.log" +test_result="$script_dir/Test_results.log" +yunohost_log="/var/lib/lxc/\$LXC_NAME/rootfs/var/log/yunohost/yunohost-cli.log" + + + + + + + + + + # Détermine l'environnement d'exécution de Package check type_exec_env=0 # Par défaut, exécution de package check seul diff --git a/sub_scripts/log_extractor.sh b/sub_scripts/log_extractor.sh index 096ee48..1cfd244 100755 --- a/sub_scripts/log_extractor.sh +++ b/sub_scripts/log_extractor.sh @@ -1,11 +1,5 @@ #!/bin/bash -temp_log="$script_dir/temp_yunohost-cli.log" -# yunohost_log="/var/lib/lxc/$LXC_NAME/rootfs/var/log/yunohost/yunohost-cli.log" -yunohost_log="/var/lib/lxc/pchecker_lxc/rootfs/var/log/yunohost/yunohost-cli.log" -complete_log="$script_dir/Complete.log" -temp_result="$script_dir/temp_result.log" - echo "Load functions from log_extractor.sh" ECHO_FORMAT () { diff --git a/sub_scripts/lxc_launcher.sh b/sub_scripts/lxc_launcher.sh index b9c0445..6a2b52a 100755 --- a/sub_scripts/lxc_launcher.sh +++ b/sub_scripts/lxc_launcher.sh @@ -1,9 +1,14 @@ #!/bin/bash -# arg_ssh="-t" +echo -e "Load functions from lxc_launcher.sh" + +#================================================= +# Globals variables +#================================================= + arg_ssh="-tt" -echo -e "Load functions from lxc_launcher.sh" +#================================================= is_lxc_running () { sudo lxc-info --name=$LXC_NAME | grep --quiet "RUNNING" diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index 56227ca..8f00d9f 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -1,14 +1,16 @@ #!/bin/bash -test_result="$script_dir/Test_results.log" -backup_hooks="conf_ssowat data_home conf_ynh_firewall conf_cron" # La liste des hooks disponible pour le backup se trouve dans /usr/share/yunohost/hooks/backup/ - echo -e "Load functions from testing_process.sh" #================================================= # Globals variables #================================================= +# A complete list of backup hooks is available at /usr/share/yunohost/hooks/backup/ +backup_hooks="conf_ssowat data_home conf_ynh_firewall conf_cron" + +#================================================= + break_before_continue () { # Make a break if auto_remove is set From 4938c348d3bf92779c7190fcddcdf2564ce791b7 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 30 Mar 2017 19:40:45 +0200 Subject: [PATCH 03/10] [ref] Upgrade package check and linter Refactoring upgrade block for package check and package linter --- package_check.sh | 124 +++++++++++++++++++++++++++++++---------------- 1 file changed, 83 insertions(+), 41 deletions(-) diff --git a/package_check.sh b/package_check.sh index b46751d..964ce6c 100755 --- a/package_check.sh +++ b/package_check.sh @@ -115,8 +115,82 @@ EOF exit 0 fi +#================================================= +# Upgrade Package check +#================================================= +git_repository=https://github.com/YunoHost/package_check +version_file="$script_dir/pcheck_version" +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" + + # Build the upgrade script + cat > "$script_dir/upgrade_script.sh" << EOF + +#!/bin/bash +# Clone in another directory +git clone --quiet $git_repository "$script_dir/upgrade" +sudo cp -a "$script_dir/upgrade/." "$script_dir/." +sudo rm -r "$script_dir/upgrade" +# Update the version file +echo "$check_version" > "$version_file" +sudo rm "$script_dir/pcheck.lock" +# Execute package check by replacement of this process +exec "$script_dir/package_check.sh" "$arguments" +EOF + + # Give the execution right + chmod +x "$script_dir/upgrade_script.sh" + + # Start the upgrade script by replacement of this process + exec "$script_dir/upgrade_script.sh" + fi +fi + +# Update the version file +echo "$check_version" > "$version_file" + +#================================================= +# Upgrade Package linter +#================================================= + +git_repository=https://github.com/YunoHost/package_linter +version_file="$script_dir/plinter_version" + +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" + + # Clone in another directory + git clone --quiet https://github.com/YunoHost/package_linter "$script_dir/package_linter_tmp" + + # And replace + sudo 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" +fi + +# Update the version file +echo "$check_version" > "$version_file" @@ -130,6 +204,15 @@ temp_result="$script_dir/temp_result.log" test_result="$script_dir/Test_results.log" yunohost_log="/var/lib/lxc/\$LXC_NAME/rootfs/var/log/yunohost/yunohost-cli.log" +#================================================= +# Load all functions +#================================================= + +source "$script_dir/sub_scripts/lxc_launcher.sh" +source "$script_dir/sub_scripts/testing_process.sh" +source "$script_dir/sub_scripts/log_extractor.sh" +source /usr/share/yunohost/helpers + @@ -156,11 +239,6 @@ if [ "$(whoami)" != "$(cat "$script_dir/sub_scripts/setup_user")" ] && test -e " exit 0 fi -source "$script_dir/sub_scripts/lxc_launcher.sh" -source "$script_dir/sub_scripts/testing_process.sh" -source "$script_dir/sub_scripts/log_extractor.sh" -source /usr/share/yunohost/helpers - # Vérifie la connexion internet. ping -q -c 2 yunohost.org > /dev/null 2>&1 if [ "$?" -ne 0 ]; then # En cas d'échec de connexion, tente de pinger un autre domaine pour être sûr @@ -187,42 +265,6 @@ then # Présence du lock, Package check ne peut pas continuer. fi touch "$script_dir/pcheck.lock" # Met en place le lock de Package check -version_script="$(git ls-remote https://github.com/YunoHost/package_check | cut -f 1 | head -n1)" -if [ -e "$script_dir/package_version" ] -then - if [ "$version_script" != "$(cat "$script_dir/package_version")" ]; then # Si le dernier commit sur github ne correspond pas au commit enregistré, il y a une mise à jour. - # Écrit le script de mise à jour, qui sera exécuté à la place de ce script, pour le remplacer et le relancer après. - ECHO_FORMAT "Mise à jour de Package check...\n" "white" "bold" - echo -e "#!/bin/bash\n" > "$script_dir/upgrade_script.sh" - echo "git clone --quiet https://github.com/YunoHost/package_check \"$script_dir/upgrade\"" >> "$script_dir/upgrade_script.sh" - echo "sudo cp -a \"$script_dir/upgrade/.\" \"$script_dir/.\"" >> "$script_dir/upgrade_script.sh" - echo "sudo rm -r \"$script_dir/upgrade\"" >> "$script_dir/upgrade_script.sh" - echo "echo \"$version_script\" > \"$script_dir/package_version\"" >> "$script_dir/upgrade_script.sh" - echo "sudo rm \"$script_dir/pcheck.lock\"" >> "$script_dir/upgrade_script.sh" - echo "exec \"$script_dir/package_check.sh\" \"$*\"" >> "$script_dir/upgrade_script.sh" - chmod +x "$script_dir/upgrade_script.sh" - exec "$script_dir/upgrade_script.sh" #Exécute le script de mise à jour. - fi -else - echo "$version_script" > "$script_dir/package_version" -fi - -version_plinter="$(git ls-remote https://github.com/YunoHost/package_linter | cut -f 1 | head -n1)" -if [ -e "$script_dir/plinter_version" ] -then - if [ "$version_plinter" != "$(cat "$script_dir/plinter_version")" ]; then # Si le dernier commit sur github ne correspond pas au commit enregistré, il y a une mise à jour. - ECHO_FORMAT "Mise à jour de package_linter..." "white" "bold" - git clone --quiet https://github.com/YunoHost/package_linter "$script_dir/package_linter_tmp" - sudo cp -a "$script_dir/package_linter_tmp/." "$script_dir/package_linter/." - sudo rm -r "$script_dir/package_linter_tmp" - fi -else # Si le fichier de version n'existe pas, il est créé. - echo "$version_plinter" > "$script_dir/plinter_version" - ECHO_FORMAT "Installation de package_linter.\n" "white" - git clone --quiet https://github.com/YunoHost/package_linter "$script_dir/package_linter" -fi -echo "$version_plinter" > "$script_dir/plinter_version" - USER_TEST=package_checker PASSWORD_TEST=checker_pwd PATH_TEST=/check From dbd28ac24b6a0a167529ece493fe99469478ba4b Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Fri, 31 Mar 2017 17:31:56 +0200 Subject: [PATCH 04/10] Refactoring, pre check_process --- package_check.sh | 502 ++++++++++++++++++--------------- sub_scripts/log_extractor.sh | 5 +- sub_scripts/lxc_launcher.sh | 66 ++--- sub_scripts/testing_process.sh | 114 ++++---- 4 files changed, 373 insertions(+), 314 deletions(-) diff --git a/package_check.sh b/package_check.sh index 964ce6c..cbf9275 100755 --- a/package_check.sh +++ b/package_check.sh @@ -6,6 +6,39 @@ if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(echo $PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi +#================================================= +# Generic functions +#================================================= + +is_it_locked () { + test -e "$script_dir/pcheck.lock" +} + +clean_exit () { + # Exit and remove all temp files + # $1 = exit code + + # 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 the application which been tested + if [ -n "$package_path" ]; then + rm -rf "$package_path" + fi + + # Remove the lock file + rm -f "$lock_file" + + exit $1 +} + #================================================= # Check and read CLI arguments #================================================= @@ -38,7 +71,7 @@ else # Read and parse all the arguments while [ $# -ne 0 ] do - # Initialize getopts' index + # Initialize the index of getopts OPTIND=1 # Parse with getopts only if the argument begin by - if [ ${1:0:1} = "-" ] @@ -112,9 +145,35 @@ package_check.sh [OPTION]... PACKAGE_TO_CHECK -y, --bash-mode Do not ask for continue check. Ignore auto_remove. EOF - exit 0 + clean_exit 0 fi +#================================================= +# Check if the lock file exist +#================================================= + +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." + answer="y" + if [ $bash_mode -ne 1 ]; then + echo -n "Do you want to continue anymore? (y/n) :" + read answer + fi + # Set the answer at lowercase only + answer=${answer,,} + if [ "${rep:0:1}" != "y" ] + then + echo "Cancel Package check execution" + clean_exit 0 + fi +fi +# Create the lock file +touch "$lock_file" + #================================================= # Upgrade Package check #================================================= @@ -139,11 +198,11 @@ then #!/bin/bash # Clone in another directory git clone --quiet $git_repository "$script_dir/upgrade" -sudo cp -a "$script_dir/upgrade/." "$script_dir/." -sudo rm -r "$script_dir/upgrade" +cp -a "$script_dir/upgrade/." "$script_dir/." +rm -r "$script_dir/upgrade" # Update the version file echo "$check_version" > "$version_file" -sudo rm "$script_dir/pcheck.lock" +rm "$script_dir/pcheck.lock" # Execute package check by replacement of this process exec "$script_dir/package_check.sh" "$arguments" EOF @@ -181,8 +240,8 @@ then git clone --quiet https://github.com/YunoHost/package_linter "$script_dir/package_linter_tmp" # And replace - sudo cp -a "$script_dir/package_linter_tmp/." "$script_dir/package_linter/." - sudo rm -r "$script_dir/package_linter_tmp" + cp -a "$script_dir/package_linter_tmp/." "$script_dir/package_linter/." + rm -r "$script_dir/package_linter_tmp" fi else echo -e "\e[97mInstall Package linter.\n\e[0m" @@ -192,17 +251,111 @@ fi # Update the version file echo "$check_version" > "$version_file" - - #================================================= -# Globals variables +# Get variables from the config file #================================================= +pcheck_config="$script_dir/config" +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) +fi + +# Use default value from the build script if needed +if [ -z "$ip_range" ]; then + ip_range=$(grep "|| PLAGE_IP=" "$build_script" | cut -d '"' -f4) + echo -e "# Ip range for the container\nPLAGE_IP=$ip_range\n" >> "$pcheck_config" +fi +if [ -z "$main_domain" ]; then + main_domain=$(grep "|| DOMAIN=" "$build_script" | cut -d '=' -f2) + echo -e "# Test domain\nDOMAIN=$main_domain\n" >> "$pcheck_config" +fi +if [ -z "$yuno_pwd" ]; then + yuno_pwd=$(grep "|| YUNO_PWD=" "$build_script" | cut -d '=' -f2) + echo -e "# YunoHost password, in the container\nYUNO_PWD=$yuno_pwd\n" >> "$pcheck_config" +fi +if [ -z "$lxc_name" ]; then + lxc_name=$(grep "|| LXC_NAME=" "$build_script" | cut -d '=' -f2) + echo -e "# Container name\nLXC_NAME=$lxc_name\n" >> "$pcheck_config" +fi +if [ -z "$lxc_bridge" ]; then + lxc_bridge=$(grep "|| LXC_BRIDGE=" "$build_script" | cut -d '=' -f2) + echo -e "# Bridge name\nLXC_BRIDGE=$lxc_bridge\n" >> "$pcheck_config" +fi + +if [ -z "$main_iface" ]; then + # Try to determine the main iface + main_iface=$(sudo route | grep default | awk '{print $8;}') + if [ -z $main_iface ] + then + echo -e "\e[91mUnable to find the name of the main iface.\e[0m" + clean_exit 1 + fi + # Store the main iface in the config file + echo -e "# Main host iface\niface=$main_iface\n" >> "$pcheck_config" +fi + +#================================================= +# Check the user who try to execute this script +#================================================= + +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 +else + echo -e "\e[93mUnable to define the user who authorised to use package check. Please fill the file $setup_user_file\e[0m" +fi + +#================================================= +# Check the internet connectivity +#================================================= + +# 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" + clean_exit 1 + fi +fi + +#================================================= +# Define globals variables +#================================================= + +# 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" -yunohost_log="/var/lib/lxc/\$LXC_NAME/rootfs/var/log/yunohost/yunohost-cli.log" +# Real YunoHost log +yunohost_log="/var/lib/lxc/$lxc_name/rootfs/var/log/yunohost/yunohost-cli.log" + +sub_domain="sous.$main_domain" +test_user=package_checker +test_password=checker_pwd +test_path=/check #================================================= # Load all functions @@ -213,195 +366,110 @@ source "$script_dir/sub_scripts/testing_process.sh" source "$script_dir/sub_scripts/log_extractor.sh" source /usr/share/yunohost/helpers +#================================================= +# Check LXC +#================================================= - - - - - - - - - -# Détermine l'environnement d'exécution de Package check -type_exec_env=0 # Par défaut, exécution de package check seul -if [ -e "$script_dir/../config" ]; then - type_exec_env=1 # Exécution en contexte de CI -fi -if [ -e "$script_dir/../auto_build/auto.conf" ]; then - type_exec_env=2 # Exécution en contexte de CI officiel -fi - -# Check user -if [ "$(whoami)" != "$(cat "$script_dir/sub_scripts/setup_user")" ] && test -e "$script_dir/sub_scripts/setup_user"; then - echo -e "\e[91mCe script doit être exécuté avec l'utilisateur $(cat "$script_dir/sub_scripts/setup_user") !\nL'utilisateur actuel est $(whoami)." - echo -en "\e[0m" - exit 0 -fi - -# Vérifie la connexion internet. -ping -q -c 2 yunohost.org > /dev/null 2>&1 -if [ "$?" -ne 0 ]; then # En cas d'échec de connexion, tente de pinger un autre domaine pour être sûr - ping -q -c 2 framasoft.org > /dev/null 2>&1 - if [ "$?" -ne 0 ]; then # En cas de nouvel échec de connexion. On considère que la connexion est down... - ECHO_FORMAT "Impossible d'établir une connexion à internet.\n" "red" - exit 1 - fi -fi - -if test -e "$script_dir/pcheck.lock" -then # Présence du lock, Package check ne peut pas continuer. - echo "Le fichier $script_dir/pcheck.lock est présent. Package check est déjà utilisé." - rep="N" - if [ "$bash_mode" -ne 1 ]; then - echo -n "Souhaitez-vous continuer quand même et ignorer le lock ? (Y/N) :" - read rep - fi - if [ "${rep:0:1}" != "Y" ] && [ "${rep:0:1}" != "y" ] && [ "${rep:0:1}" != "O" ] && [ "${rep:0:1}" != "o" ] - then # Teste uniquement le premier caractère de la réponse pour continuer malgré le lock. - echo "L'exécution de Package check est annulée" - exit 0 - fi -fi -touch "$script_dir/pcheck.lock" # Met en place le lock de Package check - -USER_TEST=package_checker -PASSWORD_TEST=checker_pwd -PATH_TEST=/check - -# Récupère les informations depuis le fichier de conf (Ou le complète le cas échéant) -pcheck_config="$script_dir/config" -# Tente de lire les informations depuis le fichier de config si il existe -if [ -e "$pcheck_config" ] +# Check if lxc is already installed +if dpkg-query -W -f '${Status}' "lxc" 2>/dev/null | grep -q "ok installed" then - PLAGE_IP=$(cat "$pcheck_config" | grep PLAGE_IP= | cut -d '=' -f2) - DOMAIN=$(cat "$pcheck_config" | grep DOMAIN= | cut -d '=' -f2) - YUNO_PWD=$(cat "$pcheck_config" | grep YUNO_PWD= | cut -d '=' -f2) - LXC_NAME=$(cat "$pcheck_config" | grep LXC_NAME= | cut -d '=' -f2) - LXC_BRIDGE=$(cat "$pcheck_config" | grep LXC_BRIDGE= | cut -d '=' -f2) - main_iface=$(cat "$pcheck_config" | grep iface= | cut -d '=' -f2) -fi -# Utilise des valeurs par défaut si les variables sont vides, et génère le fichier de config -if [ -z "$PLAGE_IP" ]; then - PLAGE_IP=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| PLAGE_IP=" | cut -d '"' -f4) - echo -e "# Plage IP du conteneur\nPLAGE_IP=$PLAGE_IP\n" >> "$pcheck_config" -fi -if [ -z "$DOMAIN" ]; then - DOMAIN=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| DOMAIN=" | cut -d '=' -f2) - echo -e "# Domaine de test\nDOMAIN=$DOMAIN\n" >> "$pcheck_config" -fi -if [ -z "$YUNO_PWD" ]; then - YUNO_PWD=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| YUNO_PWD=" | cut -d '=' -f2) - echo -e "# Mot de passe\nYUNO_PWD=$YUNO_PWD\n" >> "$pcheck_config" -fi -if [ -z "$LXC_NAME" ]; then - LXC_NAME=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| LXC_NAME=" | cut -d '=' -f2) - echo -e "# Nom du conteneur\nLXC_NAME=$LXC_NAME\n" >> "$pcheck_config" -fi -if [ -z "$LXC_BRIDGE" ]; then - LXC_BRIDGE=$(cat "$script_dir/sub_scripts/lxc_build.sh" | grep "|| LXC_BRIDGE=" | cut -d '=' -f2) - echo -e "# Nom du bridge\nLXC_BRIDGE=$LXC_BRIDGE\n" >> "$pcheck_config" -fi -if [ -z "$main_iface" ]; then - # Tente de définir l'interface réseau principale - main_iface=$(sudo route | grep default | awk '{print $8;}') # Prend l'interface réseau défini par default - if [ -z $main_iface ]; then - echo -e "\e[91mImpossible de déterminer le nom de l'interface réseau de l'hôte.\e[0m" - exit 1 - fi - # Enregistre le nom de l'interface réseau de l'hôte dans un fichier de config - echo -e "# Interface réseau principale de l'hôte\niface=$main_iface\n" >> "$pcheck_config" -fi - -if [ "$no_lxc" -eq 0 ] -then - DOMAIN=$(sudo cat /var/lib/lxc/$LXC_NAME/rootfs/etc/yunohost/current_host) -else - DOMAIN=$(sudo yunohost domain list -l 1 | cut -d" " -f 2) -fi -SOUS_DOMAIN="sous.$DOMAIN" - -if [ "$no_lxc" -eq 0 ] -then # Si le conteneur lxc est utilisé - lxc_ok=0 - # Vérifie la présence du virtualisateur en conteneur LXC - if dpkg-query -W -f '${Status}' "lxc" 2>/dev/null | grep -q "ok installed"; then - if sudo lxc-ls | grep -q "$LXC_NAME"; then # Si lxc est installé, vérifie la présence de la machine $LXC_NAME - lxc_ok=1 - fi - fi - if [ "$lxc_ok" -eq 0 ] + # 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 ] + if [ $build_lxc -eq 1 ] then - "$script_dir/sub_scripts/lxc_build.sh" # Lance la construction de la machine virtualisée. + # If lxc's not installed and build_lxc set. Asks to build the container. + build_lxc=2 else - ECHO_FORMAT "Lxc n'est pas installé, ou la machine $LXC_NAME n'est pas créée.\n" "red" - ECHO_FORMAT "Utilisez le script 'lxc_build.sh' pour installer lxc et créer la machine.\n" "red" - ECHO_FORMAT "Ou utilisez l'argument --no-lxc\n" "red" - sudo rm "$script_dir/pcheck.lock" # Retire le lock - exit 1 + 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 - # Stoppe toute activité éventuelle du conteneur, en cas d'arrêt incorrect précédemment - LXC_STOP - LXC_TURNOFF -else # Vérifie l'utilisateur et le domain si lxc n'est pas utilisé. - # Vérifie l'existence de l'utilisateur de test - echo -e "\nVérification de l'existence de l'utilisateur de test..." - if ! ynh_user_exists "$USER_TEST" - then # Si il n'existe pas, il faut le créer. - USER_TEST_CLEAN=${USER_TEST//"_"/""} - sudo yunohost user create --firstname "$USER_TEST_CLEAN" --mail "$USER_TEST_CLEAN@$DOMAIN" --lastname "$USER_TEST_CLEAN" --password "$PASSWORD_TEST" "$USER_TEST" - if [ "$?" -ne 0 ]; then - ECHO_FORMAT "La création de l'utilisateur de test a échoué. Impossible de continuer.\n" "red" - sudo rm "$script_dir/pcheck.lock" # Retire le lock - exit 1 - fi - fi - - # Vérifie l'existence du sous-domaine de test - echo "Vérification de l'existence du domaine de test..." - if [ "$(sudo yunohost domain list | grep -c "$SOUS_DOMAIN")" -eq 0 ]; then # Si il n'existe pas, il faut le créer. - sudo yunohost domain add "$SOUS_DOMAIN" - if [ "$?" -ne 0 ]; then - ECHO_FORMAT "La création du sous-domain de test a échoué. Impossible de continuer.\n" "red" - sudo rm "$script_dir/pcheck.lock" # Retire le lock - exit 1 - fi - fi -fi - -# Vérifie le type d'emplacement du package à tester -echo "Récupération du package à tester." -rm -rf "$script_dir"/*_check -GIT_PACKAGE=0 -if echo "$arg_app" | grep -Eq "https?:\/\/" +elif [ $build_lxc -eq 1 ] then - GIT_PACKAGE=1 - git clone $arg_app $gitbranch "$script_dir/$(basename "$arg_app")_check" -else - # Si c'est un dossier local, il est copié dans le dossier du script. - sudo cp -a --remove-destination "$arg_app" "$script_dir/$(basename "$arg_app")_check" -fi -APP_CHECK="$script_dir/$(basename "$arg_app")_check" -if [ "$no_lxc" -eq 0 ] -then # En cas d'exécution dans LXC, l'app sera dans le home de l'user LXC. - APP_PATH_YUNO="$(basename "$arg_app")_check" -else - APP_PATH_YUNO="$APP_CHECK" + # If lxc's not installed and build_lxc set. Asks to build the container. + build_lxc=2 fi -if [ ! -d "$APP_CHECK" ]; then - ECHO_FORMAT "Le dossier de l'application a tester est introuvable...\n" "red" - sudo rm "$script_dir/pcheck.lock" # Retire le lock - exit 1 +if [ $build_lxc -eq 2 ] +then + # Install LXC and build the container before continue. + "$script_dir/sub_scripts/lxc_build.sh" fi -sudo rm -rf "$APP_CHECK/.git" # Purge des fichiers de git + +# Stop and restore the LXC container. In case of previous incomplete execution. +LXC_STOP +# Deactivate LXC network +LXC_TURNOFF + +#================================================= +# Determine if it's a CI environment +#================================================= + +# By default, it's a standalone execution. +type_exec_env=0 +if [ -e "$script_dir/../config" ] +then + # CI environment + type_exec_env=1 +fi +if [ -e "$script_dir/../auto_build/auto.conf" ] +then + # Official CI environment + type_exec_env=2 +fi + +#================================================= +# Pick up the package +#================================================= + +echo "Pick up the package which will be tested." + +# Remove the previous package if it's still here. +rm -rf "$script_dir"/*_check + +package_dir="$(basename "$other_args")_check" +package_path="$script_dir/$package_dir" + +# If the package is in a git repository +if echo "$other_args" | grep -Eq "https?:\/\/" +then + # Clone the repository + git clone $other_args $gitbranch "$package_path" + +# If it's a local directory +else + # Do a copy in the directory of Package check + cp -a "$other_args" "$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 +fi + +# Remove the .git directory. +rm -rf "$package_path/.git" + + + + + + + + + + + + + + # Vérifie l'existence du fichier check_process check_file=1 -if [ ! -e "$APP_CHECK/check_process" ]; then +if [ ! -e "$package_path/check_process" ]; then ECHO_FORMAT "\nImpossible de trouver le fichier check_process pour procéder aux tests.\n" "red" ECHO_FORMAT "Package check va être utilisé en mode dégradé.\n" "lyellow" check_file=0 @@ -497,7 +565,7 @@ TEST_RESULTS () { if [ "$GLOBAL_LINTER" -eq 1 ]; then ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_LINTER" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" fi @@ -505,7 +573,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_SETUP" -eq 1 ]; then ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_SETUP" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" fi @@ -514,7 +582,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_REMOVE" -eq 1 ]; then ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_REMOVE" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" fi @@ -523,7 +591,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_SUB_DIR" -eq 1 ]; then ECHO_FORMAT "\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_SUB_DIR" -eq -1 ]; then - ECHO_FORMAT "\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\tFAIL\n" "red" else ECHO_FORMAT "\t\tNot evaluated.\n" "white" fi @@ -532,7 +600,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_REMOVE_SUBDIR" -eq 1 ]; then ECHO_FORMAT "\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_REMOVE_SUBDIR" -eq -1 ]; then - ECHO_FORMAT "\tFAIL\n" "lred" + ECHO_FORMAT "\tFAIL\n" "red" else ECHO_FORMAT "\tNot evaluated.\n" "white" fi @@ -541,7 +609,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_ROOT" -eq 1 ]; then ECHO_FORMAT "\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_ROOT" -eq -1 ]; then - ECHO_FORMAT "\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\tFAIL\n" "red" else ECHO_FORMAT "\t\tNot evaluated.\n" "white" fi @@ -550,7 +618,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_REMOVE_ROOT" -eq 1 ]; then ECHO_FORMAT "\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_REMOVE_ROOT" -eq -1 ]; then - ECHO_FORMAT "\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\tFAIL\n" "red" else ECHO_FORMAT "\t\tNot evaluated.\n" "white" fi @@ -559,7 +627,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_UPGRADE" -eq 1 ]; then ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_UPGRADE" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" fi @@ -568,7 +636,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_PRIVATE" -eq 1 ]; then ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_PRIVATE" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" fi @@ -577,7 +645,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_PUBLIC" -eq 1 ]; then ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_PUBLIC" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" fi @@ -586,7 +654,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_MULTI_INSTANCE" -eq 1 ]; then ECHO_FORMAT "\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_MULTI_INSTANCE" -eq -1 ]; then - ECHO_FORMAT "\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\tFAIL\n" "red" else ECHO_FORMAT "\t\tNot evaluated.\n" "white" fi @@ -595,7 +663,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_ADMIN" -eq 1 ]; then ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_ADMIN" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" fi @@ -604,7 +672,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_DOMAIN" -eq 1 ]; then ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_DOMAIN" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" fi @@ -613,7 +681,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_PATH" -eq 1 ]; then ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_PATH" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" fi @@ -622,7 +690,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_PORT" -eq 1 ]; then ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_PORT" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" fi @@ -631,7 +699,7 @@ TEST_RESULTS () { # if [ "$GLOBAL_CHECK_CORRUPT" -eq 1 ]; then # ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" # elif [ "$GLOBAL_CHECK_CORRUPT" -eq -1 ]; then -# ECHO_FORMAT "\t\t\tFAIL\n" "lred" +# ECHO_FORMAT "\t\t\tFAIL\n" "red" # else # ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" # fi @@ -640,7 +708,7 @@ TEST_RESULTS () { # if [ "$GLOBAL_CHECK_DL" -eq 1 ]; then # ECHO_FORMAT "\tSUCCESS\n" "lgreen" # elif [ "$GLOBAL_CHECK_DL" -eq -1 ]; then -# ECHO_FORMAT "\tFAIL\n" "lred" +# ECHO_FORMAT "\tFAIL\n" "red" # else # ECHO_FORMAT "\tNot evaluated.\n" "white" # fi @@ -649,7 +717,7 @@ TEST_RESULTS () { # if [ "$GLOBAL_CHECK_FINALPATH" -eq 1 ]; then # ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" # elif [ "$GLOBAL_CHECK_FINALPATH" -eq -1 ]; then -# ECHO_FORMAT "\t\t\tFAIL\n" "lred" +# ECHO_FORMAT "\t\t\tFAIL\n" "red" # else # ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" # fi @@ -658,7 +726,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_BACKUP" -eq 1 ]; then ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_BACKUP" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" fi @@ -667,7 +735,7 @@ TEST_RESULTS () { if [ "$GLOBAL_CHECK_RESTORE" -eq 1 ]; then ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" elif [ "$GLOBAL_CHECK_RESTORE" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "lred" + ECHO_FORMAT "\t\t\t\tFAIL\n" "red" else ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" fi @@ -794,7 +862,7 @@ INIT_VAR INIT_LEVEL echo -n "" > "$complete_log" # Initialise le fichier de log echo -n "" > "$test_result" # Initialise le fichier des résulats d'analyse -echo -n "" | sudo tee "$script_dir/lxc_boot.log" # Initialise le fichier de log du boot du conteneur +echo -n "" | tee "$script_dir/lxc_boot.log" # Initialise le fichier de log du boot du conteneur if [ "$no_lxc" -eq 0 ]; then LXC_INIT fi @@ -819,7 +887,7 @@ then # Si le fichier check_process est trouvé level[$(echo "$LIGNE" | cut -d '=' -f1 | cut -d ' ' -f2)]=$(echo "$LIGNE" | cut -d '=' -f2) fi fi - done 4< "$APP_CHECK/check_process" + done 4< "$package_path/check_process" while read <&4 LIGNE do LIGNE=$(echo $LIGNE | sed 's/^ *"//g') # Efface les espaces en début de ligne @@ -868,7 +936,7 @@ then # Si le fichier check_process est trouvé 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) + test_path=$(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 @@ -1001,9 +1069,9 @@ then # Si le fichier check_process est trouvé fi fi fi - done 4< "$APP_CHECK/check_process" # Utilise le descripteur de fichier 4. Car le descripteur 1 est utilisé par d'autres boucles while read dans ces scripts. + done 4< "$package_path/check_process" # Utilise le descripteur de fichier 4. Car le descripteur 1 est utilisé par d'autres boucles while read dans ces scripts. else # Si le fichier check_process n'a pas été trouvé, fonctionne en mode dégradé. - python "$script_dir/sub_scripts/ci/maniackc.py" "$APP_CHECK/manifest.json" > "$script_dir/manifest_extract" # Extrait les infos du manifest avec le script de Bram + python "$script_dir/sub_scripts/ci/maniackc.py" "$package_path/manifest.json" > "$script_dir/manifest_extract" # Extrait les infos du manifest avec le script de Bram pkg_linter=1 setup_sub_dir=1 setup_root=1 @@ -1051,7 +1119,7 @@ else # Si le fichier check_process n'a pas été trouvé, fonctionne en mode dé wrong_user=0 all_test=$((all_test-1)) fi - if grep multi_instance "$APP_CHECK/manifest.json" | grep -q false + if grep multi_instance "$package_path/manifest.json" | grep -q false then # Retire le test multi instance si la clé du manifest est à false multi_instance=0 fi @@ -1093,7 +1161,7 @@ then message="$message descend du niveau $previous_level au niveau $level" fi fi - 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) + ci_path=$(grep "main_domain=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2)/$(grep "CI_PATH=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2) message="$message sur https://$ci_path$job_log" if ! echo "$job" | grep -q "(testing)\|(unstable)"; then # Notifie par xmpp seulement sur stable "$script_dir/../auto_build/xmpp_bot/xmpp_post.sh" "$message" # Notifie sur le salon apps @@ -1102,7 +1170,7 @@ fi if [ "$level" -eq 0 ] && [ $type_exec_env -eq 1 ] then # Si l'app est au niveau 0, et que le test tourne en CI, envoi un mail d'avertissement. - dest=$(cat "$APP_CHECK/manifest.json" | grep '\"email\": ' | cut -d '"' -f 4) # Utilise l'adresse du mainteneur de l'application + dest=$(cat "$package_path/manifest.json" | grep '\"email\": ' | cut -d '"' -f 4) # Utilise l'adresse du mainteneur de l'application ci_path=$(grep "CI_URL=" "$script_dir/../config" | cut -d= -f2) if [ -n "$ci_path" ]; then message="$message sur $ci_path" @@ -1112,9 +1180,3 @@ fi echo "Le log complet des installations et suppressions est disponible dans le fichier $complete_log" # Clean -rm -f "$OUTPUTD" "$temp_RESULT" "$script_dir/url_output" "$script_dir/curl_print" "$script_dir/manifest_extract" - -if [ -n "$APP_CHECK" ]; then - sudo rm -rf "$APP_CHECK" -fi -sudo rm "$script_dir/pcheck.lock" # Retire le lock diff --git a/sub_scripts/log_extractor.sh b/sub_scripts/log_extractor.sh index 1cfd244..3475fde 100755 --- a/sub_scripts/log_extractor.sh +++ b/sub_scripts/log_extractor.sh @@ -1,6 +1,6 @@ #!/bin/bash -echo "Load functions from log_extractor.sh" +echo "Loads functions from log_extractor.sh" ECHO_FORMAT () { # Simply an echo with color and typo @@ -14,9 +14,6 @@ ECHO_FORMAT () { if [ "$2" == "lyellow" ]; then echo -en "\e[93m" fi - if [ "$2" == "lred" ]; then - echo -en "\e[91m" - fi if [ "$2" == "lgreen" ]; then echo -en "\e[92m" fi diff --git a/sub_scripts/lxc_launcher.sh b/sub_scripts/lxc_launcher.sh index 6a2b52a..555a6c9 100755 --- a/sub_scripts/lxc_launcher.sh +++ b/sub_scripts/lxc_launcher.sh @@ -1,6 +1,6 @@ #!/bin/bash -echo -e "Load functions from lxc_launcher.sh" +echo -e "Loads functions from lxc_launcher.sh" #================================================= # Globals variables @@ -11,7 +11,7 @@ arg_ssh="-tt" #================================================= is_lxc_running () { - sudo lxc-info --name=$LXC_NAME | grep --quiet "RUNNING" + sudo lxc-info --name=$lxc_name | grep --quiet "RUNNING" } LXC_INIT () { @@ -19,13 +19,13 @@ LXC_INIT () { # 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 + sudo ifup $lxc_bridge --interfaces=/etc/network/interfaces.d/$lxc_bridge | 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 "$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 $PLAGE_IP.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1 + 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 } LXC_START () { @@ -41,7 +41,7 @@ LXC_START () { # Try to start only if the container is not already started if ! is_lxc_running; then echo "Start the LXC container" | tee --append "$test_result" - sudo lxc-start --name=$LXC_NAME --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$test_result" 2>&1 + sudo lxc-start --name=$lxc_name --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$test_result" 2>&1 else echo "An LXC container is already running" | tee --append "$test_result" fi @@ -52,7 +52,7 @@ LXC_START () { do echo -n . # Try to connect with ssh to check if the container is ready to work. - if ssh $arg_ssh $LXC_NAME "exit 0" > /dev/null 2>&1; then + if ssh $arg_ssh $lxc_name "exit 0" > /dev/null 2>&1; then # Break the for loop if the container is ready. break fi @@ -62,19 +62,19 @@ LXC_START () { local failstart=0 # Check if the container is running if ! is_lxc_running; then - ECHO_FORMAT "The LXC container didn't start...\n" "lred" "bold" + 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" "lred" "bold" + ECHO_FORMAT "Rebooting the container...\n" "red" "bold" fi LXC_STOP # Stop the LXC container - elif ! ssh $arg_ssh $LXC_NAME "sudo ping -q -c 2 security.debian.org > /dev/null 2>&1; exit \$?" >> "$test_result" 2>&1 + elif ! ssh $arg_ssh $lxc_name "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" "lred" "bold" + 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" "lred" "bold" + ECHO_FORMAT "Rebooting the container...\n" "red" "bold" fi LXC_STOP # Stop the LXC container else @@ -85,7 +85,7 @@ LXC_START () { # Failed if the container failed to start if [ $i -eq $max_try ] && [ $failstart -eq 1 ] then - ECHO_FORMAT "The container failed to start $max_try times...\nIf this problem is persistent, try to fix it with lxc_check.sh." "lred" "bold" + ECHO_FORMAT "The container failed to start $max_try times...\nIf this problem is persistent, try to fix it with lxc_check.sh." "red" "bold" ECHO_FORMAT "Boot log:\n" clog cat "$script_dir/lxc_boot.log" | tee --append "$test_result" return 1 @@ -96,15 +96,15 @@ LXC_START () { COPY_LOG 1 # Copy the package into the container. - scp -rq "$APP_CHECK" "$LXC_NAME": >> "$test_result" 2>&1 + scp -rq "$package_path" "$lxc_name": >> "$test_result" 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 + 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=$? # 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" + sudo cat "/var/lib/lxc/$lxc_name/rootfs/home/pchecker/temp_yunohost-cli.log" >> "$temp_log" # Return the exit code of the ssh command return $returncode @@ -113,55 +113,55 @@ LXC_START () { LXC_STOP () { # Stop and restore the LXC container - local snapshot_path="/var/lib/lxcsnaps/$LXC_NAME/snap0" + local snapshot_path="/var/lib/lxcsnaps/$lxc_name/snap0" # Stop the LXC container if is_lxc_running; then echo "Stop the LXC container" | tee --append "$test_result" - sudo lxc-stop --name=$LXC_NAME | tee --append "$test_result" 2>&1 + sudo lxc-stop --name=$lxc_name | tee --append "$test_result" 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/rootfs/etc/hosts" + if ! sudo grep --quiet "$lxc_name" "$snapshot_path/rootfs/etc/hosts" then # If the hostname was replaced by snap0, fix it if sudo grep --quiet "snap0" "$snapshot_path/rootfs/etc/hosts" then # Replace snap0 by the real hostname - sudo sed --in-place "s/snap0/$LXC_NAME/" "$snapshot_path/rootfs/etc/hosts" + sudo sed --in-place "s/snap0/$lxc_name/" "$snapshot_path/rootfs/etc/hosts" else # Otherwise, simply add the hostname - echo "127.0.0.1 $LXC_NAME" | sudo tee --append "$snapshot_path/rootfs/etc/hosts" > /dev/null + echo "127.0.0.1 $lxc_name" | sudo tee --append "$snapshot_path/rootfs/etc/hosts" > /dev/null fi fi # Restore the snapshot. echo "Restore the previous snapshot." | tee --append "$test_result" - sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/rootfs/" "/var/lib/lxc/$LXC_NAME/rootfs/" > /dev/null 2>> "$test_result" + sudo rsync --acls --archive --delete --executability --itemize-changes --xattrs "$snapshot_path/rootfs/" "/var/lib/lxc/$lxc_name/rootfs/" > /dev/null 2>> "$test_result" } LXC_TURNOFF () { # Deactivate LXC network echo "Deactivate iptables rules." - if sudo iptables --check FORWARD --in-interface $LXC_BRIDGE --out-interface $main_iface --jump ACCEPT 2> /dev/null + 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 + 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 + 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 + 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 $PLAGE_IP.0/24 --jump MASQUERADE 2> /dev/null + 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 $PLAGE_IP.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1 + sudo iptables --table nat --delete POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1 fi echo "Deactivate the network bridge." - if sudo ifquery $LXC_BRIDGE --state > /dev/null + if sudo ifquery $lxc_bridge --state > /dev/null then - sudo ifdown --force $LXC_BRIDGE | tee --append "$test_result" 2>&1 + sudo ifdown --force $lxc_bridge | tee --append "$test_result" 2>&1 fi } @@ -170,11 +170,11 @@ LXC_CONNECT_INFO () { echo "> For access the container:" echo "To execute one command:" - echo -e "\e[1msudo lxc-attach -n $LXC_NAME -- command\e[0m" + echo -e "\e[1msudo lxc-attach -n $lxc_name -- command\e[0m" echo "To establish a ssh connection:" if [ $(cat "$script_dir/setup_user") = "root" ]; then echo -ne "\e[1msudo " fi - echo -e "\e[1mssh $arg_ssh $LXC_NAME\e[0m" + echo -e "\e[1mssh $arg_ssh $lxc_name\e[0m" } diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index 8f00d9f..05fdf92 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -1,6 +1,6 @@ #!/bin/bash -echo -e "Load functions from testing_process.sh" +echo -e "Loads functions from testing_process.sh" #================================================= # Globals variables @@ -29,7 +29,7 @@ SETUP_APP () { # Install an application in a LXC container # Install the application in a LXC container - LXC_START "sudo yunohost --debug app install \"$APP_PATH_YUNO\" -a \"$manifest_args_mod\"" + LXC_START "sudo yunohost --debug app install \"$package_dir\" -a \"$manifest_args_mod\"" # yunohost_result gets the return code of the installation yunohost_result=$? @@ -83,19 +83,19 @@ CHECK_URL () { then # Add a skipped_uris on / for the app LXC_START "sudo yunohost app setting \"$ynh_app_id\" skipped_uris -v \"/\"" - # Regen the sso's config + # 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 - # Inform /etc/hosts of LXC's IP to resolve the domain. + # 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 "$PLAGE_IP.2 $DOMAIN #package_check\n$PLAGE_IP.2 $SOUS_DOMAIN #package_check" | sudo tee --append /etc/hosts > /dev/null + echo -e "$ip_range.2 $main_domain #package_check\n$ip_range.2 $sub_domain #package_check" | sudo tee --append /etc/hosts > /dev/null # Try to resolv the domain during 10 seconds maximum. local i=0 for i in `seq 1 10`; do - curl --location --insecure $SOUS_DOMAIN > /dev/null 2>&1 + curl --location --insecure $sub_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. @@ -148,18 +148,18 @@ CHECK_URL () { # Remove the previous curl output rm -f "$script_dir/url_output" - # Call curl to try to access to the appp's url - curl --location --insecure --silent --show-error --write-out "%{http_code};%{url_effective}\n" $SOUS_DOMAIN$curl_check_path --output "$script_dir/url_output" > "$script_dir/curl_print" + # 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" $sub_domain$curl_check_path --output "$script_dir/url_output" > "$script_dir/curl_print" # Analyze the result of curl command if [ $? -ne 0 ] then - ECHO_FORMAT "Connection error...\n" "lred" "bold" + ECHO_FORMAT "Connection error...\n" "red" "bold" curl_error=1 fi # Print informations about the connection - ECHO_FORMAT "Test url: $SOUS_DOMAIN$curl_check_path\n" "white" + ECHO_FORMAT "Test url: $sub_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" @@ -202,9 +202,9 @@ CHECK_URL () { # Analyze the output of curl if [ -e "$script_dir/url_output" ] then - # Print the page's title + # Print the title of the page local url_title=$(grep "" "$script_dir/url_output" | cut --delimiter='>' --fields=2 | cut --delimiter='<' --fields=1) - ECHO_FORMAT "Titre de la page: $url_title\n" "white" + ECHO_FORMAT "Title of the page: $url_title\n" "white" # Check if the page title is neither the YunoHost portail or default nginx page if [ "$url_title" = "YunoHost Portal" ] @@ -221,7 +221,7 @@ CHECK_URL () { fi # Print the first 20 lines of the body - ECHO_FORMAT "Extract of page's body:\n" "white" + ECHO_FORMAT "Extract of the body:\n" "white" echo -e "\e[37m" # Write in 'light grey' grep "<body" --after-context=20 "$script_dir/url_output" | sed 1d | tee --append "$test_result" echo -e "\e[0m" @@ -259,7 +259,7 @@ check_manifest_key () { if [ -z "$MANIFEST_$1" ] then - ECHO_FORMAT "Unable to find a manifest key for '${1,,}' in the check_process file. Impossible to perform this test\n" "lred" clog + 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 } @@ -276,7 +276,7 @@ replace_manifest_key () { then manifest_args_mod=$(echo $manifest_args_mod | sed "s@$manifest_key=[^&]*\&@${manifest_key}=${2}\&@") else - ECHO_FORMAT "The manifest key $manifest_key doesn't found in the check_process\n" "lred" clog + ECHO_FORMAT "The manifest key $manifest_key doesn't found in the check_process\n" "red" clog fi } @@ -285,7 +285,7 @@ check_success () { } check_failed () { - ECHO_FORMAT "--- FAIL ---\n" "lred" "bold" + ECHO_FORMAT "--- FAIL ---\n" "red" "bold" } check_test_result () { @@ -326,7 +326,7 @@ is_install_failed () { # If subdir installation worked or force_install_ok setted, return subdir. echo subdir else - ECHO_FORMAT "All install checks failed, impossible to perform this test...\n" "lred" clog + ECHO_FORMAT "All installs failed, impossible to perform this test...\n" "red" clog return 1 fi } @@ -360,15 +360,15 @@ CHECK_SETUP () { local manifest_args_mod=$MANIFEST_ARGS # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$SOUS_DOMAIN" + replace_manifest_key "DOMAIN" "$sub_domain" if [ "$install_type" = "subdir" ]; then - local check_path=$PATH_TEST + local check_path=$test_path elif [ "$install_type" = "root" ]; then local check_path=/ fi replace_manifest_key "PATH" "$check_path" - replace_manifest_key "USER" "$USER_TEST" - replace_manifest_key "PASSWORD" "$PASSWORD_TEST" + replace_manifest_key "USER" "$test_user" + replace_manifest_key "PASSWORD" "$test_password" replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" # Install the application in a LXC container @@ -437,16 +437,16 @@ CHECK_UPGRADE () { local manifest_args_mod=$MANIFEST_ARGS # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$SOUS_DOMAIN" + replace_manifest_key "DOMAIN" "$sub_domain" # Use a path according to previous succeeded installs if [ "$previous_install" = "subdir" ]; then - local check_path=$PATH_TEST + local check_path=$test_path elif [ "$previous_install" = "root" ]; then local check_path=/ fi replace_manifest_key "PATH" "$check_path" - replace_manifest_key "USER" "$USER_TEST" - replace_manifest_key "PASSWORD" "$PASSWORD_TEST" + replace_manifest_key "USER" "$test_user" + replace_manifest_key "PASSWORD" "$test_password" replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" # Install the application in a LXC container @@ -459,12 +459,12 @@ CHECK_UPGRADE () { # Check if the install had work if [ $yunohost_result -ne 0 ] then - ECHO_FORMAT "\nInstallation failed...\n" "lred" "bold" + ECHO_FORMAT "\nInstallation failed...\n" "red" "bold" else ECHO_FORMAT "\nUpgrade on the same version...\n" "white" "bold" clog # Upgrade the application in a LXC container - LXC_START "sudo yunohost --debug app upgrade $ynh_app_id -f \"$APP_PATH_YUNO\"" + LXC_START "sudo yunohost --debug app upgrade $ynh_app_id -f \"$package_dir\"" # yunohost_result gets the return code of the upgrade yunohost_result=$? @@ -520,9 +520,9 @@ CHECK_PUBLIC_PRIVATE () { local manifest_args_mod=$MANIFEST_ARGS # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$SOUS_DOMAIN" - replace_manifest_key "USER" "$USER_TEST" - replace_manifest_key "PASSWORD" "$PASSWORD_TEST" + replace_manifest_key "DOMAIN" "$sub_domain" + replace_manifest_key "USER" "$test_user" + replace_manifest_key "PASSWORD" "$test_password" # Set public or private according to type of test requested if [ "$install_type" = "private" ]; then replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_private" @@ -548,7 +548,7 @@ CHECK_PUBLIC_PRIVATE () { replace_manifest_key "PATH" "$check_path" else # Jump to the second path if this check cannot be do - ECHO_FORMAT "Root install check failed, impossible to perform this test...\n" "lyellow" clog + ECHO_FORMAT "Root install failed, impossible to perform this test...\n" "lyellow" clog continue fi @@ -559,11 +559,11 @@ CHECK_PUBLIC_PRIVATE () { if [ $GLOBAL_CHECK_SUB_DIR -eq 1 ] || [ $force_install_ok -eq 1 ] then # Replace manifest key for path - local check_path=$PATH_TEST + 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 check failed, impossible to perform this test...\n" "lyellow" clog + ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "lyellow" clog return fi fi @@ -630,7 +630,7 @@ CHECK_MULTI_INSTANCE () { if [ $GLOBAL_CHECK_SUB_DIR -ne 1 ] && [ $force_install_ok -ne 1 ] then # If subdir installation doesn't worked and force_install_ok not setted, aborted this test. - ECHO_FORMAT "Sub path install check failed, impossible to perform this test...\n" "lred" clog + ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "red" clog return fi @@ -638,9 +638,9 @@ CHECK_MULTI_INSTANCE () { local manifest_args_mod=$MANIFEST_ARGS # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$SOUS_DOMAIN" - replace_manifest_key "USER" "$USER_TEST" - replace_manifest_key "PASSWORD" "$PASSWORD_TEST" + replace_manifest_key "DOMAIN" "$sub_domain" + replace_manifest_key "USER" "$test_user" + replace_manifest_key "PASSWORD" "$test_password" replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" # Install 3 times the same app @@ -650,18 +650,18 @@ CHECK_MULTI_INSTANCE () { # First installation if [ $i -eq 1 ] then - local path_1=$PATH_TEST + local path_1=$test_path ECHO_FORMAT "First installation: path=$path_1\n" clog check_path=$path_1 # Second installation elif [ $i -eq 2 ] then - local path_2=$PATH_TEST-2 + local path_2=$test_path-2 ECHO_FORMAT "Second installation: path=$path_2\n" clog check_path=$path_2 # Third installation else - local path_3="/3-${PATH_TEST#/}" + local path_3="/3-${test_path#/}" ECHO_FORMAT "Third installation: path=$path_3\n" clog check_path=$path_3 fi @@ -767,22 +767,22 @@ CHECK_COMMON_ERROR () { local manifest_args_mod=$MANIFEST_ARGS # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$SOUS_DOMAIN" - replace_manifest_key "USER" "$USER_TEST" - replace_manifest_key "PASSWORD" "$PASSWORD_TEST" + replace_manifest_key "DOMAIN" "$sub_domain" + replace_manifest_key "USER" "$test_user" + replace_manifest_key "PASSWORD" "$test_password" replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" # Replace path manifest key for the test if [ "$install_type" = "incorrect_path" ]; then # Change the path from /path to path/ - local wrong_path=${PATH_TEST#/}/ + 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=$PATH_TEST + local check_path=$test_path else [ "$install_type" = "port_already_use" ] # Use a path according to previous succeeded installs if [ "$previous_install" = "subdir" ]; then - local check_path=$PATH_TEST + local check_path=$test_path elif [ "$previous_install" = "root" ]; then local check_path=/ fi @@ -853,9 +853,9 @@ CHECK_BACKUP_RESTORE () { local manifest_args_mod=$MANIFEST_ARGS # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$SOUS_DOMAIN" - replace_manifest_key "USER" "$USER_TEST" - replace_manifest_key "PASSWORD" "$PASSWORD_TEST" + replace_manifest_key "DOMAIN" "$sub_domain" + replace_manifest_key "USER" "$test_user" + replace_manifest_key "PASSWORD" "$test_password" replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" # Try in 2 times, first in root and second in sub path. @@ -874,7 +874,7 @@ CHECK_BACKUP_RESTORE () { 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 check failed, impossible to perform this test...\n" "lyellow" clog + ECHO_FORMAT "Root install failed, impossible to perform this test...\n" "lyellow" clog continue fi @@ -885,12 +885,12 @@ CHECK_BACKUP_RESTORE () { if [ $GLOBAL_CHECK_SUB_DIR -eq 1 ] || [ $force_install_ok -eq 1 ] then # Replace manifest key for path - local check_path=$PATH_TEST + 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 check failed, impossible to perform this test...\n" "lyellow" clog + ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "lyellow" clog return fi fi @@ -905,7 +905,7 @@ CHECK_BACKUP_RESTORE () { # Made a backup if the installation succeed if [ $yunohost_result -ne 0 ] then - ECHO_FORMAT "\nInstallation failed...\n" "lred" "bold" + ECHO_FORMAT "\nInstallation failed...\n" "red" "bold" else ECHO_FORMAT "\nBackup of the application...\n" "white" "bold" clog @@ -940,7 +940,7 @@ CHECK_BACKUP_RESTORE () { 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 ./ + sudo cp -a /var/lib/lxc/$lxc_name/rootfs/home/yunohost.backup/archives ./ # RESTORE # Try the restore process in 2 times, first after removing the app, second after a restore of the container. @@ -962,7 +962,7 @@ CHECK_BACKUP_RESTORE () { LXC_STOP # Place the copy of the backup archive in the container. - sudo mv -f ./archives /var/lib/lxc/$LXC_NAME/rootfs/home/yunohost.backup/ + sudo mv -f ./archives /var/lib/lxc/$lxc_name/rootfs/home/yunohost.backup/ ECHO_FORMAT "\nRestore on a clean YunoHost system...\n" "white" "bold" clog fi @@ -1012,7 +1012,7 @@ PACKAGE_LINTER () { unit_test_title "Package linter..." # Execute package linter and linter_result gets the return code of the package linter - "$script_dir/package_linter/package_linter.py" "$APP_CHECK" > "$temp_result" + "$script_dir/package_linter/package_linter.py" "$package_path" > "$temp_result" # linter_result gets the return code of the package linter local linter_result=$? @@ -1050,7 +1050,7 @@ TEST_LAUNCHER () { TESTING_PROCESS () { # Launch all tests successively - ECHO_FORMAT "\nScénario de test: $PROCESS_NAME\n" "white" "underlined" clog + ECHO_FORMAT "\nTests serie: $PROCESS_NAME\n" "white" "underlined" clog # Init the value for the current test cur_test=1 From 09d17a8ab21e1152c30c438daedcf9e1956fba94 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis <maniack_crudelis@yahoo.fr> Date: Sat, 1 Apr 2017 01:26:16 +0200 Subject: [PATCH 05/10] [ref] Refactoring parsing of check_process --- check_process | 6 - package_check.sh | 580 +++++++++++++++------------------ sub_scripts/testing_process.sh | 184 +++++------ 3 files changed, 359 insertions(+), 411 deletions(-) diff --git a/check_process b/check_process index 421c303..93fdae7 100644 --- a/check_process +++ b/check_process @@ -1,5 +1,4 @@ ;; Nom du test - auto_remove=1 # Commentaire ignoré ; Manifest domain="domain.tld" (DOMAIN) @@ -20,13 +19,8 @@ upgrade=1 backup_restore=1 multi_instance=1 - wrong_user=1 - wrong_path=1 incorrect_path=1 - corrupt_source=0 - fail_download_source=0 port_already_use=1 (66) - final_path_already_use=0 ;;; Levels Level 1=auto Level 2=auto diff --git a/package_check.sh b/package_check.sh index cbf9275..abf0218 100755 --- a/package_check.sh +++ b/package_check.sh @@ -6,14 +6,12 @@ if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(echo $PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi +#================================================= +# Starting and checking #================================================= # Generic functions #================================================= -is_it_locked () { - test -e "$script_dir/pcheck.lock" -} - clean_exit () { # Exit and remove all temp files # $1 = exit code @@ -354,7 +352,6 @@ yunohost_log="/var/lib/lxc/$lxc_name/rootfs/var/log/yunohost/yunohost-cli.log" sub_domain="sous.$main_domain" test_user=package_checker -test_password=checker_pwd test_path=/check #================================================= @@ -457,24 +454,272 @@ rm -rf "$package_path/.git" +#================================================= +# Parsing and performing tests +#================================================= +# Check if a check_process file exist +#================================================= - - - - - - - - - -# Vérifie l'existence du fichier check_process check_file=1 -if [ ! -e "$package_path/check_process" ]; then - ECHO_FORMAT "\nImpossible de trouver le fichier check_process pour procéder aux tests.\n" "red" - ECHO_FORMAT "Package check va être utilisé en mode dégradé.\n" "lyellow" +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 fi +#================================================= +# Initialize tests +#================================================= + +# Default values for level +level[1]=auto +level[2]=auto +level[3]=auto +level[4]=0 +level[5]=auto +level[6]=auto +level[7]=auto +level[8]=0 +level[9]=0 +level[10]=0 + +# Purge some log files +> "$complete_log" +> "$test_result" +> "$script_dir/lxc_boot.log" + +# Initialize LXC network +LXC_INIT + +# Default values for check_process and TESTING_PROCESS +initialize_values() { + # Test results + RESULT_linter=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_check_=0 + + # auto_remove parameter + if [ $interrupt -eq 1 ]; then + auto_remove=0 + else + auto_remove=1 + fi + + # Number of tests to proceed + all_test=0 +} + +#================================================= +# Parse the check_process +#================================================= + +# Parse the check_process only if it's exist +if [ $check_file -eq 1 ] +then + ECHO_FORMAT "Parsing of 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" + + # 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 "$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 + # Search for the first line + if check_line "$1"; then + # Activate the extract process + extract=1 + fi + + # 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 + done < "$source_file" + } + + # 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" + + # Get the value associated to each level + for i in `seq 1 10` + do + # Find the line for this level + line=$(find_string "^Level $i=") + # And get the value + level[$i]=$(echo "$line" | cut -d '=' -f2) + done + + # Parse each tests serie + while read tests_serie + do + # Initialize the values for this serie of tests + initialize_values + + # 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 "^;; " "^;;" "$check_process" + + # Parse all infos about arguments of manifest + # Extract the manifest arguments section from the second partial file + partial_check_process=$partial1 + extract_section "^; Manifest" "^; " "$partial2" + + # Initialize the arguments list + 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*](.*//')" + # 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") + path_arg=$(keep_name_arg_only "PATH") + user_arg=$(keep_name_arg_only "USER") + port_arg=$(keep_name_arg_only "PORT") + 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 "|public=[[:alnum:]]*" | cut -d "=" -f2)) + fi + + + # 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 + all_test=$((all_test+1)) + return 1 + else + return 0 + fi + } + + pkg_linter=$(read_check_option pkg_linter) + setup_sub_dir=$(read_check_option setup_sub_dir) + setup_root=$(read_check_option setup_root) + setup_nourl=$(read_check_option setup_nourl) + setup_private=$(read_check_option setup_private) + setup_public=$(read_check_option setup_public) + upgrade=$(read_check_option upgrade) + backup_restore=$(read_check_option backup_restore) + multi_instance=$(read_check_option multi_instance) + incorrect_path=$(read_check_option incorrect_path) + port_already_use=$(read_check_option port_already_use) + # 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 + + # Launch all tests successively + TESTING_PROCESS + # Print the final results of the tests + TEST_RESULTS + + +if [ "$bash_mode" -ne 1 ]; then + read -p "Appuyer sur une touche pour démarrer le scénario de test suivant..." < /dev/tty +fi + + done <<< "$(grep "^;; " "$check_process")" + + +else +# No check process... +fi + + +# dégradé + domain_arg="null" + path_arg="null" + user_arg="null" + public_arg="null" + public_public_arg="null" + public_private_arg="null" + port_arg="null" + + + + # Cette fonctionne détermine le niveau final de l'application, en prenant en compte d'éventuels forçages @@ -784,292 +1029,7 @@ TEST_RESULTS () { done } -INIT_VAR() { - GLOBAL_LINTER=0 - GLOBAL_CHECK_SETUP=0 - GLOBAL_CHECK_SUB_DIR=0 - GLOBAL_CHECK_ROOT=0 - GLOBAL_CHECK_REMOVE=0 - GLOBAL_CHECK_REMOVE_SUBDIR=0 - GLOBAL_CHECK_REMOVE_ROOT=0 - GLOBAL_CHECK_UPGRADE=0 - GLOBAL_CHECK_BACKUP=0 - GLOBAL_CHECK_RESTORE=0 - GLOBAL_CHECK_PRIVATE=0 - GLOBAL_CHECK_PUBLIC=0 - GLOBAL_CHECK_MULTI_INSTANCE=0 - GLOBAL_CHECK_ADMIN=0 - GLOBAL_CHECK_DOMAIN=0 - GLOBAL_CHECK_PATH=0 - GLOBAL_CHECK_CORRUPT=0 - GLOBAL_CHECK_DL=0 - GLOBAL_CHECK_PORT=0 - GLOBAL_CHECK_FINALPATH=0 - IN_PROCESS=0 - MANIFEST=0 - CHECKS=0 - if [ $interrupt -eq 1 ]; then - auto_remove=0 - else - auto_remove=1 - fi - install_pass=0 - note=0 - tnote=0 - all_test=0 - MANIFEST_DOMAIN="null" - MANIFEST_PATH="null" - MANIFEST_USER="null" - MANIFEST_PUBLIC="null" - MANIFEST_PUBLIC_public="null" - MANIFEST_PUBLIC_private="null" - MANIFEST_PASSWORD="null" - MANIFEST_PORT="null" - - pkg_linter=0 - setup_sub_dir=0 - setup_root=0 - setup_nourl=0 - setup_private=0 - setup_public=0 - upgrade=0 - backup_restore=0 - multi_instance=0 - wrong_user=0 - wrong_path=0 - incorrect_path=0 - corrupt_source=0 - fail_download_source=0 - port_already_use=0 - final_path_already_use=0 -} - -INIT_LEVEL() { - level[1]="auto" # L'application s'installe et se désinstalle correctement. -- Peut être vérifié par package_check - level[2]="auto" # L'application s'installe et se désinstalle dans toutes les configurations communes. -- Peut être vérifié par package_check - level[3]="auto" # L'application supporte l'upgrade depuis une ancienne version du package. -- Peut être vérifié par package_check - level[4]=0 # L'application prend en charge de LDAP et/ou HTTP Auth. -- Doit être vérifié manuellement - level[5]="auto" # Aucune erreur dans package_linter. -- Peut être vérifié par package_check - level[6]="auto" # L'application peut-être sauvegardée et restaurée sans erreurs sur la même machine ou une autre. -- Peut être vérifié par package_check - level[7]="auto" # Aucune erreur dans package check. -- Peut être vérifié par package_check - level[8]=0 # L'application respecte toutes les YEP recommandées. -- Doit être vérifié manuellement - level[9]=0 # L'application respecte toutes les YEP optionnelles. -- Doit être vérifié manuellement - level[10]=0 # L'application est jugée parfaite. -- Doit être vérifié manuellement -} - -INIT_VAR -INIT_LEVEL -echo -n "" > "$complete_log" # Initialise le fichier de log -echo -n "" > "$test_result" # Initialise le fichier des résulats d'analyse -echo -n "" | tee "$script_dir/lxc_boot.log" # Initialise le fichier de log du boot du conteneur -if [ "$no_lxc" -eq 0 ]; then - LXC_INIT -fi - -if [ "$check_file" -eq 1 ] -then # Si le fichier check_process est trouvé - ## Parsing du fichier check_process de manière séquentielle. - echo "Parsing du fichier check_process" - IN_LEVELS=0 - while read <&4 LIGNE - do # Parse les indications de niveaux d'app avant de parser les tests - LIGNE=$(echo $LIGNE | sed 's/^ *"//g') # Efface les espaces en début de ligne - if [ "${LIGNE:0:1}" == "#" ]; then - continue # Ligne de commentaire, ignorée. - fi - if echo "$LIGNE" | grep -q "^;;; Levels"; then # Définition des variables de niveaux - IN_LEVELS=1 - fi - if [ "$IN_LEVELS" -eq 1 ] - then - if echo "$LIGNE" | grep -q "Level "; then # Définition d'un niveau - level[$(echo "$LIGNE" | cut -d '=' -f1 | cut -d ' ' -f2)]=$(echo "$LIGNE" | cut -d '=' -f2) - fi - fi - done 4< "$package_path/check_process" - while read <&4 LIGNE - do - LIGNE=$(echo $LIGNE | sed 's/^ *"//g') # Efface les espaces en début de ligne - if [ "${LIGNE:0:1}" == "#" ]; then - # Ligne de commentaire, ignorée. - continue - fi - if echo "$LIGNE" | grep -q "^auto_remove="; then # Indication d'auto remove - if [ $interrupt -eq 0 ]; then # Si interrupt est à 1, la valeur du check_process est ignorée. - auto_remove=$(echo "$LIGNE" | cut -d '=' -f2) - fi - fi - if echo "$LIGNE" | grep -q "^;;" && ! echo "$LIGNE" | grep -q "^;;;"; then # Début d'un scénario de test - if [ "$IN_PROCESS" -eq 1 ]; then # Un scénario est déjà en cours. Donc on a atteind la fin du scénario. - TESTING_PROCESS - TEST_RESULTS - INIT_VAR - if [ "$bash_mode" -ne 1 ]; then - read -p "Appuyer sur une touche pour démarrer le scénario de test suivant..." < /dev/tty - fi - fi - PROCESS_NAME=${LIGNE#;; } - IN_PROCESS=1 - MANIFEST=0 - CHECKS=0 - IN_LEVELS=0 - fi - if [ "$IN_PROCESS" -eq 1 ] - then # Analyse des arguments du scenario de test - if echo "$LIGNE" | grep -q "^; Manifest"; then # Arguments du manifest - MANIFEST=1 - MANIFEST_ARGS="" # Initialise la chaine des arguments d'installation - fi - if echo "$LIGNE" | grep -q "^; Checks"; then # Tests à effectuer - MANIFEST=0 - CHECKS=1 - fi - if [ "$MANIFEST" -eq 1 ] - then # Analyse des arguments du manifest - if echo "$LIGNE" | grep -q "="; then - if echo "$LIGNE" | grep -q "(DOMAIN)"; then # Domaine dans le manifest - MANIFEST_DOMAIN=$(echo "$LIGNE" | cut -d '=' -f1) # Récupère la clé du manifest correspondant au domaine - 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 n'est pas null, utilise ce path au lieu de la valeur par défaut. - test_path=$(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 "(USER)"; then # User dans le manifest - MANIFEST_USER=$(echo "$LIGNE" | cut -d '=' -f1) # Récupère la clé du manifest correspondant à l'utilisateur - LIGNE=$(echo "$LIGNE" | cut -d '(' -f1) # Retire l'indicateur de clé de manifest à la fin de la ligne - fi - if echo "$LIGNE" | grep -q "(PUBLIC"; then # Accès public/privé dans le manifest - MANIFEST_PUBLIC=$(echo "$LIGNE" | cut -d '=' -f1) # Récupère la clé du manifest correspondant à l'accès public ou privé - MANIFEST_PUBLIC_public=$(echo "$LIGNE" | grep -o "|public=[[:alnum:]]*" | cut -d "=" -f2) # Récupère la valeur pour un accès public. - MANIFEST_PUBLIC_private=$(echo "$LIGNE" | grep -o "|private=[[:alnum:]]*" | cut -d "=" -f2) # Récupère la valeur pour un accès privé. - LIGNE=$(echo "$LIGNE" | cut -d '(' -f1) # Retire l'indicateur de clé de manifest à la fin de la ligne - fi - if echo "$LIGNE" | grep -q "(PASSWORD)"; then # Password dans le manifest - MANIFEST_PASSWORD=$(echo "$LIGNE" | cut -d '=' -f1) # Récupère la clé du manifest correspondant au mot de passe - LIGNE=$(echo "$LIGNE" | cut -d '(' -f1) # Retire l'indicateur de clé de manifest à la fin de la ligne - fi - if echo "$LIGNE" | grep -q "(PORT)"; then # Port dans le manifest - MANIFEST_PORT=$(echo "$LIGNE" | cut -d '=' -f1) # Récupère la clé du manifest correspondant au port - LIGNE=$(echo "$LIGNE" | cut -d '(' -f1) # Retire l'indicateur de clé de manifest à la fin de la ligne - fi -# if [ "${#MANIFEST_ARGS}" -gt 0 ]; then # Si il y a déjà des arguments -# MANIFEST_ARGS="$MANIFEST_ARGS&" #, précède de & -# fi - MANIFEST_ARGS="$MANIFEST_ARGS$(echo $LIGNE | sed 's/^ *\| *$\|\"//g')&" # Ajoute l'argument du manifest, en retirant les espaces de début et de fin ainsi que les guillemets. - fi - fi - if [ "$CHECKS" -eq 1 ] - then # Analyse des tests à effectuer sur ce scenario. - if echo "$LIGNE" | grep -q "^pkg_linter="; then # Test d'installation en sous-dossier - pkg_linter=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$pkg_linter" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^setup_sub_dir="; then # Test d'installation en sous-dossier - setup_sub_dir=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$setup_sub_dir" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^setup_root="; then # Test d'installation à la racine - setup_root=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$setup_root" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^setup_nourl="; then # Test d'installation sans accès par url - setup_nourl=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$setup_nourl" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^setup_private="; then # Test d'installation en privé - setup_private=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$setup_private" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^setup_public="; then # Test d'installation en public - setup_public=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$setup_public" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^upgrade="; then # Test d'upgrade - upgrade=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$upgrade" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^backup_restore="; then # Test de backup et restore - backup_restore=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$backup_restore" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^multi_instance="; then # Test d'installation multiple - multi_instance=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$multi_instance" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^wrong_user="; then # Test d'erreur d'utilisateur - wrong_user=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$wrong_user" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^wrong_path="; then # Test d'erreur de path ou de domaine - wrong_path=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$wrong_path" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^incorrect_path="; then # Test d'erreur de forme de path - incorrect_path=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$incorrect_path" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^corrupt_source="; then # Test d'erreur sur source corrompue - corrupt_source=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$corrupt_source" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^fail_download_source="; then # Test d'erreur de téléchargement de la source - fail_download_source=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$fail_download_source" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^port_already_use="; then # Test d'erreur de port - port_already_use=$(echo "$LIGNE" | cut -d '=' -f2) - if echo "$LIGNE" | grep -q "([0-9]*)" - then # Le port est mentionné ici. - MANIFEST_PORT="$(echo "$LIGNE" | cut -d '(' -f2 | cut -d ')' -f1)" # Récupère le numéro du port; Le numéro de port est précédé de # pour indiquer son absence du manifest. - port_already_use=${port_already_use:0:1} # Garde uniquement la valeur de port_already_use - fi - if [ "$port_already_use" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - if echo "$LIGNE" | grep -q "^final_path_already_use="; then # Test sur final path déjà utilisé. - final_path_already_use=$(echo "$LIGNE" | cut -d '=' -f2) - if [ "$final_path_already_use" -eq 1 ]; then - all_test=$((all_test+1)) - fi - fi - fi - fi - done 4< "$package_path/check_process" # Utilise le descripteur de fichier 4. Car le descripteur 1 est utilisé par d'autres boucles while read dans ces scripts. else # Si le fichier check_process n'a pas été trouvé, fonctionne en mode dégradé. python "$script_dir/sub_scripts/ci/maniackc.py" "$package_path/manifest.json" > "$script_dir/manifest_extract" # Extrait les infos du manifest avec le script de Bram pkg_linter=1 @@ -1085,17 +1045,17 @@ else # Si le fichier check_process n'a pas été trouvé, fonctionne en mode dé while read LIGNE do if echo "$LIGNE" | grep -q ":ynh.local"; then - MANIFEST_DOMAIN=$(echo "$LIGNE" | grep ":ynh.local" | cut -d ':' -f1) # Garde uniquement le nom de la clé. + domain_arg=$(echo "$LIGNE" | grep ":ynh.local" | cut -d ':' -f1) # Garde uniquement le nom de la clé. fi if echo "$LIGNE" | grep -q "path:"; then - MANIFEST_PATH=$(echo "$LIGNE" | grep "path:" | cut -d ':' -f1) # Garde uniquement le nom de la clé. + path_arg=$(echo "$LIGNE" | grep "path:" | cut -d ':' -f1) # Garde uniquement le nom de la clé. fi if echo "$LIGNE" | grep -q "user:\|admin:"; then - MANIFEST_USER=$(echo "$LIGNE" | grep "user:\|admin:" | cut -d ':' -f1) # Garde uniquement le nom de la clé. + user_arg=$(echo "$LIGNE" | grep "user:\|admin:" | cut -d ':' -f1) # Garde uniquement le nom de la clé. fi - MANIFEST_ARGS="$MANIFEST_ARGS$(echo "$LIGNE" | cut -d ':' -f1,2 | sed s/:/=/)&" # Ajoute l'argument du manifest + manifest_arguments="$manifest_arguments$(echo "$LIGNE" | cut -d ':' -f1,2 | sed s/:/=/)&" # Ajoute l'argument du manifest done < "$script_dir/manifest_extract" - if [ "$MANIFEST_DOMAIN" == "null" ] + if [ "$domain_arg" == "null" ] then ECHO_FORMAT "La clé de manifest du domaine n'a pas été trouvée.\n" "lyellow" setup_sub_dir=0 @@ -1105,7 +1065,7 @@ else # Si le fichier check_process n'a pas été trouvé, fonctionne en mode dé incorrect_path=0 all_test=$((all_test-5)) fi - if [ "$MANIFEST_PATH" == "null" ] + if [ "$path_arg" == "null" ] then ECHO_FORMAT "La clé de manifest du path n'a pas été trouvée.\n" "lyellow" setup_root=0 @@ -1113,7 +1073,7 @@ else # Si le fichier check_process n'a pas été trouvé, fonctionne en mode dé incorrect_path=0 all_test=$((all_test-3)) fi - if [ "$MANIFEST_USER" == "null" ] + if [ "$user_arg" == "null" ] then ECHO_FORMAT "La clé de manifest de l'user admin n'a pas été trouvée.\n" "lyellow" wrong_user=0 diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index 05fdf92..ed7f06b 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -56,14 +56,14 @@ REMOVE_APP () { # Remove the application from the LXC container LXC_START "sudo yunohost --debug 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 "Deleting successful. ($YUNOHOST_REMOVE)\n" "white" clog + if [ "$yunohost_remove" -eq 0 ]; then + ECHO_FORMAT "Deleting successful. ($yunohost_remove)\n" "white" clog else - ECHO_FORMAT "Deleting failed. ($YUNOHOST_REMOVE)\n" "white" clog + ECHO_FORMAT "Deleting failed. ($yunohost_remove)\n" "white" clog fi } @@ -79,7 +79,7 @@ CHECK_URL () { ECHO_FORMAT "\nTry to access by url...\n" "white" "bold" # Force a skipped_uris if public mode is not set - if [ "$MANIFEST_PUBLIC" = "null" ] + if [ -z "$public_arg" ] then # Add a skipped_uris on / for the app LXC_START "sudo yunohost app setting \"$ynh_app_id\" skipped_uris -v \"/\"" @@ -257,7 +257,7 @@ check_manifest_key () { # Check if a manifest key is set # $1 = manifest key - if [ -z "$MANIFEST_$1" ] + 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 @@ -269,8 +269,8 @@ replace_manifest_key () { # $1 = Manifest key # $2 = Replacement value - # Build the variable name by concatenate MANIFEST and $1 - local manifest_key=$(eval echo \$MANIFEST_$1) + # Build the variable name by concatenate $1 and _arg + local manifest_key=$(eval echo \$${1}_arg) if [ -n "$manifest_key" ] then @@ -304,7 +304,7 @@ check_test_result () { check_test_result_remove () { # Check the result of a remove and print SUCCESS or FAIL - if [ $YUNOHOST_REMOVE -eq 0 ] + if [ $yunohost_remove -eq 0 ] then check_success return 0 @@ -317,11 +317,11 @@ check_test_result_remove () { is_install_failed () { # Check if an install have previously work - if [ $GLOBAL_CHECK_ROOT -eq 1 ] + if [ $RESULT_check_root -eq 1 ] then # If root installation worked, return root. echo root - elif [ $GLOBAL_CHECK_SUB_DIR -eq 1 ] || [ $force_install_ok -eq 1 ] + elif [ $RESULT_check_sub_dir -eq 1 ] || [ $force_install_ok -eq 1 ] then # If subdir installation worked or force_install_ok setted, return subdir. echo subdir @@ -352,24 +352,23 @@ CHECK_SETUP () { # 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 + check_manifest_key "domain" || return + check_manifest_key "path" || return fi # Copy original arguments - local manifest_args_mod=$MANIFEST_ARGS + local manifest_args_mod=$manifest_arguments # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$sub_domain" + replace_manifest_key "domain" "$sub_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 "PASSWORD" "$test_password" - replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" + 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 @@ -383,12 +382,12 @@ CHECK_SETUP () { # Check the result and print SUCCESS or FAIL if check_test_result then # Success - GLOBAL_CHECK_SETUP=1 # Installation succeed + RESULT_global_setup=1 # Installation succeed local check_result_setup=1 # Installation in a sub path succeed else # Fail # The global success for a installation can't be failed if another installation succeed - if [ $GLOBAL_CHECK_SETUP -ne 1 ]; then - GLOBAL_CHECK_SETUP=-1 # Installation failed + if [ $RESULT_global_setup -ne 1 ]; then + RESULT_global_setup=-1 # Installation failed fi local check_result_setup=-1 # Installation in a sub path failed fi @@ -403,11 +402,11 @@ CHECK_SETUP () { if check_test_result_remove then # Success local check_result_remove=1 # Remove in sub path succeed - GLOBAL_CHECK_REMOVE=1 # Remove succeed + RESULT_global_remove=1 # Remove succeed else # Fail # The global success for a deletion can't be failed if another remove succeed - if [ $GLOBAL_CHECK_REMOVE -ne 1 ]; then - GLOBAL_CHECK_REMOVE=-1 # Remove failed + 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 @@ -415,11 +414,11 @@ CHECK_SETUP () { # Fill the correct variable depend on the type of test if [ "$install_type" = "subdir" ] then - GLOBAL_CHECK_SUB_DIR=$check_result_setup - GLOBAL_CHECK_REMOVE_SUBDIR=$check_result_remove + RESULT_check_sub_dir=$check_result_setup + RESULT_check_remove_sub_dir=$check_result_remove else # root and no_url - GLOBAL_CHECK_ROOT=$check_result_setup - GLOBAL_CHECK_REMOVE_ROOT=$check_result_remove + RESULT_check_root=$check_result_setup + RESULT_check_remove_root=$check_result_remove fi } @@ -434,20 +433,19 @@ CHECK_UPGRADE () { [ "$previous_install" = "1" ] && return # Copy original arguments - local manifest_args_mod=$MANIFEST_ARGS + local manifest_args_mod=$manifest_arguments # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$sub_domain" + replace_manifest_key "domain" "$sub_domain" # Use a path according to previous succeeded installs if [ "$previous_install" = "subdir" ]; then local check_path=$test_path elif [ "$previous_install" = "root" ]; then local check_path=/ fi - replace_manifest_key "PATH" "$check_path" - replace_manifest_key "USER" "$test_user" - replace_manifest_key "PASSWORD" "$test_password" - replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" + 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 ECHO_FORMAT "\nPreliminary install...\n" "white" "bold" clog @@ -486,9 +484,9 @@ CHECK_UPGRADE () { # Check the result and print SUCCESS or FAIL if check_test_result then # Success - GLOBAL_CHECK_UPGRADE=1 # Upgrade succeed + RESULT_check_upgrade=1 # Upgrade succeed else # Fail - GLOBAL_CHECK_UPGRADE=-1 # Upgrade failed + RESULT_check_upgrade=-1 # Upgrade failed fi # Remove the application @@ -507,9 +505,9 @@ CHECK_PUBLIC_PRIVATE () { 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_manifest_key "public" || return + check_manifest_key "public_public" || return + check_manifest_key "public_private" || return # Check if an install have previously work local previous_install=$(is_install_failed) @@ -517,17 +515,16 @@ CHECK_PUBLIC_PRIVATE () { [ "$previous_install" = "1" ] && return # Copy original arguments - local manifest_args_mod=$MANIFEST_ARGS + local manifest_args_mod=$manifest_arguments # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$sub_domain" - replace_manifest_key "USER" "$test_user" - replace_manifest_key "PASSWORD" "$test_password" + replace_manifest_key "domain" "$sub_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" "$MANIFEST_PUBLIC_private" + replace_manifest_key "public" "$public_private_arg" elif [ "$install_type" = "public" ]; then - replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" + replace_manifest_key "public" "$public_public_arg" fi # Initialize the value @@ -541,11 +538,11 @@ CHECK_PUBLIC_PRIVATE () { if [ $i -eq 0 ] then # Check if root installation worked, or if force_install_ok is setted. - if [ $GLOBAL_CHECK_ROOT -eq 1 ] || [ $force_install_ok -eq 1 ] + if [ $RESULT_check_root -eq 1 ] || [ $force_install_ok -eq 1 ] then # Replace manifest key for path local check_path=/ - replace_manifest_key "PATH" "$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 @@ -556,11 +553,11 @@ CHECK_PUBLIC_PRIVATE () { elif [ $i -eq 1 ] then # Check if sub path installation worked, or if force_install_ok is setted. - if [ $GLOBAL_CHECK_SUB_DIR -eq 1 ] || [ $force_install_ok -eq 1 ] + if [ $RESULT_check_sub_dir -eq 1 ] || [ $force_install_ok -eq 1 ] then # Replace manifest key for path local check_path=$test_path - replace_manifest_key "PATH" "$check_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 @@ -608,9 +605,9 @@ CHECK_PUBLIC_PRIVATE () { # Fill the correct variable depend on the type of test if [ "$install_type" = "private" ] then - GLOBAL_CHECK_PRIVATE=$check_result_public_private + RESULT_check_private=$check_result_public_private else # public - GLOBAL_CHECK_PUBLIC=$check_result_public_private + RESULT_check_public=$check_result_public_private fi # Make a break if auto_remove is set @@ -627,7 +624,7 @@ CHECK_MULTI_INSTANCE () { unit_test_title "Installation multi-instance..." # Check if the sub path install have previously work - if [ $GLOBAL_CHECK_SUB_DIR -ne 1 ] && [ $force_install_ok -ne 1 ] + if [ $RESULT_check_sub_dir -ne 1 ] && [ $force_install_ok -ne 1 ] then # If subdir installation doesn't worked and force_install_ok not setted, aborted this test. ECHO_FORMAT "Sub path install failed, impossible to perform this test...\n" "red" clog @@ -635,13 +632,12 @@ CHECK_MULTI_INSTANCE () { fi # Copy original arguments - local manifest_args_mod=$MANIFEST_ARGS + local manifest_args_mod=$manifest_arguments # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$sub_domain" - replace_manifest_key "USER" "$test_user" - replace_manifest_key "PASSWORD" "$test_password" - replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" + replace_manifest_key "domain" "$sub_domain" + replace_manifest_key "user" "$test_user" + replace_manifest_key "public" "$public_public_arg" # Install 3 times the same app local i=0 @@ -667,7 +663,7 @@ CHECK_MULTI_INSTANCE () { fi # Replace path manifest key for the test - replace_manifest_key "PATH" "$check_path" + replace_manifest_key "path" "$check_path" # Install the application in a LXC container SETUP_APP @@ -733,10 +729,10 @@ CHECK_MULTI_INSTANCE () { if [ $multi_yunohost_result_1 -eq 0 ] && ( [ $multi_yunohost_result_2 -eq 0 ] || [ $multi_yunohost_result_3 -eq 0 ] ) then # Success check_success - GLOBAL_CHECK_MULTI_INSTANCE=1 + RESULT_check_multi_instance=1 else # Fail check_failed - GLOBAL_CHECK_MULTI_INSTANCE=-1 + RESULT_check_multi_instance=-1 fi # Make a break if auto_remove is set @@ -751,11 +747,11 @@ CHECK_COMMON_ERROR () { 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 + 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 + check_manifest_key "port" || return fi # Check if an install have previously work @@ -764,20 +760,19 @@ CHECK_COMMON_ERROR () { [ "$previous_install" = "1" ] && return # Copy original arguments - local manifest_args_mod=$MANIFEST_ARGS + local manifest_args_mod=$manifest_arguments # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$sub_domain" - replace_manifest_key "USER" "$test_user" - replace_manifest_key "PASSWORD" "$test_password" - replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" + replace_manifest_key "domain" "$sub_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" + 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 @@ -786,7 +781,7 @@ CHECK_COMMON_ERROR () { elif [ "$previous_install" = "root" ]; then local check_path=/ fi - replace_manifest_key "PATH" "$check_path" + replace_manifest_key "path" "$check_path" fi # Open the specified port to force the script to find another @@ -794,16 +789,16 @@ CHECK_COMMON_ERROR () { then # If the first character is a #, that means it this port number is not in the manifest - if [ "${MANIFEST_PORT:0:1}" = "#" ] + if [ "${port_arg:0:1}" = "#" ] then # Retrieve the port number - local check_port="${MANIFEST_PORT:1}" + 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" + replace_manifest_key "port" "$check_port" fi # Open the port before the installation @@ -830,9 +825,9 @@ CHECK_COMMON_ERROR () { # Fill the correct variable depend on the type of test if [ "$install_type" = "incorrect_path" ] then - GLOBAL_CHECK_PATH=$check_result_setup + RESULT_check_path=$check_result_setup elif [ "$install_type" = "port_already_use" ]; then - GLOBAL_CHECK_PORT=$check_result_setup + RESULT_check_port=$check_result_setup fi # Make a break if auto_remove is set @@ -850,13 +845,12 @@ CHECK_BACKUP_RESTORE () { [ "$previous_install" = "1" ] && return # Copy original arguments - local manifest_args_mod=$MANIFEST_ARGS + local manifest_args_mod=$manifest_arguments # Replace manifest key for the test - replace_manifest_key "DOMAIN" "$sub_domain" - replace_manifest_key "USER" "$test_user" - replace_manifest_key "PASSWORD" "$test_password" - replace_manifest_key "PUBLIC" "$MANIFEST_PUBLIC_public" + replace_manifest_key "domain" "$sub_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 @@ -866,11 +860,11 @@ CHECK_BACKUP_RESTORE () { if [ $i -eq 0 ] then # Check if root installation worked, or if force_install_ok is setted. - if [ $GLOBAL_CHECK_ROOT -eq 1 ] || [ $force_install_ok -eq 1 ] + if [ $RESULT_check_root -eq 1 ] || [ $force_install_ok -eq 1 ] then # Replace manifest key for path local check_path=/ - replace_manifest_key "PATH" "$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 @@ -882,11 +876,11 @@ CHECK_BACKUP_RESTORE () { elif [ $i -eq 1 ] then # Check if sub path installation worked, or if force_install_ok is setted. - if [ $GLOBAL_CHECK_SUB_DIR -eq 1 ] || [ $force_install_ok -eq 1 ] + if [ $RESULT_check_sub_dir -eq 1 ] || [ $force_install_ok -eq 1 ] then # Replace manifest key for path local check_path=$test_path - replace_manifest_key "PATH" "$check_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 @@ -931,12 +925,12 @@ CHECK_BACKUP_RESTORE () { then # Success check_success # The global success for a backup can't be a success if another backup failed - if [ $GLOBAL_CHECK_BACKUP -ne -1 ]; then - GLOBAL_CHECK_BACKUP=1 # Backup succeed + if [ $RESULT_check_backup -ne -1 ]; then + RESULT_check_backup=1 # Backup succeed fi else # Fail check_failed - GLOBAL_CHECK_BACKUP=-1 # Backup failed + RESULT_check_backup=-1 # Backup failed fi # Grab the backup archive into the LXC container, and keep a copy @@ -990,11 +984,11 @@ CHECK_BACKUP_RESTORE () { if check_test_result then # Success # The global success for a restore can't be a success if another restore failed - if [ $GLOBAL_CHECK_RESTORE -ne -1 ]; then - GLOBAL_CHECK_RESTORE=1 # Restore succeed + if [ $RESULT_check_restore -ne -1 ]; then + RESULT_check_restore=1 # Restore succeed fi else # Fail - GLOBAL_CHECK_RESTORE=-1 # Restore failed + RESULT_check_restore=-1 # Restore failed fi # Make a break if auto_remove is set @@ -1024,10 +1018,10 @@ PACKAGE_LINTER () { if [ $linter_result -eq 0 ] then # Success check_success - GLOBAL_LINTER=1 + RESULT_linter=1 else # Fail check_failed - GLOBAL_LINTER=-1 + RESULT_linter=-1 fi } @@ -1038,7 +1032,7 @@ TEST_LAUNCHER () { # Intialize values yunohost_result=-1 - YUNOHOST_REMOVE=-1 + yunohost_remove=-1 # Execute the test $1 $2 @@ -1050,7 +1044,7 @@ TEST_LAUNCHER () { TESTING_PROCESS () { # Launch all tests successively - ECHO_FORMAT "\nTests serie: $PROCESS_NAME\n" "white" "underlined" clog + ECHO_FORMAT "\nTests serie: $tests_serie\n" "white" "underlined" clog # Init the value for the current test cur_test=1 From 1d2b4620403abc75f2cf4e0c5e7157756ca68ffa Mon Sep 17 00:00:00 2001 From: Maniack Crudelis <maniack_crudelis@yahoo.fr> Date: Mon, 3 Apr 2017 18:42:04 +0200 Subject: [PATCH 06/10] [ref] Print results and No check_process file And some corrections... --- package_check.sh | 748 +++++++++--------- sub_scripts/ci/maniackc.py | 15 - sub_scripts/{lxc_launcher.sh => launcher.sh} | 8 +- .../default_args.py => manifest_parsing.py} | 28 +- sub_scripts/testing_process.sh | 2 +- 5 files changed, 367 insertions(+), 434 deletions(-) delete mode 100755 sub_scripts/ci/maniackc.py rename sub_scripts/{lxc_launcher.sh => launcher.sh} (95%) rename sub_scripts/{ci/default_args.py => manifest_parsing.py} (72%) diff --git a/package_check.sh b/package_check.sh index abf0218..38c9943 100755 --- a/package_check.sh +++ b/package_check.sh @@ -110,7 +110,7 @@ else ;; esac else - other_args="$other_args $1" + other_args="$1" fi shift done @@ -143,7 +143,7 @@ package_check.sh [OPTION]... PACKAGE_TO_CHECK -y, --bash-mode Do not ask for continue check. Ignore auto_remove. EOF - clean_exit 0 + exit 0 fi #================================================= @@ -156,17 +156,16 @@ if test -e "$lock_file" then # If the lock file exist echo "The lock file $lock_file is present. Package check would not continue." - answer="y" if [ $bash_mode -ne 1 ]; then echo -n "Do you want to continue anymore? (y/n) :" read answer fi # Set the answer at lowercase only answer=${answer,,} - if [ "${rep:0:1}" != "y" ] + if [ "${answer:0:1}" != "y" ] then echo "Cancel Package check execution" - clean_exit 0 + exit 0 fi fi # Create the lock file @@ -295,7 +294,11 @@ if [ -z "$main_iface" ]; then if [ -z $main_iface ] then echo -e "\e[91mUnable to find the name of the main iface.\e[0m" - clean_exit 1 + + # Remove the lock file + rm -f "$lock_file" + # And exit + exit 1 fi # Store the main iface in the config file echo -e "# Main host iface\niface=$main_iface\n" >> "$pcheck_config" @@ -331,7 +334,11 @@ if [ "$?" -ne 0 ]; then 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" - clean_exit 1 + + # Remove the lock file + rm -f "$lock_file" + # And exit + exit 1 fi fi @@ -358,7 +365,7 @@ test_path=/check # Load all functions #================================================= -source "$script_dir/sub_scripts/lxc_launcher.sh" +source "$script_dir/sub_scripts/launcher.sh" source "$script_dir/sub_scripts/testing_process.sh" source "$script_dir/sub_scripts/log_extractor.sh" source /usr/share/yunohost/helpers @@ -453,6 +460,215 @@ rm -rf "$package_path/.git" +#================================================= +# Determine and print the results +#================================================= + +TEST_RESULTS () { + + # Print the test result + print_result () { + # Print the name of the test + ECHO_FORMAT "$1: " + + # 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 + 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 "Installation" $RESULT_global_setup + print_result "Deleting" $RESULT_global_remove + print_result "Installation in a sub path" $RESULT_check_sub_dir + print_result "Deleting from a sub path" $RESULT_check_remove_sub_dir + print_result "Installation on the root" $RESULT_check_root + print_result "Deleting from root" $RESULT_check_remove_root + print_result "Upgrade" $RESULT_check_upgrade + print_result "Installation in private mode" $RESULT_check_private + print_result "Installation in public mode" $RESULT_check_public + print_result "Multi-instance installations" $RESULT_check_multi_instance + print_result "Malformed path" $RESULT_check_path + print_result "Port already used" $RESULT_check_port + print_result "Backup" $RESULT_check_backup + print_result "Restore" $RESULT_check_restore + + + + # 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 checked, but it'll be ignored in the final sum + + # 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 + } + + # 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 fifth level + # -> The package have no error with package linter + 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 -eq 1 ] || \ + ( [ $RESULT_linter -ne -1 ] && \ + [ "${level[5]}" == "2" ] ) + then level[5]=2 + else level[5]=0 + fi + fi + + # Evaluate the sixth level + # -> The package can be backup and restore without error + if level_can_change 6 + 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[6]}" == "2" ] ) + 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 + # 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 ] + then level[7]=2 + else level[7]=0 + fi + fi + + # Initialize the global level + global_level=0 + + # 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 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 + + # 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 + + # Then, print the levels + # Print the global level + ECHO_FORMAT "Level of this application: $global_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 +} #================================================= # Parsing and performing tests @@ -512,7 +728,6 @@ initialize_values() { RESULT_check_multi_instance=0 RESULT_check_path=0 RESULT_check_port=0 - RESULT_check_=0 # auto_remove parameter if [ $interrupt -eq 1 ]; then @@ -532,7 +747,7 @@ initialize_values() { # Parse the check_process only if it's exist if [ $check_file -eq 1 ] then - ECHO_FORMAT "Parsing of check_process file" + ECHO_FORMAT "Parsing of check_process file\n" # Remove all commented lines in the check_process sed --in-place '/^#/d' "$check_process" @@ -558,12 +773,6 @@ then local line="" while read line do - # Search for the first line - if check_line "$1"; then - # Activate the extract process - extract=1 - fi - # Extract the line if [ $extract -eq 1 ] then @@ -575,6 +784,12 @@ then # 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" } @@ -592,21 +807,26 @@ then # Find the line for this level line=$(find_string "^Level $i=") # And get the value - level[$i]=$(echo "$line" | cut -d '=' -f2) + level[$i]=$(echo "$line" | cut -d'=' -f2) done # Parse each tests serie while read tests_serie do + # 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 + # 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 "^;; " "^;;" "$check_process" - + extract_section "^$tests_serie" "^;;" "$check_process" # Parse all infos about arguments of manifest # Extract the manifest arguments section from the second partial file partial_check_process=$partial1 @@ -643,8 +863,8 @@ then 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 "|public=[[:alnum:]]*" | cut -d "=" -f2)) + 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 @@ -660,24 +880,40 @@ then # And return this value if [ "${value:0:1}" = "1" ] then - all_test=$((all_test+1)) - return 1 + echo 1 else - return 0 + echo 0 fi } + count_test () { + # Increase the number of test, if this test is set at 1. + test "$1" -eq 1 && all_test=$((all_test+1)) + } + 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 upgrade=$(read_check_option upgrade) + count_test $upgrade backup_restore=$(read_check_option backup_restore) + count_test $backup_restore multi_instance=$(read_check_option multi_instance) + count_test $multi_instance incorrect_path=$(read_check_option incorrect_path) + count_test $incorrect_path port_already_use=$(read_check_option port_already_use) + count_test $port_already_use + # For port_already_use, check if there is also a port number if [ $port_already_use -eq 1 ] then @@ -695,401 +931,129 @@ then # Print the final results of the tests TEST_RESULTS - -if [ "$bash_mode" -ne 1 ]; then - read -p "Appuyer sur une touche pour démarrer le scénario de test suivant..." < /dev/tty -fi - done <<< "$(grep "^;; " "$check_process")" - +# No check_process file. Try to parse the manifest. else -# No check process... -fi + # Initialize the values for this serie of tests + initialize_values + manifest_extract="$script_dir/manifest_extract" -# dégradé - domain_arg="null" - path_arg="null" - user_arg="null" - public_arg="null" - public_public_arg="null" - public_private_arg="null" - port_arg="null" + # 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" - - - - - -# Cette fonctionne détermine le niveau final de l'application, en prenant en compte d'éventuels forçages -APP_LEVEL () { - level=0 # Initialise le niveau final à 0 - # Niveau 1: L'application ne s'installe pas ou ne fonctionne pas après installation. - if [ "${level[1]}" == "auto" ] || [ "${level[1]}" -eq 2 ]; then - if [ "$GLOBAL_CHECK_SETUP" -eq 1 ] && [ "$GLOBAL_CHECK_REMOVE" -eq 1 ] - then level[1]=2 ; else level[1]=0 ; fi - fi - - # Niveau 2: L'application s'installe et se désinstalle dans toutes les configurations communes. - if [ "${level[2]}" == "auto" ] || [ "${level[2]}" -eq 2 ]; then - if [ "$GLOBAL_CHECK_SUB_DIR" -ne -1 ] && \ - [ "$GLOBAL_CHECK_REMOVE_SUBDIR" -ne -1 ] && \ - [ "$GLOBAL_CHECK_ROOT" -ne -1 ] && \ - [ "$GLOBAL_CHECK_REMOVE_ROOT" -ne -1 ] && \ - [ "$GLOBAL_CHECK_PRIVATE" -ne -1 ] && \ - [ "$GLOBAL_CHECK_PUBLIC" -ne -1 ] && \ - [ "$GLOBAL_CHECK_MULTI_INSTANCE" -ne -1 ] - then level[2]=2 ; else level[2]=0 ; fi - fi - - # Niveau 3: L'application supporte l'upgrade depuis une ancienne version du package. - if [ "${level[3]}" == "auto" ] || [ "${level[3]}" == "2" ]; then - if [ "$GLOBAL_CHECK_UPGRADE" -eq 1 ] || ( [ "${level[3]}" == "2" ] && [ "$GLOBAL_CHECK_UPGRADE" -ne -1 ] ) - then level[3]=2 ; else level[3]=0 ; fi - fi - - # Niveau 4: L'application prend en charge de LDAP et/ou HTTP Auth. -- Doit être vérifié manuellement - - # Niveau 5: Aucune erreur dans package_linter. - if [ "${level[5]}" == "auto" ] || [ "${level[5]}" == "2" ]; then - if [ "$GLOBAL_LINTER" -eq 1 ] || ( [ "${level[5]}" == "2" ] && [ "$GLOBAL_LINTER" -ne -1 ] ) - then level[5]=2 ; else level[5]=0 ; fi - fi - - # Niveau 6: L'application peut-être sauvegardée et restaurée sans erreurs sur la même machine ou une autre. - if [ "${level[6]}" == "auto" ] || [ "${level[6]}" == "2" ]; then - if [ "$GLOBAL_CHECK_BACKUP" -eq 1 ] && [ "$GLOBAL_CHECK_RESTORE" -eq 1 ] || ( [ "${level[6]}" == "2" ] && [ "$GLOBAL_CHECK_BACKUP" -ne -1 ] && [ "$GLOBAL_CHECK_RESTORE" -ne -1 ] ) - then level[6]=2 ; else level[6]=0 ; fi - fi - - # Niveau 7: Aucune erreur dans package check. - if [ "${level[7]}" == "auto" ] || [ "${level[7]}" == "2" ]; then - if [ "$GLOBAL_CHECK_SETUP" -ne -1 ] && \ - [ "$GLOBAL_CHECK_REMOVE" -ne -1 ] && \ - [ "$GLOBAL_CHECK_SUB_DIR" -ne -1 ] && \ - [ "$GLOBAL_CHECK_REMOVE_SUBDIR" -ne -1 ] && \ - [ "$GLOBAL_CHECK_REMOVE_ROOT" -ne -1 ] && \ - [ "$GLOBAL_CHECK_UPGRADE" -ne -1 ] && \ - [ "$GLOBAL_CHECK_PRIVATE" -ne -1 ] && \ - [ "$GLOBAL_CHECK_PUBLIC" -ne -1 ] && \ - [ "$GLOBAL_CHECK_MULTI_INSTANCE" -ne -1 ] && \ - [ "$GLOBAL_CHECK_ADMIN" -ne -1 ] && \ - [ "$GLOBAL_CHECK_DOMAIN" -ne -1 ] && \ - [ "$GLOBAL_CHECK_PATH" -ne -1 ] && \ - [ "$GLOBAL_CHECK_PORT" -ne -1 ] && \ - [ "$GLOBAL_CHECK_BACKUP" -ne -1 ] && \ - [ "$GLOBAL_CHECK_RESTORE" -ne -1 ] && \ - [ "${level[5]}" -ge -1 ] # Si tout les tests sont validés. Et si le level 5 est validé ou forcé. - then level[7]=2 ; else level[7]=0 ; fi - fi - - # Niveau 8: L'application respecte toutes les YEP recommandées. -- Doit être vérifié manuellement - - # Niveau 9: L'application respecte toutes les YEP optionnelles. -- Doit être vérifié manuellement - - # Niveau 10: L'application est jugée parfaite. -- Doit être vérifié manuellement - - # Calcule le niveau final - for i in {1..10}; do - if [ "${level[i]}" == "auto" ]; then - level[i]=0 # Si des niveaux sont encore à auto, c'est une erreur de syntaxe dans le check_process, ils sont fixé à 0. - elif [ "${level[i]}" == "na" ]; then - continue # Si le niveau est "non applicable" (na), il est ignoré dans le niveau final - elif [ "${level[i]}" -ge 1 ]; then - level=$i # Si le niveau est validé, il est pris en compte dans le niveau final - else - break # Dans les autres cas (niveau ni validé, ni ignoré), la boucle est stoppée. Le niveau final est donc le niveau précédemment validé - fi - done -} - -TEST_RESULTS () { - APP_LEVEL - ECHO_FORMAT "\n\nPackage linter: " - if [ "$GLOBAL_LINTER" -eq 1 ]; then - ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_LINTER" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" - fi - ECHO_FORMAT "Installation: " - if [ "$GLOBAL_CHECK_SETUP" -eq 1 ]; then - ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_SETUP" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Suppression: " - if [ "$GLOBAL_CHECK_REMOVE" -eq 1 ]; then - ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_REMOVE" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Installation en sous-dossier: " - if [ "$GLOBAL_CHECK_SUB_DIR" -eq 1 ]; then - ECHO_FORMAT "\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_SUB_DIR" -eq -1 ]; then - ECHO_FORMAT "\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Suppression depuis sous-dossier: " - if [ "$GLOBAL_CHECK_REMOVE_SUBDIR" -eq 1 ]; then - ECHO_FORMAT "\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_REMOVE_SUBDIR" -eq -1 ]; then - ECHO_FORMAT "\tFAIL\n" "red" - else - ECHO_FORMAT "\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Installation à la racine: " - if [ "$GLOBAL_CHECK_ROOT" -eq 1 ]; then - ECHO_FORMAT "\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_ROOT" -eq -1 ]; then - ECHO_FORMAT "\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Suppression depuis racine: " - if [ "$GLOBAL_CHECK_REMOVE_ROOT" -eq 1 ]; then - ECHO_FORMAT "\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_REMOVE_ROOT" -eq -1 ]; then - ECHO_FORMAT "\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Upgrade: " - if [ "$GLOBAL_CHECK_UPGRADE" -eq 1 ]; then - ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_UPGRADE" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Installation privée: " - if [ "$GLOBAL_CHECK_PRIVATE" -eq 1 ]; then - ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_PRIVATE" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Installation publique: " - if [ "$GLOBAL_CHECK_PUBLIC" -eq 1 ]; then - ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_PUBLIC" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Installation multi-instance: " - if [ "$GLOBAL_CHECK_MULTI_INSTANCE" -eq 1 ]; then - ECHO_FORMAT "\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_MULTI_INSTANCE" -eq -1 ]; then - ECHO_FORMAT "\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Mauvais utilisateur: " - if [ "$GLOBAL_CHECK_ADMIN" -eq 1 ]; then - ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_ADMIN" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Erreur de domaine: " - if [ "$GLOBAL_CHECK_DOMAIN" -eq 1 ]; then - ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_DOMAIN" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Correction de path: " - if [ "$GLOBAL_CHECK_PATH" -eq 1 ]; then - ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_PATH" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Port déjà utilisé: " - if [ "$GLOBAL_CHECK_PORT" -eq 1 ]; then - ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_PORT" -eq -1 ]; then - ECHO_FORMAT "\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" - fi - -# ECHO_FORMAT "Source corrompue: " -# if [ "$GLOBAL_CHECK_CORRUPT" -eq 1 ]; then -# ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" -# elif [ "$GLOBAL_CHECK_CORRUPT" -eq -1 ]; then -# ECHO_FORMAT "\t\t\tFAIL\n" "red" -# else -# ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" -# fi - -# ECHO_FORMAT "Erreur de téléchargement de la source: " -# if [ "$GLOBAL_CHECK_DL" -eq 1 ]; then -# ECHO_FORMAT "\tSUCCESS\n" "lgreen" -# elif [ "$GLOBAL_CHECK_DL" -eq -1 ]; then -# ECHO_FORMAT "\tFAIL\n" "red" -# else -# ECHO_FORMAT "\tNot evaluated.\n" "white" -# fi - -# ECHO_FORMAT "Dossier déjà utilisé: " -# if [ "$GLOBAL_CHECK_FINALPATH" -eq 1 ]; then -# ECHO_FORMAT "\t\t\tSUCCESS\n" "lgreen" -# elif [ "$GLOBAL_CHECK_FINALPATH" -eq -1 ]; then -# ECHO_FORMAT "\t\t\tFAIL\n" "red" -# else -# ECHO_FORMAT "\t\t\tNot evaluated.\n" "white" -# fi - - ECHO_FORMAT "Backup: " - if [ "$GLOBAL_CHECK_BACKUP" -eq 1 ]; then - ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_BACKUP" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" - fi - - ECHO_FORMAT "Restore: " - if [ "$GLOBAL_CHECK_RESTORE" -eq 1 ]; then - ECHO_FORMAT "\t\t\t\tSUCCESS\n" "lgreen" - elif [ "$GLOBAL_CHECK_RESTORE" -eq -1 ]; then - ECHO_FORMAT "\t\t\t\tFAIL\n" "red" - else - ECHO_FORMAT "\t\t\t\tNot evaluated.\n" "white" - fi - ECHO_FORMAT "\t\t Notes de résultats: $note/$tnote - " "white" "bold" - if [ "$note" -gt 0 ] - then - note=$(( note * 20 / tnote )) - fi - if [ "$note" -le 5 ]; then - color_note="red" - typo_note="bold" - smiley=":'(" # La contribution à Shasha. Qui m'a forcé à ajouté les smiley sous la contrainte ;) - elif [ "$note" -le 10 ]; then - color_note="red" - typo_note="" - smiley=":(" - elif [ "$note" -le 15 ]; then - color_note="lyellow" - typo_note="" - smiley=":s" - elif [ "$note" -gt 15 ]; then - color_note="lgreen" - typo_note="" - smiley=":)" - fi - if [ "$note" -ge 20 ]; then - color_note="lgreen" - typo_note="bold" - smiley="\o/" - fi - ECHO_FORMAT "$note/20 $smiley\n" "$color_note" "$typo_note" - ECHO_FORMAT "\t Ensemble de tests effectués: $tnote/21\n\n" "white" "bold" - - # Affiche le niveau final - ECHO_FORMAT "Niveau de l'application: $level\n" "white" "bold" - for i in {1..10} - do - ECHO_FORMAT "\t Niveau $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 -} - - -else # Si le fichier check_process n'a pas été trouvé, fonctionne en mode dégradé. - python "$script_dir/sub_scripts/ci/maniackc.py" "$package_path/manifest.json" > "$script_dir/manifest_extract" # Extrait les infos du manifest avec le script de Bram + # 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 - wrong_user=1 - wrong_path=1 incorrect_path=1 + port_already_use=0 all_test=$((all_test+9)) - while read LIGNE + + + # Read each arguments and store them + while read line do - if echo "$LIGNE" | grep -q ":ynh.local"; then - domain_arg=$(echo "$LIGNE" | grep ":ynh.local" | cut -d ':' -f1) # Garde uniquement le nom de la clé. + # 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") + } + + # 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 - if echo "$LIGNE" | grep -q "path:"; then - path_arg=$(echo "$LIGNE" | grep "path:" | cut -d ':' -f1) # Garde uniquement le nom de la clé. - fi - if echo "$LIGNE" | grep -q "user:\|admin:"; then - user_arg=$(echo "$LIGNE" | grep "user:\|admin:" | cut -d ':' -f1) # Garde uniquement le nom de la clé. - fi - manifest_arguments="$manifest_arguments$(echo "$LIGNE" | cut -d ':' -f1,2 | sed s/:/=/)&" # Ajoute l'argument du manifest - done < "$script_dir/manifest_extract" - if [ "$domain_arg" == "null" ] + } + 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 - ECHO_FORMAT "La clé de manifest du domaine n'a pas été trouvée.\n" "lyellow" + 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 + } + + # 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 - setup_root=0 - multi_instance=0 - wrong_user=0 - incorrect_path=0 - all_test=$((all_test-5)) + 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 [ "$path_arg" == "null" ] + if [ -z "$path_arg" ] then - ECHO_FORMAT "La clé de manifest du path n'a pas été trouvée.\n" "lyellow" - setup_root=0 - multi_instance=0 - incorrect_path=0 - all_test=$((all_test-3)) + 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 [ "$user_arg" == "null" ] + if [ -z "$public_arg" ] then - ECHO_FORMAT "La clé de manifest de l'user admin n'a pas été trouvée.\n" "lyellow" - wrong_user=0 - all_test=$((all_test-1)) + 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 # Retire le test multi instance si la clé du manifest est à false - multi_instance=0 + then + count_test "$multi_instance" || multi_instance=0 fi + + # Launch all tests successively + TESTING_PROCESS + # Print the final results of the tests + TEST_RESULTS fi -TESTING_PROCESS -if [ "$no_lxc" -eq 0 ]; then - LXC_TURNOFF -fi -TEST_RESULTS + + + + + + + + + + + + + + + app_name=${arg_app%_ynh} # Supprime '_ynh' à la fin du nom de l'app # Mail et bot xmpp pour le niveau de l'app diff --git a/sub_scripts/ci/maniackc.py b/sub_scripts/ci/maniackc.py deleted file mode 100755 index 4145193..0000000 --- a/sub_scripts/ci/maniackc.py +++ /dev/null @@ -1,15 +0,0 @@ -# Merci a Bram pour ce code python. -# https://github.com/YunoHost/ci - -import sys -import json - -from default_args import argument_for_question - - -if __name__ == '__main__': - manifest_path = sys.argv[1:][0] - manifest = json.load(open(manifest_path, "r")) - - for question in manifest["arguments"]["install"]: - print ":".join(argument_for_question(question, all_choices=True)) diff --git a/sub_scripts/lxc_launcher.sh b/sub_scripts/launcher.sh similarity index 95% rename from sub_scripts/lxc_launcher.sh rename to sub_scripts/launcher.sh index 555a6c9..b106613 100755 --- a/sub_scripts/lxc_launcher.sh +++ b/sub_scripts/launcher.sh @@ -1,6 +1,6 @@ -#!/bin/bash +# #!/bin/bash -echo -e "Loads functions from lxc_launcher.sh" +echo -e "Loads functions from launcher.sh" #================================================= # Globals variables @@ -43,7 +43,7 @@ LXC_START () { echo "Start the LXC container" | tee --append "$test_result" sudo lxc-start --name=$lxc_name --daemon --logfile "$script_dir/lxc_boot.log" | tee --append "$test_result" 2>&1 else - echo "An LXC container is already running" | tee --append "$test_result" + echo "A LXC container is already running" | tee --append "$test_result" fi # Check during 20 seconds if the container has finished to start. @@ -68,7 +68,7 @@ LXC_START () { ECHO_FORMAT "Rebooting the container...\n" "red" "bold" fi LXC_STOP # Stop the LXC container - elif ! ssh $arg_ssh $lxc_name "ping -q -c 2 security.debian.org > /dev/null 2>&1; exit \$?" >> "$test_result" 2>&1 + elif ! ssh $arg_ssh $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" diff --git a/sub_scripts/ci/default_args.py b/sub_scripts/manifest_parsing.py similarity index 72% rename from sub_scripts/ci/default_args.py rename to sub_scripts/manifest_parsing.py index 173b775..d6982fe 100755 --- a/sub_scripts/ci/default_args.py +++ b/sub_scripts/manifest_parsing.py @@ -1,10 +1,8 @@ # Merci a Bram pour ce code python. # https://github.com/YunoHost/ci -import os +import sys import json -from urllib import urlretrieve - def argument_for_question(question, all_choices=False): question_type = question.get("type") @@ -51,23 +49,9 @@ def argument_for_question(question, all_choices=False): else: raise Exception("Unknow question type: %s\n" % question_type, question) -def default_arguments_for_app(app_data): - answers = [] - for question in app_data["manifest"]["arguments"]["install"]: - answers.append(argument_for_question(question)) - - return "&".join(["=".join([x[0], x[1]]) for x in answers]) - - -def main(): - if not os.path.exists("/tmp/yunohost_official_apps_list.json"): - urlretrieve("https://app.yunohost.org/official.json", "/tmp/yunohost_official_apps_list.json") - - app_list = json.load(open("/tmp/yunohost_official_apps_list.json")) - - for name, data in sorted(app_list.items(), key=lambda x: x[0]): - print "%s:" % name, default_arguments_for_app(data) - - if __name__ == '__main__': - main() + manifest_path = sys.argv[1:][0] + manifest = json.load(open(manifest_path, "r")) + + for question in manifest["arguments"]["install"]: + print ":".join(argument_for_question(question, all_choices=True)) diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index ed7f06b..51a4caf 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -621,7 +621,7 @@ CHECK_PUBLIC_PRIVATE () { CHECK_MULTI_INSTANCE () { # Try multi-instance installations - unit_test_title "Installation multi-instance..." + unit_test_title "Multi-instance installations..." # Check if the sub path install have previously work if [ $RESULT_check_sub_dir -ne 1 ] && [ $force_install_ok -ne 1 ] From e3fd48f2aca0b5d66a9a9948ebd2cc26df349b84 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis <maniack_crudelis@yahoo.fr> Date: Mon, 3 Apr 2017 20:50:31 +0200 Subject: [PATCH 07/10] [ref] XMPP and mail --- package_check.sh | 121 +++++++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 47 deletions(-) diff --git a/package_check.sh b/package_check.sh index 38c9943..854b6ac 100755 --- a/package_check.sh +++ b/package_check.sh @@ -110,7 +110,7 @@ else ;; esac else - other_args="$1" + app_arg="$1" fi shift done @@ -433,19 +433,19 @@ echo "Pick up the package which will be tested." # Remove the previous package if it's still here. rm -rf "$script_dir"/*_check -package_dir="$(basename "$other_args")_check" +package_dir="$(basename "$app_arg")_check" package_path="$script_dir/$package_dir" # If the package is in a git repository -if echo "$other_args" | grep -Eq "https?:\/\/" +if echo "$app_arg" | grep -Eq "https?:\/\/" then # Clone the repository - git clone $other_args $gitbranch "$package_path" + git clone $app_arg $gitbranch "$package_path" # If it's a local directory else # Do a copy in the directory of Package check - cp -a "$other_args" "$package_path" + cp -a "$app_arg" "$package_path" fi # Check if the package directory is really here. @@ -1039,68 +1039,95 @@ else TEST_RESULTS fi +echo "You can find the complete log of these tests in $complete_log" +#================================================= +# Inform of the results by XMPP and/or by mail +#================================================= +# Keep only the name of the app +app_name=${package_dir%_ynh_check} - - - - - - - - - - -app_name=${arg_app%_ynh} # Supprime '_ynh' à la fin du nom de l'app -# Mail et bot xmpp pour le niveau de l'app -if [ "$level" -eq 0 ]; then - message="L'application $(basename "$app_name") vient d'échouer aux tests d'intégration continue" -fi - -if [ $type_exec_env -eq 2 ] +# If the app completely failed and obtained 0 +if [ $global_level -eq 0 ] then - # Récupère le nom du job dans le CI - id=$(cat "$script_dir/../CI.lock") # Récupère l'id du job en cours - job=$(grep "$id" "$script_dir/../work_list" | cut -d ';' -f 3) # Et récupère le nom du job dans le work_list - job=${job// /%20} # Replace all space by %20 + message="Application $app_name has completely failed to continuous integration tests" + +# If the app has obtained another level than 0. +# And if package check it's in the official CI environment +# Check the level variation +elif [ $type_exec_env -eq 2 ] + + # Get the job name, stored in the work_list + job=$(head -n1 "$script_dir/../work_list" | cut -d ';' -f 3) + + # Build the log path (and replace all space by %20 in the job name) if [ -n "$job" ]; then - job_log="/job/$job/lastBuild/console" + job_log="/job/${job// /%20}/lastBuild/console" fi - # Prend le niveau précédemment calculé - previous_level=$(grep "$(basename "$app_name")" "$script_dir/../auto_build/list_level_stable" | cut -d: -f2) - if [ "$level" -ne 0 ] + + # 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="L'application $(basename "$app_name")" + message="Application $app_name" + # If non previous level was found if [ -z "$previous_level" ]; then - message="$message vient d'atteindre le niveau $level" + message="$message just reach the level $level" + # If the level stays the same elif [ $level -eq $previous_level ]; then - message="$message reste au niveau $level" + message="$message stays at level $level" + # If the level go up elif [ $level -gt $previous_level ]; then - message="$message monte du niveau $previous_level au niveau $level" + message="$message rise from level $previous_level to level $level" + # If the level go down elif [ $level -lt $previous_level ]; then - message="$message descend du niveau $previous_level au niveau $level" + message="$message go down from level $previous_level to level $level" fi fi +fi + +# If the test was perform in the official CI environment +# Add the log address +# And inform with xmpp +if [ $type_exec_env -eq 2 ] + + # Build the address of the server from auto.conf ci_path=$(grep "main_domain=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2)/$(grep "CI_PATH=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2) - message="$message sur https://$ci_path$job_log" - if ! echo "$job" | grep -q "(testing)\|(unstable)"; then # Notifie par xmpp seulement sur stable - "$script_dir/../auto_build/xmpp_bot/xmpp_post.sh" "$message" # Notifie sur le salon apps + + # 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 ! echo "$job" | grep -q "(testing)\|(unstable)" + then + "$script_dir/../auto_build/xmpp_bot/xmpp_post.sh" "$message" > /dev/null 2>&1 fi fi -if [ "$level" -eq 0 ] && [ $type_exec_env -eq 1 ] -then # Si l'app est au niveau 0, et que le test tourne en CI, envoi un mail d'avertissement. - dest=$(cat "$package_path/manifest.json" | grep '\"email\": ' | cut -d '"' -f 4) # Utilise l'adresse du mainteneur de l'application - ci_path=$(grep "CI_URL=" "$script_dir/../config" | cut -d= -f2) - if [ -n "$ci_path" ]; then - message="$message sur $ci_path" +# Send a mail to main maintainer if the app failed and obtained the level 0. +# Only if package check is in a CI environment (Official or not) +if [ $global_level -eq 0 ] && [ $type_exec_env -ge 1 ] +then + + # Get the maintainer email from the manifest + dest=$(grep '\"email\": ' "$package_path/manifest.json" | cut -d '"' -f 4) + + # Send the message by mail, if a address has been find + if [ -n "$dest" ]; then + mail -s "[YunoHost] Your app $app_name has completely failed to continuous integration tests" "$dest" <<< "$message" fi - mail -s "[YunoHost] Échec d'installation d'une application dans le CI" "$dest" <<< "$message" # Envoi un avertissement par mail. fi -echo "Le log complet des installations et suppressions est disponible dans le fichier $complete_log" -# Clean +#================================================= +# Clean and exit +#================================================= + +clean_exit 0 From 23bef139d34935905835c03e6432b19713da740c Mon Sep 17 00:00:00 2001 From: Maniack Crudelis <maniack_crudelis@yahoo.fr> Date: Tue, 4 Apr 2017 11:39:43 +0200 Subject: [PATCH 08/10] Fix arguments parsing --- package_check.sh | 102 +++++++++++++++++++++------------------- sub_scripts/launcher.sh | 12 ++--- 2 files changed, 60 insertions(+), 54 deletions(-) diff --git a/package_check.sh b/package_check.sh index 854b6ac..a278db1 100755 --- a/package_check.sh +++ b/package_check.sh @@ -15,7 +15,7 @@ if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$( clean_exit () { # Exit and remove all temp files # $1 = exit code - + # Deactivate LXC network LXC_TURNOFF @@ -67,53 +67,59 @@ else arguments=${arguments//--bash-mode/-y} # Read and parse all the arguments - while [ $# -ne 0 ] - do - # Initialize the index of getopts - OPTIND=1 - # Parse with getopts only if the argument begin by - - if [ ${1:0:1} = "-" ] - then - getopts ":b:fihly " parameter - case $parameter in - b) - # --branch=branch-name - gitbranch="$OPTARG" - ;; - f) - # --force-install-ok - force_install_ok=1 - ;; - i) - # --interrupt - interrupt=1 - ;; - h) - # --help - notice=1 - ;; - l) - # --build-lxc - build_lxc=1 - ;; - y) - # --bash-mode - bash_mode=1 - ;; - \?) - echo "Invalid argument: -$OPTARG" >&2 - notice=1 - ;; - :) - echo "-$OPTARG parameter requires an argument." >&2 - notice=1 - ;; - esac - else - app_arg="$1" - fi - shift - done + # Use a function here, to use standart arguments $@ and use more simply getopts and shift. + parse_arg () { + while [ $# -ne 0 ] + do + # Initialize the index of getopts + OPTIND=1 + # Parse with getopts only if the argument begin by - + if [ ${1:0:1} = "-" ] + then + getopts ":b:fihly " parameter + case $parameter in + b) + # --branch=branch-name + gitbranch="$OPTARG" + ;; + f) + # --force-install-ok + force_install_ok=1 + ;; + i) + # --interrupt + interrupt=1 + ;; + h) + # --help + notice=1 + ;; + l) + # --build-lxc + build_lxc=1 + ;; + y) + # --bash-mode + bash_mode=1 + ;; + \?) + echo "Invalid argument: -$OPTARG" >&2 + notice=1 + ;; + :) + echo "-$OPTARG parameter requires an argument." >&2 + notice=1 + ;; + esac + else + app_arg="$1" + fi + shift + done + } + + # Call parse_arg and pass the modified list of args. + parse_arg $arguments fi # Prevent a conflict between --interrupt and --bash-mode diff --git a/sub_scripts/launcher.sh b/sub_scripts/launcher.sh index b106613..17ac702 100755 --- a/sub_scripts/launcher.sh +++ b/sub_scripts/launcher.sh @@ -82,7 +82,7 @@ LXC_START () { break fi - # Failed if the container failed to start + # Fail if the container failed to start if [ $i -eq $max_try ] && [ $failstart -eq 1 ] then ECHO_FORMAT "The container failed to start $max_try times...\nIf this problem is persistent, try to fix it with lxc_check.sh." "red" "bold" @@ -92,7 +92,7 @@ LXC_START () { fi done - # Count the number of line of the current yunohost log file. + # Count the number of lines of the current yunohost log file. COPY_LOG 1 # Copy the package into the container. @@ -142,9 +142,9 @@ LXC_STOP () { } LXC_TURNOFF () { - # Deactivate LXC network + # Disable LXC network - echo "Deactivate iptables rules." + 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 @@ -158,7 +158,7 @@ LXC_TURNOFF () { sudo iptables --table nat --delete POSTROUTING --source $ip_range.0/24 --jump MASQUERADE | tee --append "$test_result" 2>&1 fi - echo "Deactivate the network bridge." + 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 @@ -168,7 +168,7 @@ LXC_TURNOFF () { LXC_CONNECT_INFO () { # Print access information - echo "> For access the container:" + echo "> To access the container:" echo "To execute one command:" echo -e "\e[1msudo lxc-attach -n $lxc_name -- command\e[0m" From 914516640eb96e20a791edf661fb2a8d12675e9e Mon Sep 17 00:00:00 2001 From: Maniack Crudelis <maniack_crudelis@yahoo.fr> Date: Wed, 5 Apr 2017 19:44:03 +0200 Subject: [PATCH 09/10] Corrections --- package_check.sh | 48 ++++++++++++++++++---------------- sub_scripts/testing_process.sh | 4 +-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/package_check.sh b/package_check.sh index a278db1..9945e63 100755 --- a/package_check.sh +++ b/package_check.sh @@ -44,7 +44,7 @@ clean_exit () { echo "" # Init arguments value -gitbranch=0 +gitbranch="" force_install_ok=0 interrupt=0 notice=0 @@ -525,6 +525,18 @@ TEST_RESULTS () { # auto -> This level has not a value yet. # na -> This level will not 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]=0 + 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 @@ -666,9 +678,9 @@ TEST_RESULTS () { for i in `seq 1 10` do ECHO_FORMAT "\t Level $i: " - if [ "${level[i]}" == "na" ]; then + if [ "${level[$i]}" == "na" ]; then ECHO_FORMAT "N/A\n" - elif [ "${level[i]}" -ge 1 ]; then + elif [ "${level[$i]}" -ge 1 ]; then ECHO_FORMAT "1\n" "white" "bold" else ECHO_FORMAT "0\n" @@ -696,18 +708,6 @@ fi # Initialize tests #================================================= -# Default values for level -level[1]=auto -level[2]=auto -level[3]=auto -level[4]=0 -level[5]=auto -level[6]=auto -level[7]=auto -level[8]=0 -level[9]=0 -level[10]=0 - # Purge some log files > "$complete_log" > "$test_result" @@ -1066,6 +1066,7 @@ then # And if package check it's in the official CI environment # Check the level variation elif [ $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) @@ -1084,16 +1085,16 @@ elif [ $type_exec_env -eq 2 ] message="Application $app_name" # If non previous level was found if [ -z "$previous_level" ]; then - message="$message just reach the level $level" + message="$message just reach the level $global_level" # If the level stays the same - elif [ $level -eq $previous_level ]; then - message="$message stays at level $level" + elif [ $global_level -eq $previous_level ]; then + message="$message stays at level $global_level" # If the level go up - elif [ $level -gt $previous_level ]; then - message="$message rise from level $previous_level to level $level" + elif [ $global_level -gt $previous_level ]; then + message="$message rise from level $previous_level to level $global_level" # If the level go down - elif [ $level -lt $previous_level ]; then - message="$message go down from level $previous_level to level $level" + elif [ $global_level -lt $previous_level ]; then + message="$message go down from level $previous_level to level $global_level" fi fi fi @@ -1102,9 +1103,10 @@ fi # Add the log address # And inform with xmpp if [ $type_exec_env -eq 2 ] +then # Build the address of the server from auto.conf - ci_path=$(grep "main_domain=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2)/$(grep "CI_PATH=" "$script_dir/../auto_build/auto.conf" | cut -d= -f2) + 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" diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index 51a4caf..1ba9f3d 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -275,8 +275,6 @@ replace_manifest_key () { if [ -n "$manifest_key" ] then manifest_args_mod=$(echo $manifest_args_mod | sed "s@$manifest_key=[^&]*\&@${manifest_key}=${2}\&@") - else - ECHO_FORMAT "The manifest key $manifest_key doesn't found in the check_process\n" "red" clog fi } @@ -1044,7 +1042,7 @@ TEST_LAUNCHER () { TESTING_PROCESS () { # Launch all tests successively - ECHO_FORMAT "\nTests serie: $tests_serie\n" "white" "underlined" clog + ECHO_FORMAT "\nTests serie: ${tests_serie#;; }\n" "white" "underlined" clog # Init the value for the current test cur_test=1 From 3db48f2e9bfbf154ef5f845c24961edbe8a80903 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis <maniack_crudelis@yahoo.fr> Date: Wed, 5 Apr 2017 19:59:37 +0200 Subject: [PATCH 10/10] Split and upgrade readme --- README-fr.md | 155 +++++++++++++++++++++++++++++++++++++ README.md | 207 ++++---------------------------------------------- check_process | 2 +- 3 files changed, 171 insertions(+), 193 deletions(-) create mode 100644 README-fr.md diff --git a/README-fr.md b/README-fr.md new file mode 100644 index 0000000..93addf1 --- /dev/null +++ b/README-fr.md @@ -0,0 +1,155 @@ +Package checker for YunoHost +================== + +[Yunohost project](https://yunohost.org/#/) + +> [Read this readme in english](README.md) + +Ensemble de tests unitaires pour vérifier les packages Yunohost. +Le script `package_check.sh` effectue une succession de test sur un package afin de vérifier sa capacité à s'installer et se désinstaller dans différents cas. +Le résultats des tests est affiché directement et stocké dans le fichier Test_results.log + +Le script est capable d'effectuer les tests suivant: +- Vérification du package avec [package linter](https://github.com/YunoHost/package_linter) +- Installation en sous-dossier +- Installation à la racine du domaine +- Installation sans accès par url (Pour les applications n'ayant pas d'interface web) +- Installation en privé +- Installation en public +- Upgrade sur la même version du package +- Backup +- Restore après suppression de l'application +- Restore sans installation préalable +- Installation multi-instance +- Test de path mal formé (path/ au lieu de /path) +- Test de port déjà utilisé + +Package check utilise un conteneur LXC pour créer un environnement de test propre sans résidus d'installations précédentes. + +Usage: +Pour une app dans un dossier: `./package_check.sh APP_ynh` +Pour une app sur github: `./package_check.sh https://github.com/USER/APP_ynh` + +Il est nécessaire de fournir, à la racine du package de l'app à tester, un fichier `check_process` pour indiquer au script les arguments attendu et les tests à effectuer. +Si ce fichier n'est pas présent, package_check sera utilisé en mode dégradé. Il va tenter de repérer les arguments domain, path et admin dans le manifest pour exécuter un nombre restreint de test, en fonction des arguments trouvés. + +--- +## Déploiement du script de test + +``` +git clone https://github.com/YunoHost/package_check +package_check/sub_scripts/lxc_build.sh +package_check/package_check.sh APP_ynh +``` + +--- +## Syntaxe du fichier `check_process` +> A l'exception des espaces, la syntaxe du fichier doit être scrupuleusement respectée. + +``` +;; Nom du test +# Commentaire ignoré + ; Manifest + domain="$DOMAIN" (DOMAIN) + path="$PATH" (PATH) + admin="$USER" (USER) + language="fr" + is_public=1 (PUBLIC|public=1|private=0) + password="$PASSWORD" (PASSWORD) + port="666" (PORT) + ; Checks + pkg_linter=1 + setup_sub_dir=1 + setup_root=1 + setup_nourl=0 + setup_private=1 + setup_public=1 + upgrade=1 + backup_restore=1 + multi_instance=1 + incorrect_path=1 + port_already_use=1 (XXXX) +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto + Level 4=0 + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 +``` +### `;; Nom du test` +Nom du scénario de test qui sera effectué. +On peut créer autant de scénario de test que voulu, tous ayant la même syntaxe. +Les différents scénarios de test seront exécutés successivement. + +### `; Manifest` +Ensemble des clés du manifest. +Toutes les clés du manifest doivent être renseignée afin de procéder à l'installation. +> Les clés de manifest données ici ne le sont qu'à titre d'exemple. Voir le manifest de l'application. +Certaines clés de manifest sont indispensables au script pour effectuer certains test. Ces clés doivent être mises en évidence afin que le script soit capable de les retrouver et de changer leur valeur. +`(DOMAIN)`, `(PATH)`, `(USER)` et `(PORT)` doivent être mis en bout de ligne des clés correspondantes. Ces clés seront modifiées par le script. +`(PUBLIC|public=1|private=0)` doit, en plus de correspondre à la clé de visibilité public, indiquer les valeurs du manifest pour public et privé. + +### `; Checks` +Ensemble des tests à effectuer. +Chaque test marqué à 1 sera effectué par le script. +Si un test est absent de la liste, il sera ignoré. Cela revient à le noter à 0. +- `pkg_linter`: Vérification du package avec [package linter](https://github.com/YunoHost/package_linter) +- `setup_sub_dir`: Installation dans le path /check. +- `setup_root`: Installation à la racine du domaine. +- `setup_nourl`: Installation sans accès http. Ce test ne devrait être choisi que pour les applications ne disposant pas d'une interface web. +- `setup_private`: Installation en privé. +- `setup_public`: Installation en public. +- `upgrade`: Upgrade du package sur la même version. Test uniquement le script upgrade. +- `backup_restore`: Backup et restauration. +- `multi_instance`: Installation de l'application 3 fois de suite, pour vérifier sa capacité à être multi-instance. Les 2e et 3e installations se font respectivement en ajoutant un suffixe et un préfixe au path. +- `incorrect_path`: Provoque une erreur avec un path malformé, path/. +- `port_already_use`: Provoque une erreur sur le port en l'ouvrant avant le script d'install. + Le test` port_already_use` peut éventuellement prendre en argument un numéro de port. Si celui-ci n'est pas dans le manifest. + Le numéro de port doit alors être noté entre parenthèse, il servira au test de port. + +### `;;; Levels` +Permet de choisir comment [chaque niveau](https://yunohost.org/#/packaging_apps_levels_fr) est déterminé. +Chaque niveau fixé à *auto* sera déterminé par le script. Il est également possible de fixer le niveau à *1* ou à *0* pour respectivement le valider ou l'invalider. +Il est à noter que les niveaux 4, 8, 9 et 10 ne peuvent être fixés à *auto* car ils ne peuvent être testés par le script et nécessitent une vérification manuelle. Il est toutefois possible de les fixer à *na* pour indiquer que le niveau n'est pas applicable (par exemple pour le niveau 4 quand une app ne propose pas de SSO LDAP). Un niveau *na* sera tout simplement ignoré dans le calcul du niveau final. + +- Niveau 1 : L'application s'installe et se désinstalle correctement. -- Peut être vérifié par package_check +- Niveau 2 : L'application s'installe et se désinstalle dans toutes les configurations communes. -- Peut être vérifié par package_check +- Niveau 3 : L'application supporte l'upgrade depuis une ancienne version du package. -- Peut être vérifié par package_check +- Niveau 4 : L'application prend en charge de LDAP et/ou HTTP Auth. -- Doit être vérifié manuellement +- Niveau 5 : Aucune erreur dans package_linter. -- Peut être vérifié par package_check +- Niveau 6 : L'application peut-être sauvegardée et restaurée sans erreurs sur la même machine ou une autre. -- Peut être vérifié par package_check +- Niveau 7 : Aucune erreur dans package check. -- Peut être vérifié par package_check +- Niveau 8 : L'application respecte toutes les YEP recommandées. -- Doit être vérifié manuellement +- Niveau 9 : L'application respecte toutes les YEP optionnelles. -- Doit être vérifié manuellement +- Niveau 10 : L'application est jugée parfaite. -- Doit être vérifié manuellement + +--- +Le script `package_check.sh` accepte 6 arguments en plus du package à tester. +- `--bash-mode`: Rend le script autonome. Aucune intervention de l'utilisateur ne sera nécessaire. + La valeur de auto_remove est ignorée. +- `--branch=nom-de-branche`: Teste une branche du dépôt plutôt que de tester master. Permet de tester les pull request. +- `--build-lxc`: Installe LXC et créer le conteneur debian Yunohost si nécessaire. +- `--force-install-ok`: Force la réussite des installations, même si elles échouent. Permet d'effectuer les tests qui suivent même si l'installation a échouée. +- `--interrupt`: Force l'option auto_remove à 0, le script marquera une pause avant chaque suppression d'application. +- `--help`: Affiche l'aide du script + +--- +## LXC + +Package check utilise la virtualisation en conteneur pour assurer l'intégrité de l'environnement de test. +L'usage de LXC apporte une meilleure stabilité au processus de test, un test de suppression échoué n'entraine pas l'échec des tests suivant, et permet de garder un environnement de test sans résidus de test précédents. En revanche, l'usage de LXC augmente la durée des tests, en raison des manipulations du conteneur et de la réinstallation systématique des dépendances de l'application. + +Il faut prévoir également un espace suffisant sur l'hôte, au minimum 4Go pour le conteneur, son snapshot et sa copie de sauvegarde. + +L'usage de LXC est facilité par 4 scripts, permettant de gérer la création, la mise à jour, la suppression et la réparation du conteneur. +- `lxc_build.sh`: lxc_build installe LXC et ses dépendances, puis créer le conteneur debian. + Il ajoute ensuite le support réseau, installe Yunohost et le configure. Et enfin configure un accès ssh. + L'accès ssh par défaut est `ssh -t pchecker_lxc` +- `lxc_upgrade.sh`: Effectue la mise à jour du conteneur à l'aide d'apt-get et recréer le snapshot. +- `lxc_remove.sh`: Supprime le conteneur LXC, son snapshot et sa sauvegarde. Désinstalle LXC et déconfigure le réseau associé. +- `lxc_check.sh`: Vérifie le conteneur LXC et tente de le réparer si nécessaire. diff --git a/README.md b/README.md index 9f1e982..4223d2d 100644 --- a/README.md +++ b/README.md @@ -3,176 +3,7 @@ Package checker for YunoHost [Yunohost project](https://yunohost.org/#/) -Ensemble de tests unitaires pour vérifier les packages Yunohost. -Le script `package_check.sh` effectue une succession de test sur un package afin de vérifier sa capacité à s'installer et se désinstaller dans différents cas. -Le résultats des tests est affiché directement et stocké dans le fichier Test_results.log - -Le script est capable d'effectuer les tests suivant: -- Vérification du package avec [package linter](https://github.com/YunoHost/package_linter) -- Installation en sous-dossier -- Installation à la racine du domaine -- Installation sans accès par url (Pour les applications n'ayant pas d'interface web) -- Installation en privé -- Installation en public -- Upgrade sur la même version du package -- Backup -- Restore après suppression de l'application -- Restore sans installation préalable -- Installation multi-instance -- Test d'utilisateur incorrect -- Test de domaine incorrect -- Test de path mal formé (path/ au lieu de /path) -- Test de port déjà utilisé - -Par défaut, Package check utilise un conteneur LXC pour créer un environnement de test propre sans résidus d'installations précédentes. Ce comportement peut être contourné avec le paramètre --no-lxc -> ATTENTION: Si LXC n'est pas utilisé, le script devrait être utilisé uniquement dans un environnement de test dédié, jamais sur un serveur en production. Il va provoquer de nombreuses erreurs d'installation du package et pourrait donc laisser des résidus indésirables. - -Usage: -Pour une app dans un dossier: `./package_check.sh APP_ynh` -Pour une app sur github: `./package_check.sh https://github.com/USER/APP_ynh` - -Il est nécessaire de fournir, à la racine du package de l'app à tester, un fichier `check_process` pour indiquer au script les arguments attendu et les tests à effectuer. -Si ce fichier n'est pas présent, package_check sera utilisé en mode dégradé. Il va tenter de repérer les arguments domain, path et admin dans le manifest pour exécuter un nombre restreint de test, en fonction des arguments trouvés. - ---- -## Déploiement du script de test - -``` -git clone https://github.com/YunoHost/package_check -package_check/sub_scripts/lxc_build.sh -package_check/package_check.sh APP_ynh -``` - ---- -## Syntaxe du fichier `check_process` -> A l'exception des espaces, la syntaxe du fichier doit être scrupuleusement respectée. - -``` -;; Nom du test - auto_remove=1 -# Commentaire ignoré - ; Manifest - domain="$DOMAIN" (DOMAIN) - path="$PATH" (PATH) - admin="$USER" (USER) - language="fr" - is_public=1 (PUBLIC|public=1|private=0) - password="$PASSWORD" (PASSWORD) - port="666" (PORT) - ; Checks - pkg_linter=1 - setup_sub_dir=1 - setup_root=1 - setup_nourl=0 - setup_private=1 - setup_public=1 - upgrade=1 - backup_restore=1 - multi_instance=1 - wrong_user=1 - wrong_path=1 - incorrect_path=1 - corrupt_source=0 - fail_download_source=0 - port_already_use=1 (XXXX) - final_path_already_use=0 -;;; Levels - Level 1=auto - Level 2=auto - Level 3=auto - Level 4=0 - Level 5=auto - Level 6=auto - Level 7=auto - Level 8=0 - Level 9=0 - Level 10=0 -``` -### `;; Nom du test` -Nom du scénario de test qui sera effectué. -On peut créer autant de scénario de test que voulu, tous ayant la même syntaxe. -Les différents scénarios de test seront exécutés successivement. - -### `auto_remove` -Si `auto_remove` est à 0, le script marque une pause avant chaque suppression de l'app. Afin d'éffectuer des vérifications manuelles si nécessaire. -Sinon, l'app est supprimée automatiquement et les tests continuent. - -### `; Manifest` -Ensemble des clés du manifest. -Toutes les clés du manifest doivent être renseignée afin de procéder à l'installation. -> Les clés de manifest données ici ne le sont qu'à titre d'exemple. Voir le manifest de l'application. -Certaines clés de manifest sont indispensables au script pour effectuer certains test. Ces clés doivent être mises en évidence afin que le script soit capable de les retrouver et de changer leur valeur. -`(DOMAIN)`, `(PATH)`, `(USER)`, `(PASSWORD)` et `(PORT)` doivent être mis en bout de ligne des clés correspondantes. Ces clés seront modifiées par le script. -`(PUBLIC|public=1|private=0)` doit, en plus de correspondre à la clé de visibilité public, indiquer les valeurs du manifest pour public et privé. - -### `; Checks` -Ensemble des tests à effectuer. -Chaque test marqué à 1 sera effectué par le script. -Si un test est absent de la liste, il sera ignoré. Cela revient à le noter à 0. -- `pkg_linter`: Vérification du package avec [package linter](https://github.com/YunoHost/package_linter) -- `setup_sub_dir`: Installation dans le path /check. -- `setup_root`: Installation à la racine du domaine. -- `setup_nourl`: Installation sans accès http. Ce test ne devrait être choisi que pour les applications ne disposant pas d'une interface web. -- `setup_private`: Installation en privé. -- `setup_public`: Installation en public. -- `upgrade`: Upgrade du package sur la même version. Test uniquement le script upgrade. -- `backup_restore`: Backup et restauration. -- `multi_instance`: Installation de l'application 3 fois de suite, pour vérifier sa capacité à être multi-instance. Les 2e et 3e installations se font respectivement en ajoutant un suffixe et un préfixe au path. -- `wrong_user`: Provoque une erreur avec un nom d'utilisateur incorrect. -- `wrong_path`: Provoque une erreur avec un domain incorrect. -- `incorrect_path`: Provoque une erreur avec un path malformé, path/. -- `corrupt_source`: *Non implémenté pour le moment...* -- `fail_download_source`: *Non implémenté pour le moment...* -- `port_already_use`: Provoque une erreur sur le port en l'ouvrant avant le script d'install. - Le test` port_already_use` peut éventuellement prendre en argument un numéro de port. Si celui-ci n'est pas dans le manifest. - Le numéro de port doit alors être noté entre parenthèse, il servira au test de port. -- `final_path_already_use`: *Non implémenté pour le moment...* - -### `;;; Levels` -Permet de choisir comment [chaque niveau](https://yunohost.org/#/packaging_apps_levels_fr) est déterminé. -Chaque niveau fixé à *auto* sera déterminé par le script. Il est également possible de fixer le niveau à *1* ou à *0* pour respectivement le valider ou l'invalider. -Il est à noter que les niveaux 4, 8, 9 et 10 ne peuvent être fixés à *auto* car ils ne peuvent être testés par le script et nécessitent une vérification manuelle. Il est toutefois possible de les fixer à *na* pour indiquer que le niveau n'est pas applicable (par exemple pour le niveau 4 quand une app ne propose pas de SSO LDAP). Un niveau *na* sera tout simplement ignoré dans le calcul du niveau final. -- Niveau 1 : L'application s'installe et se désinstalle correctement. -- Peut être vérifié par package_check -- Niveau 2 : L'application s'installe et se désinstalle dans toutes les configurations communes. -- Peut être vérifié par package_check -- Niveau 3 : L'application supporte l'upgrade depuis une ancienne version du package. -- Peut être vérifié par package_check -- Niveau 4 : L'application prend en charge de LDAP et/ou HTTP Auth. -- Doit être vérifié manuellement -- Niveau 5 : Aucune erreur dans package_linter. -- Peut être vérifié par package_check -- Niveau 6 : L'application peut-être sauvegardée et restaurée sans erreurs sur la même machine ou une autre. -- Peut être vérifié par package_check -- Niveau 7 : Aucune erreur dans package check. -- Peut être vérifié par package_check -- Niveau 8 : L'application respecte toutes les YEP recommandées. -- Doit être vérifié manuellement -- Niveau 9 : L'application respecte toutes les YEP optionnelles. -- Doit être vérifié manuellement -- Niveau 10 : L'application est jugée parfaite. -- Doit être vérifié manuellement - ---- -Le script `package_check.sh` accepte 6 arguments en plus du package à tester. -- `--bash-mode`: Rend le script autonome. Aucune intervention de l'utilisateur ne sera nécessaire. - La valeur de auto_remove est ignorée. -- `--branch=nom-de-branche`: Teste une branche du dépôt plutôt que de tester master. Permet de tester les pull request. -- `--build-lxc`: Installe LXC et créer le conteneur debian Yunohost si nécessaire. -- `--force-install-ok`: Force la réussite des installations, même si elles échouent. Permet d'effectuer les tests qui suivent même si l'installation a échouée. -- `--interrupt`: Force l'option auto_remove à 0, le script marquera une pause avant chaque suppression d'application. -- `--no-lxc`: N'utilise pas la virtualisation en conteneur LXC. Les tests seront effectué directement sur la machine hôte. -- `--help`: Affiche l'aide du script - ---- -## LXC - -Package check utilise la virtualisation en conteneur pour assurer l'intégrité de l'environnement de test. -L'usage de LXC apporte une meilleure stabilité au processus de test, un test de suppression échoué n'entraine pas l'échec des tests suivant, et permet de garder un environnement de test sans résidus de test précédents. En revanche, l'usage de LXC augmente la durée des tests, en raison des manipulations du conteneur et de la réinstallation systématique des dépendances de l'application. - -Il faut prévoir également un espace suffisant sur l'hôte, au minimum 4Go pour le conteneur, son snapshot et sa copie de sauvegarde. - -L'usage de LXC est facilité par 4 scripts, permettant de gérer la création, la mise à jour, la suppression et la réparation du conteneur. -- `lxc_build.sh`: lxc_build installe LXC et ses dépendances, puis créer le conteneur debian. - Il ajoute ensuite le support réseau, installe Yunohost et le configure. Et enfin configure un accès ssh. - L'accès ssh par défaut est `ssh -t pchecker_lxc` -- `lxc_upgrade.sh`: Effectue la mise à jour du conteneur à l'aide d'apt-get et recréer le snapshot. -- `lxc_remove.sh`: Supprime le conteneur LXC, son snapshot et sa sauvegarde. Désinstalle LXC et déconfigure le réseau associé. -- `lxc_check.sh`: Vérifie le conteneur LXC et tente de le réparer si nécessaire. - ---- ---- -## Package checker for YunoHost +> [Lire ce readme en francais](README-fr.md) Set of unit tests for check Yunohost packages. The `package_check.sh` script perform a series of tests on a package for check its capability to install and remove in différents cases. @@ -190,13 +21,10 @@ The script is able to perform following tests: - Restore after application uninstall - Restore without installation before - Multi-instances installation -- Test with wrong user -- Test with wrong domain - Test malformed path (path/ instead od /path) - Test port already use -As default, package_check script use an LXC container to manipulate the package in a non parasited environnement by previous installs. This behavior can be overriden with --no-lxc parameter. -> BE CAREFUL, If LXC is not used, this script should be used only in a dedicated test environnement, never on a prod server. It will causes many installations errors and risk to leave residues. +Package_check script use an LXC container to manipulate the package in a non parasited environnement by previous installs. Usage: For an app in a dir: `./package_check.sh APP_ynh` @@ -220,8 +48,7 @@ package_check/package_check.sh APP_ynh ``` ;; Test name - auto_remove=1 -# Comment ignore +# Comment ignored ; Manifest domain="$DOMAIN" (DOMAIN) path="$PATH" (PATH) @@ -240,29 +67,31 @@ package_check/package_check.sh APP_ynh upgrade=1 backup_restore=1 multi_instance=1 - wrong_user=1 - wrong_path=1 incorrect_path=1 - corrupt_source=0 - fail_download_source=0 port_already_use=1 (XXXX) - final_path_already_use=0 +;;; Levels + Level 1=auto + Level 2=auto + Level 3=auto + Level 4=0 + Level 5=auto + Level 6=auto + Level 7=auto + Level 8=0 + Level 9=0 + Level 10=0 ``` ### `;; Test name` Name of tests series that will be perform. It's possible to create multiples tests series, all with the same syntax. All different tests series will be perform sequentialy. -### `auto_remove` -If `auto_remove` is at 0, the script pause before each deleting of app. To lets you check manually if necessary. -Otherwise, the app is automaticaly removed and tests continue. - ### `; Manifest` Set of manifest keys. All manifest keys need to be filled to perform installation. > The manifest keys filled here are simply an exemple. Check the app's manifest. Some manifest keys are necessary for the script to performs some tests. This keys must be highlighted for the script is able to find them and modify their values. -`(DOMAIN)`, `(PATH)`, `(USER)`, `(PASSWORD)` and `(PORT)` must be placed at the end of corresponding key. This key will be changed by the script. +`(DOMAIN)`, `(PATH)`, `(USER)` and `(PORT)` must be placed at the end of corresponding key. This key will be changed by the script. `(PUBLIC|public=1|private=0)` must, in addition to match the public key, indicate the values for public and private. ### `; Checks` @@ -278,15 +107,10 @@ If a test is not in the list, it will be ignored. It's similar to marked at 0. - `upgrade`: Upgrade package on same version. Only test the upgrade script. - `backup_restore`: Backup then restore. - `multi_instance`: Installing the application 3 times to verify its ability to be multi-instance. The 2nd and 3rd respectively installs are adding a suffix then prefix path. -- `wrong_user`: Causes an errror with a wrong user name. -- `wrong_path`: Causes an error with a wrong domain. - `incorrect_path`: Causes an arror with a malformed path, path/. -- `corrupt_source`: *Not implemented yet...* -- `fail_download_source`: *Not implemented yet...* - `port_already_use`: Causes an error on the port by opening before. The `port_already_use` test may eventually take in argument the port number. The port number must be written into parentheses, it will serve to test port. -- `final_path_already_use`: *Not implemented yet...* ### `;;; Levels` Allow to choose how [each level](https://yunohost.org/#/packaging_apps_levels_fr) is determined @@ -312,7 +136,6 @@ The `package_check.sh` script accept 6 arguments in addition of package to be ch - `--build-lxc`: Install LXC and create the Debian Yunohost container if necessary. - `--force-install-ok`: Force success of installation, even if they fail. Allow to perform following tests even if installation fail. - `--interrupt`: Force auto_remove value, break before each remove. -- `--no-lxc`: Not use virtualization with LXC container. All tests will perform directly on the hosts machine. - `--help`: Display help. --- diff --git a/check_process b/check_process index 93fdae7..6881cd5 100644 --- a/check_process +++ b/check_process @@ -7,7 +7,7 @@ language="fr" # is_public="Yes" (PUBLIC|public=Yes|private=No) is_public=1 (PUBLIC|public=1|private=0) - password="pass" (PASSWORD) + password="pass" port="666" (PORT) ; Checks pkg_linter=1