diff --git a/package_check.sh b/package_check.sh index f9b452e..4444bdf 100755 --- a/package_check.sh +++ b/package_check.sh @@ -23,6 +23,7 @@ clean_exit () { rm -f "$script_dir/url_output" rm -f "$script_dir/curl_print" rm -f "$script_dir/manifest_extract" + rm -rf "$script_dir/tmp_context_for_tests" # Remove the application which been tested if [ -n "$package_path" ]; then @@ -883,20 +884,15 @@ then # 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 -m1 "$1" "$partial_check_process") + echo $(grep -m1 "$1" "$check_process_section") } # Extract a section found between $1 and $2 from the file $3 extract_section () { # Erase the partial check_process - > "$partial_check_process" + > "$check_process_section" local source_file="$3" local extract=0 local line="" @@ -906,16 +902,16 @@ then if [ $extract -eq 1 ] then # Check if the line is the second line to found - if check_line "$2"; then + if echo $line | grep -q "$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" + echo "$line" >> "$check_process_section" fi # Search for the first line - if check_line "$1"; then + if echo $line | grep -q "$1"; then # Activate the extract process extract=1 fi @@ -928,7 +924,7 @@ then # Extract the level section - partial_check_process=$partial1 + check_process_section=$partial1 extract_section "^;;; Levels" ";; " "$check_process" # Get the value associated to each level @@ -945,7 +941,7 @@ then # Extract the Options section - partial_check_process=$partial1 + check_process_section=$partial1 extract_section "^;;; Options" ";; " "$check_process" # Try to find a optionnal email address to notify the maintainer @@ -963,39 +959,30 @@ then # Initialize the values for this serie of tests initialize_values + rm -rf $script_dir/tmp_context_for_tests/ + mkdir -p $script_dir/tmp_context_for_tests/ + # Break after the first tests serie if [ $total_number_of_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 + check_process_section=$partial2 # Extract the section of the current tests serie extract_section "^$tests_serie" "^;;" "$check_process" - partial_check_process=$partial1 + check_process_section=$partial1 # Check if there a pre-install instruction for this serie extract_section "^; pre-install" "^;" "$partial2" - pre_install="$(cat "$partial_check_process")" + cat "$check_process_section" > ./tmp_context_for_tests/preinstall.sh.template # Parse all infos about arguments of manifest # Extract the manifest arguments section from the second partial file extract_section "^; Manifest" "^; " "$partial2" - # Initialize the arguments list - manifest_arguments="" - - # Read each arguments and store them - while read line - do - # Extract each argument by removing spaces or tabulations before a parenthesis - add_arg="$(echo $line | sed 's/[ *|\t*](.*//')" - # Remove all double quotes - add_arg="${add_arg//\"/}" - # Then add this argument and follow it by & - manifest_arguments="${manifest_arguments}${add_arg}&" - done < "$partial_check_process" + manifest_arguments=$(cat $check_process_section | awk '{print $1}' | tr -d '"' | tr '\n' '&') # Try to find all specific arguments needed for the tests keep_name_arg_only () { @@ -1056,7 +1043,7 @@ then add_arg="${line//\"/}" # Then add this argument and follow it by : actions_arguments="${actions_arguments}${add_arg}:" - done < "$partial_check_process" + done < "$check_process_section" # Parse all infos about arguments of config-panel.toml # Extract the config_panel arguments section from the second partial file @@ -1072,7 +1059,7 @@ then add_arg="${line//\"/}" # Then add this argument and follow it by : config_panel_arguments="${config_panel_arguments}${add_arg}:" - done < "$partial_check_process" + done < "$check_process_section" # Parse all tests to perform # Extract the checks options section from the second partial file @@ -1080,9 +1067,7 @@ then 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) + local value=$(find_string "^$1=" | awk -F= '{print $2}') # And return this value if [ "${value:0:1}" = "1" ] then @@ -1139,9 +1124,9 @@ then fi # Clean the upgrade list - > "$script_dir/upgrade_list" + touch "$script_dir/tmp_context_for_tests/upgrade_list" # Get multiples lines for upgrade option. - while $(grep --quiet "^upgrade=" "$partial_check_process") + while $(grep --quiet "^upgrade=" "$check_process_section") do # Get the value for the first upgrade test. temp_upgrade=$(read_check_option upgrade) @@ -1158,14 +1143,14 @@ then line="${line##*from_commit=}" # Add the upgrade to the list only if the test is set to 1 if [ $temp_upgrade -eq 1 ]; then - echo "$line" >> "$script_dir/upgrade_list" + echo "$line" >> "$script_dir/tmp_context_for_tests/upgrade_list" fi elif [ $temp_upgrade -eq 1 ]; then # Or simply 'current' for a standard upgrade. - echo "current" >> "$script_dir/upgrade_list" + echo "current" >> "$script_dir/tmp_context_for_tests/upgrade_list" fi # Remove this line from the check_process - sed --in-place "\|${line}$|d" "$partial_check_process" + sed --in-place "\|${line}$|d" "$check_process_section" done # Launch all tests successively @@ -1188,7 +1173,7 @@ else manifest_extract="$script_dir/manifest_extract" - # Extract the informations from the manifest with the Bram's sly snake script. + # Extract the informations from the manifest with the Brams sly snake script. python "$script_dir/sub_scripts/manifest_parsing.py" "$package_path/manifest.json" > "$manifest_extract" # Default tests diff --git a/sub_scripts/testing_process.sh b/sub_scripts/testing_process.sh index ffe1eee..50ae185 100644 --- a/sub_scripts/testing_process.sh +++ b/sub_scripts/testing_process.sh @@ -2,13 +2,6 @@ echo -e "Loads 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 () { @@ -58,23 +51,25 @@ SETUP_APP () { current_snapshot=snap0 # Exec the pre-install instruction, if there one - if [ -n "$pre_install" ] + preinstall_script_template="$script_dir/tmp_context_for_tests/preinstall.sh.template" + if [ -e "$preinstall_script_template" ] then small_title "Pre installation request" # Start the lxc container LXC_START "true" # Copy all the instructions into a script - echo "$pre_install" > "$script_dir/preinstall.sh" - chmod +x "$script_dir/preinstall.sh" - # Replace variables - sed -i "s/\$USER/$test_user/" "$script_dir/preinstall.sh" - sed -i "s/\$DOMAIN/$main_domain/" "$script_dir/preinstall.sh" - sed -i "s/\$SUBDOMAIN/$sub_domain/" "$script_dir/preinstall.sh" - sed -i "s/\$PASSWORD/$yuno_pwd/" "$script_dir/preinstall.sh" + preinstall_script="$script_dir/tmp_context_for_tests/preinstall.sh" + cp "$preinstall_script_template" "$preinstall_script" + chmod +x "$preinstall_script" + # Hydrate the template with variables + sed -i "s/\$USER/$test_user/" "$preinstall_script" + sed -i "s/\$DOMAIN/$main_domain/" "$preinstall_script" + sed -i "s/\$SUBDOMAIN/$sub_domain/" "$preinstall_script" + sed -i "s/\$PASSWORD/$yuno_pwd/" "$preinstall_script" # Copy the pre-install script into the container. - scp -rq "$script_dir/preinstall.sh" "$lxc_name": + scp -rq "$preinstall_script" "$lxc_name": # Then execute the script to execute the pre-install commands. - LXC_START "./preinstall.sh >&2" | tee -a "$complete_log" + LXC_START "./preinstall.sh >&2" fi # Install the application in a LXC container @@ -658,7 +653,7 @@ CHECK_UPGRADE () { # Get the specific section for this upgrade from the check_process extract_section "^; commit=$commit" "^;" "$check_process" # Get the name for this upgrade. - upgrade_name=$(grep "^name=" "$partial_check_process" | cut -d'=' -f2) + upgrade_name=$(grep "^name=" "$check_process_section" | cut -d'=' -f2) # Or use the commit if there's no name. if [ -z "$upgrade_name" ]; then start_test "Upgrade from the commit $commit" @@ -698,7 +693,7 @@ CHECK_UPGRADE () { # Backup the modified arguments update_manifest_args="$manifest_args_mod" # Get the arguments of the manifest for this upgrade. - manifest_args_mod="$(grep "^manifest_arg=" "$partial_check_process" | cut -d'=' -f2-)" + manifest_args_mod="$(grep "^manifest_arg=" "$check_process_section" | cut -d'=' -f2-)" if [ -z "$manifest_args_mod" ]; then # If there's no specific arguments, use the previous one. manifest_args_mod="$update_manifest_args" @@ -764,7 +759,7 @@ CHECK_UPGRADE () { current_snapshot=snap0 # Stop and restore the LXC container LXC_STOP >> $complete_log - done 4< "$script_dir/upgrade_list" + done 4< "$script_dir/tmp_context_for_tests/upgrade_list" } CHECK_PUBLIC_PRIVATE () { @@ -1144,6 +1139,9 @@ CHECK_BACKUP_RESTORE () { else small_title "Backup of the application..." + # 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" + # Made a backup of the application run_yunohost "backup create -n Backup_test --apps $ynh_app_id --system $backup_hooks"