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