From bf25e6ac379fdc3e04660110a285f16eaa314561 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 8 Mar 2018 14:38:15 +0000 Subject: [PATCH] Arrays without quotes --- src/freedombone-addremove | 12 +++++--- src/freedombone-adduser | 3 +- src/freedombone-app-pelican | 3 +- src/freedombone-app-pleroma | 4 +-- src/freedombone-backup-local | 3 +- src/freedombone-config | 6 ++-- src/freedombone-controlpanel | 15 ++++++---- src/freedombone-controlpanel-user | 3 +- src/freedombone-freedns | 6 ++-- src/freedombone-image | 9 ++++-- src/freedombone-logging | 6 ++-- src/freedombone-mesh-blog | 3 +- src/freedombone-rmuser | 3 +- src/freedombone-tests | 3 +- src/freedombone-utils-backup | 9 ++++-- src/freedombone-utils-config | 11 +++++--- src/freedombone-utils-selector | 47 ++++++++++++++++++++----------- src/freedombone-utils-setup | 3 +- 18 files changed, 98 insertions(+), 51 deletions(-) diff --git a/src/freedombone-addremove b/src/freedombone-addremove index 58d1468c..6f0845b2 100755 --- a/src/freedombone-addremove +++ b/src/freedombone-addremove @@ -72,7 +72,8 @@ function mark_unselected_apps_as_removed { fi app_index=0 - for app_name in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for app_name in ${APPS_AVAILABLE[@]} do if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then echo "_${app_name}_" >> "$REMOVED_APPS_FILE" @@ -106,7 +107,8 @@ function show_apps { applist="" n=1 app_index=0 - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do if [[ ${APPS_INSTALLED[$app_index]} == "0" && "$select_all_apps" != "add-all" ]]; then applist="$applist $n $a off" @@ -144,7 +146,8 @@ function remove_apps_selected { removals="" app_index=0 n=0 - for a in "${APPS_INSTALLED[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_INSTALLED[@]} do if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then @@ -188,7 +191,8 @@ function install_apps_selected { installs="" app_index=0 n=0 - for a in "${APPS_INSTALLED[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_INSTALLED[@]} do if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then diff --git a/src/freedombone-adduser b/src/freedombone-adduser index 9acb819a..be350333 100755 --- a/src/freedombone-adduser +++ b/src/freedombone-adduser @@ -211,7 +211,8 @@ chmod 600 "/home/$ADD_USERNAME/README" echo $'Detecting installed apps...' detect_apps get_apps_installed_names -for app_name in "${APPS_INSTALLED_NAMES[@]}" +# shellcheck disable=SC2068 +for app_name in ${APPS_INSTALLED_NAMES[@]} do if [[ $(function_exists "add_user_${app_name}") == "1" ]]; then echo $"Adding user to ${app_name}" diff --git a/src/freedombone-app-pelican b/src/freedombone-app-pelican index c6809ab2..82f46050 100755 --- a/src/freedombone-app-pelican +++ b/src/freedombone-app-pelican @@ -295,7 +295,8 @@ function pelican_change_theme { if [ -f $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index ]; then curr_theme_index=$(cat $PELICAN_BLOG_INSTALL_DIR/.blog-theme-index) fi - for a in "${THEMES[@]}" + # shellcheck disable=SC2068 + for a in ${THEMES[@]} do is_selected='off' if [ "$curr_theme_index" ]; then diff --git a/src/freedombone-app-pleroma b/src/freedombone-app-pleroma index bb6f1a7c..27cb6100 100755 --- a/src/freedombone-app-pleroma +++ b/src/freedombone-app-pleroma @@ -180,7 +180,7 @@ function expire_pleroma_posts { echo ''; echo '# copy the avatar files to a temporary directory'; echo "arr=( \$avatars )"; - echo "for i in \"\${arr[@]}\"; do"; + echo "for i in \${arr[@]}; do"; echo " if [[ \"\$i\" == *'/media/'* ]]; then"; echo " imagefile=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}');"; echo " if [ -f \$imagefile ]; then"; @@ -203,7 +203,7 @@ function expire_pleroma_posts { echo ''; echo '# copy the banner files to a temporary directory'; echo "arr=( \$banners )"; - echo "for i in \"\${arr[@]}\"; do"; + echo "for i in \${arr[@]}; do"; echo " if [[ \"\$i\" == *'/media/'* ]]; then"; echo " imagefile=/etc/pleroma/uploads/\$(echo \$i | sed 's|\"||g' | sed 's|,||g' | awk -F '/media/' '{print \$2}');"; echo " if [ -f \$imagefile ]; then"; diff --git a/src/freedombone-backup-local b/src/freedombone-backup-local index 12d373d0..e1e403d5 100755 --- a/src/freedombone-backup-local +++ b/src/freedombone-backup-local @@ -228,7 +228,8 @@ function backup_directories { "/root/.passwords, passwordstore" ) - for dr in "${backup_dirs[@]}" + # shellcheck disable=SC2068 + for dr in ${backup_dirs[@]} do # if this directory exists then back it up to the given destination source_directory=$(echo "$dr" | awk -F ',' '{print $1}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') diff --git a/src/freedombone-config b/src/freedombone-config index 33d4646b..168c0b26 100755 --- a/src/freedombone-config +++ b/src/freedombone-config @@ -798,7 +798,8 @@ function choose_system_variant { varslist="" n=1 - for a in "${available_variants_list[@]}" + # shellcheck disable=SC2068 + for a in ${available_variants_list[@]} do varstate='off' if [[ "$a" == $'full' || "$a" == $'Full' ]]; then @@ -1057,7 +1058,8 @@ function select_user { users_array=($homedirs) delete=(git) - for del in "${delete[@]}" + # shellcheck disable=SC2068 + for del in ${delete[@]} do # shellcheck disable=SC2206 users_array=(${users_array[@]/$del}) diff --git a/src/freedombone-controlpanel b/src/freedombone-controlpanel index 37563643..f4cf7504 100755 --- a/src/freedombone-controlpanel +++ b/src/freedombone-controlpanel @@ -230,7 +230,8 @@ function passwords_show_apps { i=0 W=() name=() - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do if [[ $(function_exists "change_password_${a}") == "1" ]]; then i=$((i+1)) @@ -410,7 +411,8 @@ function show_domains { grep 'sks onion domain' "${COMPLETION_FILE}" | awk -F ':' '{print $2}' fi - for app_name in "${APPS_INSTALLED_NAMES[@]}" + # shellcheck disable=SC2068 + for app_name in ${APPS_INSTALLED_NAMES[@]} do if ! grep -q "SHOW_ON_ABOUT=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then continue @@ -1129,7 +1131,8 @@ function restore_data_from_storage { app_list+=("$AllStr") util_index=0 - for a in "${utils_installed[@]}" + # shellcheck disable=SC2068 + for a in ${utils_installed[@]} do applist="$applist $n $a off" app_name=${utils_installed[util_index]} @@ -1139,7 +1142,8 @@ function restore_data_from_storage { done app_index=0 - for a in "${APPS_INSTALLED_NAMES[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_INSTALLED_NAMES[@]} do applist="$applist $n $a off" n=$((n+1)) @@ -2233,7 +2237,8 @@ function menu_app_settings { appnames=() n=1 app_index=0 - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do if [[ ${APPS_INSTALLED[$app_index]} != "0" ]]; then if [[ $(function_exists "configure_interactive_${a}") == "1" ]]; then diff --git a/src/freedombone-controlpanel-user b/src/freedombone-controlpanel-user index 45318738..7c280d26 100755 --- a/src/freedombone-controlpanel-user +++ b/src/freedombone-controlpanel-user @@ -837,7 +837,8 @@ function menu_run_client_app { appnames=() n=1 app_index=0 - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do if [[ ${APPS_INSTALLED[$app_index]} != "0" ]]; then if [[ $(function_exists "run_client_${a}") == "1" ]]; then diff --git a/src/freedombone-freedns b/src/freedombone-freedns index e9db50a3..327f4c0d 100755 --- a/src/freedombone-freedns +++ b/src/freedombone-freedns @@ -55,7 +55,8 @@ detected_codes=() codelines=$(grep "_CODE=" "$CONFIGURATION_FILE" | uniq) while read -r line; do code=$(echo "$line" | awk -F '=' '{print $2}') - if ! item_in_array "$code" "${detected_codes[@]}"; then + # shellcheck disable=SC2068 + if ! item_in_array "$code" ${detected_codes[@]}; then detected_codes+=("$code") fi done <<< "$codelines" @@ -64,7 +65,8 @@ if [ ! -d "$HOME/.freedns-update" ]; then mkdir "$HOME/.freedns-update" fi cd "$HOME/.freedns-update" || exit 2467824684 -for code in "${detected_codes[@]}" +# shellcheck disable=SC2068 +for code in ${detected_codes[@]} do if [ $VERBOSE ]; then echo $"command: $FREEDNS_WGET${code}=" diff --git a/src/freedombone-image b/src/freedombone-image index 034a4c6f..fb772ab3 100755 --- a/src/freedombone-image +++ b/src/freedombone-image @@ -482,7 +482,8 @@ fi # Move any existing images into a build subdirectory image_types=( xz img sig vdi qcow2 ) -for im in "${image_types[@]}" +# shellcheck disable=SC2068 +for im in ${image_types[@]} do # shellcheck disable=SC2012,SC2086 no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l) @@ -496,7 +497,8 @@ do done # Delete anything which didn't move -for im in "${image_types[@]}" +# shellcheck disable=SC2068 +for im in ${image_types[@]} do # shellcheck disable=SC2012,SC2086 no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l) @@ -624,7 +626,8 @@ if [ ${#imgfiles[@]} -eq 0 ]; then fi # Move images from temporary directory to the current directory -for im in "${image_types[@]}" +# shellcheck disable=SC2068 +for im in ${image_types[@]} do # shellcheck disable=SC2012,SC2086 no_of_files=$(ls -afq build/${PROJECT_NAME}*.${im} | wc -l) diff --git a/src/freedombone-logging b/src/freedombone-logging index ca3dbdd7..0b76aeb0 100755 --- a/src/freedombone-logging +++ b/src/freedombone-logging @@ -73,7 +73,8 @@ function logging_get_app_names { function turn_logging_on { logging_get_app_names - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do echo $"Turning on logging for ${a}" "logging_on_${a}" @@ -83,7 +84,8 @@ function turn_logging_on { function turn_logging_off { logging_get_app_names - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do echo $"Turning off logging for ${a}" "logging_off_${a}" diff --git a/src/freedombone-mesh-blog b/src/freedombone-mesh-blog index 46a967db..8152ff52 100755 --- a/src/freedombone-mesh-blog +++ b/src/freedombone-mesh-blog @@ -187,7 +187,8 @@ function change_theme { if [ -f /tmp/.blog-themes ]; then rm /tmp/.blog-themes fi - for a in "${THEMES[@]}" + # shellcheck disable=SC2068 + for a in ${THEMES[@]} do echo "$n $a" >> /tmp/.blog-themes n=$((n+1)) diff --git a/src/freedombone-rmuser b/src/freedombone-rmuser index b83e0940..6b4a42c5 100755 --- a/src/freedombone-rmuser +++ b/src/freedombone-rmuser @@ -124,7 +124,8 @@ fi echo $'Detecting installed apps...' detect_apps get_apps_installed_names -for app_name in "${APPS_INSTALLED_NAMES[@]}" +# shellcheck disable=SC2068 +for app_name in ${APPS_INSTALLED_NAMES[@]} do if [[ $(function_exists "remove_user_${app_name}") == "1" ]]; then echo $"Removing user from ${app_name}" diff --git a/src/freedombone-tests b/src/freedombone-tests index cf201b60..3b726b91 100755 --- a/src/freedombone-tests +++ b/src/freedombone-tests @@ -124,7 +124,8 @@ function test_app_functions { for filename in $FILES do # for each expected interface function - for f in "${interface_functions[@]}" + # shellcheck disable=SC2068 + for f in ${interface_functions[@]} do test_app_function_type "${filename}" "$f" done diff --git a/src/freedombone-utils-backup b/src/freedombone-utils-backup index 77fa3fc0..4598fc51 100755 --- a/src/freedombone-utils-backup +++ b/src/freedombone-utils-backup @@ -543,7 +543,8 @@ function backup_apps { detect_installable_apps get_apps_installed_names - for app_name in "${APPS_INSTALLED_NAMES[@]}" + # shellcheck disable=SC2068 + for app_name in ${APPS_INSTALLED_NAMES[@]} do echo $"Backup ${app_name}" app_load_variables "${app_name}" @@ -563,7 +564,8 @@ function restore_apps { detect_installable_apps get_apps_installed_names - for app_name in "${APPS_INSTALLED_NAMES[@]}" + # shellcheck disable=SC2068 + for app_name in ${APPS_INSTALLED_NAMES[@]} do confirm_restore= if [ ! "$2" ]; then @@ -807,7 +809,8 @@ function valid_backup_destination { available_variants_list=() available_system_variants - if ! item_in_array "${destination_dir}" "${available_variants_list[@]}"; then + # shellcheck disable=SC2068 + if ! item_in_array "${destination_dir}" ${available_variants_list[@]}; then is_valid="no" fi diff --git a/src/freedombone-utils-config b/src/freedombone-utils-config index 00191c46..06f24e0a 100755 --- a/src/freedombone-utils-config +++ b/src/freedombone-utils-config @@ -279,7 +279,8 @@ function remove_completion_param { } function save_configuration_values { - for v in "${configuration_variables[@]}" + # shellcheck disable=SC2068 + for v in ${configuration_variables[@]} do write_config_param "$v" "${!v}" done @@ -299,7 +300,8 @@ function read_configuration_values { cp "$CONFIGURATION_FILE" "/root/${PROJECT_NAME}.cfg" fi - for v in "${configuration_variables[@]}" + # shellcheck disable=SC2068 + for v in ${configuration_variables[@]} do read_config_param "$v" done @@ -337,13 +339,14 @@ function check_domains { domains_array=("$specified_domains") checked_domains=() - for d in "${domains_array[@]}" + # shellcheck disable=SC2068 + for d in ${domains_array[@]} do domain_param=$(echo "$d" | awk -F '=' '{print $1}') if [[ "$domain_param" != "DEFAULT_DOMAIN_NAME" ]]; then domain_value=$(echo "$d" | awk -F '=' '{print $2}') if [[ "$domain_value" != "${LOCAL_NAME}.local" ]]; then - if ! item_in_array "${domain_value}" "${checked_domains[@]}"; then + if ! item_in_array "${domain_value}" ${checked_domains[@]}; then # test that this is a valid domain name function_check test_domain_name test_domain_name "$domain_value" diff --git a/src/freedombone-utils-selector b/src/freedombone-utils-selector index 8eea0926..e56173b9 100755 --- a/src/freedombone-utils-selector +++ b/src/freedombone-utils-selector @@ -69,7 +69,8 @@ function app_load_variables { #shellcheck disable=SC2206 configvarname=( ${!configvarname} ) - for v in "${configvarname[@]}" + # shellcheck disable=SC2068 + for v in ${configvarname[@]} do read_config_param "$v" done @@ -90,7 +91,8 @@ function app_save_variables { #shellcheck disable=SC2206 configvarname=( ${!configvarname} ) - for v in "${configvarname[@]}" + # shellcheck disable=SC2068 + for v in ${configvarname[@]} do write_config_param "$v" "${!v}" done @@ -128,9 +130,10 @@ function available_system_variants { system_variants_list=$(app_variants "$filename") # shellcheck disable=SC2206 variants_array=($system_variants_list) - for variant_str in "${variants_array[@]}" + # shellcheck disable=SC2068 + for variant_str in ${variants_array[@]} do - if ! item_in_array "${variant_str}" "${new_available_variants_list[@]}"; then + if ! item_in_array "${variant_str}" ${new_available_variants_list[@]}; then new_available_variants_list+=("$variant_str") fi done @@ -146,7 +149,8 @@ function is_valid_variant { function_check available_system_variants available_system_variants - for variant_str in "${available_variants_list[@]}" + # shellcheck disable=SC2068 + for variant_str in ${available_variants_list[@]} do if [[ "$sys_type" == "$variant_str" ]]; then return "1" @@ -161,7 +165,8 @@ function show_available_variants { function_check available_system_variants available_system_variants - for variant_str in "${available_variants_list[@]}" + # shellcheck disable=SC2068 + for variant_str in ${available_variants_list[@]} do echo " $variant_str" done @@ -250,7 +255,8 @@ function install_completed { # populates an array of "0" or "1" for whether apps are installed function get_apps_installed { - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do APPS_INSTALLED+=("$(app_is_installed "$a")") done @@ -259,7 +265,8 @@ function get_apps_installed { # populates an array of installed app names function get_apps_installed_names { APPS_INSTALLED_NAMES=() - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do if [[ $(app_is_installed "$a") == "1" ]]; then APPS_INSTALLED_NAMES+=("$a") @@ -281,7 +288,8 @@ function detect_apps { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if ! item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"; then + # shellcheck disable=SC2068 + if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then APPS_AVAILABLE+=("${app_name}") APPS_CHOSEN+=("0") fi @@ -312,7 +320,8 @@ function detect_installable_apps { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if ! item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"; then + # shellcheck disable=SC2068 + if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then variants_list=$(app_variants "$filename") # check for empty string if [ ${#variants_list} -gt 0 ]; then @@ -344,7 +353,8 @@ function detect_installed_apps { app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') if [[ $(app_is_installed "$app_name") == "1" ]]; then - if ! item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"; then + # shellcheck disable=SC2068 + if ! item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then variants_list=$(app_variants "$filename") if [ ${#variants_list} -gt 0 ]; then APPS_AVAILABLE+=("${app_name}") @@ -378,7 +388,8 @@ function choose_apps_for_variant { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if item_in_array "${app_name}" "${APPS_AVAILABLE[@]}"; then + # shellcheck disable=SC2068 + if item_in_array "${app_name}" ${APPS_AVAILABLE[@]}; then if grep -q "VARIANTS=" "${filename}"; then variants_list=$(app_variants "$filename") if [[ "${variants_list}" == 'all'* || \ @@ -408,7 +419,8 @@ function choose_apps_for_variant { # show a list of apps which have been chosen function list_chosen_apps { app_index=0 - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then echo $"${a}" @@ -419,7 +431,8 @@ function list_chosen_apps { function remove_apps { app_index=0 - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do if [[ ${APPS_INSTALLED[$app_index]} == "1" ]]; then if [[ ${APPS_CHOSEN[$app_index]} == "0" ]]; then @@ -450,7 +463,8 @@ function remove_apps { function install_apps_interactive { echo $"Interactive installer" app_index=0 - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then @@ -546,7 +560,8 @@ function install_apps { # now install the apps app_index=0 - for a in "${APPS_AVAILABLE[@]}" + # shellcheck disable=SC2068 + for a in ${APPS_AVAILABLE[@]} do if [[ ${APPS_INSTALLED[$app_index]} == "0" ]]; then if [[ ${APPS_CHOSEN[$app_index]} == "1" ]]; then diff --git a/src/freedombone-utils-setup b/src/freedombone-utils-setup index 66148ebf..a7f6becc 100755 --- a/src/freedombone-utils-setup +++ b/src/freedombone-utils-setup @@ -1105,7 +1105,8 @@ function upgrade_apps { do app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') - if ! item_in_array "${app_name}" "${APPS_COMPLETED[@]}"; then + # shellcheck disable=SC2068 + if ! item_in_array "${app_name}" ${APPS_COMPLETED[@]}; then function_check app_is_installed if [[ "$(app_is_installed "$app_name")" == "1" ]]; then echo ''