From c39e31a92cc7f962906236b50f2fb85401c338af Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sun, 17 Sep 2023 21:57:39 +0200 Subject: [PATCH] Code review / add quotes around suspicious vars that may be empty --- scripts/_common.sh | 2 +- scripts/config | 16 ++++++++-------- scripts/install | 2 +- scripts/restore | 2 +- scripts/upgrade | 12 ++++++------ 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index b6e0acb..94a730a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -25,7 +25,7 @@ function used_iw_devices() local other_hotspot_apps=$(grep -F -x -v $app <<< ${hotspot_apps}) for hotspot_app in ${other_hotspot_apps}; do hotspot_wifi_device=$(ynh_app_setting_get --app=$hotspot_app --key=wifi_device) - if [[ -n ${hotspot_wifi_device} ]]; then + if [[ -n "${hotspot_wifi_device}" ]]; then echo "${hotspot_wifi_device}" fi done diff --git a/scripts/config b/scripts/config index 7ad0dc5..b7c9748 100644 --- a/scripts/config +++ b/scripts/config @@ -27,7 +27,7 @@ final_path=$(ynh_app_setting_get $app final_path) #================================================= get__no_antenna() { - if [[ $(unused_iw_devices) == "" ]] + if [[ "$(unused_iw_devices)" == "" ]] then echo "value: true" else @@ -39,7 +39,7 @@ get__status() { local service_enabled=$(ynh_app_setting_get $app service_enabled) if systemctl is-active hostapd@$app -q then - if [[ $service_enabled -eq 1 ]] + if [[ "$service_enabled" -eq 1 ]] then cat << EOF style: success @@ -54,7 +54,7 @@ ask: en: Your Hotspot is running, but it shouldn't ! EOF fi - elif [[ $service_enabled -eq 1 ]] + elif [[ "$service_enabled" -eq 1 ]] then cat << EOF style: danger @@ -77,7 +77,7 @@ EOF get__wifi_device() { local unused_wifi_devices=$(unused_iw_devices) - if [[ -z ${unused_wifi_devices} ]] + if [[ -z "${unused_wifi_devices}" ]] then echo "choices: []" else @@ -99,11 +99,11 @@ get__dns() { ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix) ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns) - if [[ -n ${ip6_net} ]] && [[ -z ${ip6_dns} ]]; then + if [[ -n "${ip6_net}" ]] && [[ -z "${ip6_dns}" ]]; then ip6_dns="${ip6_net}1" fi - if [[ -n ${ip4_nat_prefix} ]] && [[ -z ${ip4_dns} ]]; then + if [[ -n "${ip4_nat_prefix}" ]] && [[ -z "${ip4_dns}" ]]; then ip4_dns="${ip4_nat_prefix}.1" fi @@ -164,11 +164,11 @@ set__dns() { ip6_dns="${ip6_dns%%,}" ip4_dns="${ip4_dns%%,}" - if [[ -n ${ip6_net} ]] && [[ -z ${ip6_dns} ]]; then + if [[ -n "${ip6_net}" ]] && [[ -z "${ip6_dns}" ]]; then ip6_dns="${ip6_net}1" fi - if [[ -n ${ip4_nat_prefix} ]] && [[ -z ${ip4_dns} ]]; then + if [[ -n "${ip4_nat_prefix}" ]] && [[ -z "${ip4_dns}" ]]; then ip4_dns="${ip4_nat_prefix}.1" fi diff --git a/scripts/install b/scripts/install index fb494bd..a8ebb60 100644 --- a/scripts/install +++ b/scripts/install @@ -200,7 +200,7 @@ systemctl disable hostapd --quiet 2>&1 systemctl stop hostapd 2>&1 systemctl unmask hostapd 2>&1 # On some system e.g. RPi, for some reason hostapd is masked after install ... -if [[ -n ${wifi_device} ]]; then +if [[ -n "${wifi_device}" ]]; then configure_hostapd configure_dhcp fi diff --git a/scripts/restore b/scripts/restore index 6bce614..43d912c 100644 --- a/scripts/restore +++ b/scripts/restore @@ -107,7 +107,7 @@ yunohost service add $service_name --description "Creates a Wi-Fi access point" ynh_script_progression --message="Starting a systemd service..." hot_reload_usb_wifi_cards -if [[ -z $wifi_device ]] || ! grep -q -F $wifi_device <(unused_iw_devices); then +if [[ -z "$wifi_device" ]] || ! grep -q -F "$wifi_device" <(unused_iw_devices); then wifi_device=$(unused_iw_devices | head -n 1) ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" fi diff --git a/scripts/upgrade b/scripts/upgrade index 076da9d..ce8da75 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -84,7 +84,7 @@ if [ -z $service_name ]; then ynh_app_setting_set --app=$app --key=service_name --value=$service_name fi -if [[ -n ${multissid} ]] && [[ ${multissid} -gt 1 ]]; then +if [[ -n "${multissid}" ]] && [[ "${multissid}" -gt 1 ]]; then wifi_ssid=$(cut -d'|' -f 1 <<< ${wifi_ssid}) wifi_secure=$(cut -d'|' -f 1 <<< ${wifi_secure}) wifi_passphrase=$(cut -d'|' -f 1 <<< ${wifi_passphrase}) @@ -129,7 +129,7 @@ else ip4_dns=$(ynh_app_setting_get --app=$app --key=ip4_dns) fi -if [[ -n ${multissid} ]]; then +if [[ -n "${multissid}" ]]; then ynh_app_setting_delete --app=$app --key=multissid ynh_secure_remove --file="/etc/hostapd/hostapd.conf" @@ -138,7 +138,7 @@ if [[ -n ${multissid} ]]; then ynh_secure_remove --file="/etc/dnsmasq.dhcpd/" fi -if [[ -z ${advanced} ]]; then +if [[ -z "${advanced}" ]]; then ynh_app_setting_set --app=$app --key=advanced --value=0 fi @@ -202,8 +202,8 @@ ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Copying configuration..." hot_reload_usb_wifi_cards -if [[ -z $wifi_device ]] || ! grep -q -F $wifi_device <(unused_iw_devices); then - wifi_device=$(unused_iw_devices | head -n 1) +if [[ -z "$wifi_device" ]] || ! grep -q -F "$wifi_device" <(unused_iw_devices); then + wifi_device="$(unused_iw_devices | head -n 1)" ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" fi @@ -217,7 +217,7 @@ install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/ho install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.$app/dhcpdv6.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.$app/dhcpdv4.conf.tpl -if [[ -n ${wifi_device} ]]; then +if [[ -n "${wifi_device}" ]]; then configure_hostapd configure_dhcp fi