Browse Source

Merge pull request #112 from YunoHost-Apps/testing

Testing
Alexandre Aubin 1 year ago
parent
commit
19e43b8726
14 changed files with 64 additions and 103 deletions
  1. 1 1
      README.md
  2. 1 1
      README_fr.md
  3. 0 4
      conf/dnsmasq.conf.tpl
  4. 0 0
      conf/dnsmasq_dhcpdv4.conf
  5. 0 0
      conf/dnsmasq_dhcpdv6.conf
  6. 0 0
      conf/hostapd.conf
  7. 6 0
      conf/ynh-hotspot
  8. 1 1
      manifest.json
  9. 39 53
      scripts/_common.sh
  10. 0 8
      scripts/backup
  11. 2 2
      scripts/config
  12. 4 10
      scripts/install
  13. 2 11
      scripts/restore
  14. 8 12
      scripts/upgrade

+ 1 - 1
README.md

@@ -20,7 +20,7 @@ If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/in
 * Combine with the [VPN Client app](https://github.com/labriqueinternet/vpnclient_ynh) to obtain a VPN-protected WiFi
 
 
-**Shipped version:** 2.1.1~ynh1
+**Shipped version:** 2.2.0~ynh1
 
 ## Screenshots
 

+ 1 - 1
README_fr.md

@@ -20,7 +20,7 @@ Si vous n’avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) po
 * À combiner avec l'[app VPN Client](https://github.com/labriqueinternet/vpnclient_ynh) pour obtenir un accès internet aumatiquement protégé par votre VPN
 
 
-**Version incluse :** 2.1.1~ynh1
+**Version incluse :** 2.2.0~ynh1
 
 ## Captures d’écran
 

+ 0 - 4
conf/dnsmasq.conf.tpl

@@ -1,4 +0,0 @@
-# Wifi Hotspot app for YunoHost 
-
-# Enable DNS resolution on wifi interface
-interface=__WIFI_DEVICE__

conf/dnsmasq_dhcpdv4.conf.tpl → conf/dnsmasq_dhcpdv4.conf


conf/dnsmasq_dhcpdv6.conf.tpl → conf/dnsmasq_dhcpdv6.conf


conf/hostapd.conf.tpl → conf/hostapd.conf


+ 6 - 0
conf/ynh-hotspot

@@ -296,6 +296,9 @@ start)
 
     # Update dynamic settings
     ynh_app_setting_set hotspot gateway_interface "${new_gateway_interface}"
+
+    # Regen-conf dnsmasq to enable dns resolution on dnsmasq for the new interface
+    yunohost tools regen-conf dnsmasq
     ;;
 stop)
     echo "[hotspot] Stopping..."
@@ -319,6 +322,9 @@ stop)
         echo "Stop hostapd"
         stop_hostapd
     fi
+
+    # Regen-conf dnsmasq to disable dns resolution on dnsmasq for the previous interface
+    yunohost tools regen-conf dnsmasq
     ;;
 restart)
     $0 stop

+ 1 - 1
manifest.json

@@ -6,7 +6,7 @@
         "en": "Create and manager wifi networks, share Internet access and use YunoHost apps accross wifi",
         "fr": "Créer et configurer des réseaux wifi, partager l'accès a Internet et utiliser les applications YunoHost via wifi"
     },
-    "version": "2.1.1~ynh1",
+    "version": "2.2.0~ynh1",
     "url": "https://github.com/labriqueinternet/hotspot_ynh",
     "license": "AGPL-3.0",
     "maintainer": {

+ 39 - 53
scripts/_common.sh

@@ -14,31 +14,31 @@ free_firmware_packages="firmware-ath9k-htc"
 
 function other_hotspot_apps()
 {
-  local app_shortname="${app%%__*}"
-  local hotspot_apps=$(yunohost app list --output-as json | jq -r .apps[].id | grep -F $app_shortname)
-  # Remove this app from hotspot apps list
-  grep -F -x -v $app <<< ${hotspot_apps}
+    local app_shortname="${app%%__*}"
+    local hotspot_apps=$(yunohost app list --output-as json | jq -r .apps[].id | grep -F $app_shortname)
+    # Remove this app from hotspot apps list
+    grep -F -x -v $app <<< ${hotspot_apps}
 }
 
 function iw_devices()
 {
-  /sbin/iw dev | grep Interface | grep -v 'mon\.' | grep -v hotspot | awk '{ print $NF }'
+    /sbin/iw dev | grep Interface | grep -v 'mon\.' | grep -v hotspot | awk '{ print $NF }'
 }
 
 function used_iw_devices()
 {
-  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
-      echo "${hotspot_wifi_device}"
-    fi
-  done
+    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
+            echo "${hotspot_wifi_device}"
+        fi
+    done
 }
 
 function unused_iw_devices()
 {
-  # Only prints devices that are not in the list of used devices
-  iw_devices | grep -F -v -f <(used_iw_devices)
+    # Only prints devices that are not in the list of used devices
+    iw_devices | grep -F -v -f <(used_iw_devices)
 }
 
 function check_armbian_nonfree_conflict()
@@ -47,10 +47,10 @@ function check_armbian_nonfree_conflict()
   # If we're on armbian, force $firmware_nonfree
   # because armbian-firmware conflicts with firmware-misc-nonfree package
   if dpkg --list | grep -q armbian-firmware; then
-    echo "You are running Armbian and firmware-misc-nonfree are known to conflict with armbian-firwmare. " >&2
-    echo "The package firmware-misc-nonfree is a dependency of firmware-ralink, so firmware-ralink will NOT be installed" >&2
-    echo "You can manually install firmware-ralink with 'apt -o Dpkg::Options::=\"--force-overwrite\" firmware-ralink'" >&2
-    nonfree_firmware_packages=$(echo $nonfree_firmware_packages | sed 's/ firmware-ralink//')
+      echo "You are running Armbian and firmware-misc-nonfree are known to conflict with armbian-firwmare. " >&2
+      echo "The package firmware-misc-nonfree is a dependency of firmware-ralink, so firmware-ralink will NOT be installed" >&2
+      echo "You can manually install firmware-ralink with 'apt -o Dpkg::Options::=\"--force-overwrite\" firmware-ralink'" >&2
+      nonfree_firmware_packages=$(echo $nonfree_firmware_packages | sed 's/ firmware-ralink//')
   fi
 
 }
@@ -58,50 +58,36 @@ function check_armbian_nonfree_conflict()
 
 function hot_reload_usb_wifi_cards()
 {
-  modulesList="acx-mac80211 ar5523 ar9170usb at76c50x-usb at76_usb ath9k_htc carl9170 orinoco_usb p54usb prism2_usb r8712u r8192s_usb r8192u_usb rndis_wlan rt2500usb rt2800usb rt2870sta rt73usb rtl8187 rtl8192cu usb8xxx vt6656_stage zd1201 zd1211rw"
-  modprobe --quiet --remove $modulesList || true
-  possibleUsbDevicesNeedingReload=$(dmesg | grep -Pio '(?<=usb )[0-9-]+(?=:.*firmware)' | sort | uniq)
-  for usbPath in $possibleUsbDevicesNeedingReload; do
-    if [[ -f "/sys/bus/usb/devices/$usbPath/authorized" ]]; then
-      echo "Try to reload driver for usb $usbPath" >&2
-      echo 0 > /sys/bus/usb/devices/$usbPath/authorized
-      echo 1 > /sys/bus/usb/devices/$usbPath/authorized
-      # Wait for driver reloading
-      sleep 2
-    fi
-  done
+    modulesList="acx-mac80211 ar5523 ar9170usb at76c50x-usb at76_usb ath9k_htc carl9170 orinoco_usb p54usb prism2_usb r8712u r8192s_usb r8192u_usb rndis_wlan rt2500usb rt2800usb rt2870sta rt73usb rtl8187 rtl8192cu usb8xxx vt6656_stage zd1201 zd1211rw"
+    modprobe --quiet --remove $modulesList || true
+    possibleUsbDevicesNeedingReload=$(dmesg | grep -Pio '(?<=usb )[0-9-]+(?=:.*firmware)' | sort | uniq)
+    for usbPath in $possibleUsbDevicesNeedingReload; do
+        if [[ -f "/sys/bus/usb/devices/$usbPath/authorized" ]]; then
+            echo "Try to reload driver for usb $usbPath" >&2
+            echo 0 > /sys/bus/usb/devices/$usbPath/authorized
+            echo 1 > /sys/bus/usb/devices/$usbPath/authorized
+            # Wait for driver reloading
+            sleep 2
+        fi
+    done
 }
 
 function configure_hostapd()
 {
-  if [[ "${wifi_secure}" -eq 1 ]]; then
-		sec_comment=""
-	else
-		sec_comment="#"
-	fi
-
-	ynh_add_config --template="/etc/hostapd/$app/hostapd.conf.tpl" --destination="/etc/hostapd/$app/hostapd.conf"
-}
+    if [[ "${wifi_secure}" -eq 1 ]]; then
+        sec_comment=""
+    else
+        sec_comment="#"
+    fi
 
-function configure_dnsmasq()
-{
-  ynh_add_config --template="/etc/dnsmasq.$app/dnsmasq.conf.tpl" --destination="/etc/dnsmasq.d/$app.conf"
-  systemctl restart dnsmasq
+    ynh_add_config --template="../conf/hostapd.conf" --destination="/etc/hostapd/$app/hostapd.conf"
 }
 
 function configure_dhcp()
 {
-  ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv4.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv4.conf"
+    ynh_add_config --template="../conf/dnsmasq_dhcpdv4.conf" --destination="/etc/dnsmasq.$app/dhcpdv4.conf"
 
-	if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then
-		ynh_add_config --template="/etc/dnsmasq.$app/dhcpdv6.conf.tpl" --destination="/etc/dnsmasq.$app/dhcpdv6.conf"
-	fi  
+    if [[ -n "${ip6_net}" ]] && [[ "${ip6_net}" != "none" ]]; then
+        ynh_add_config --template="../conf/dnsmasq_dhcpdv6.conf" --destination="/etc/dnsmasq.$app/dhcpdv6.conf"
+    fi  
 }
-
-#=================================================
-# EXPERIMENTAL HELPERS
-#=================================================
-
-#=================================================
-# FUTURE OFFICIAL HELPERS
-#=================================================

+ 0 - 8
scripts/backup

@@ -40,16 +40,8 @@ ynh_print_info --message="Declaring files to be backed up..."
 # BACKUP THE APP MAIN DIR
 #=================================================
 
-ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf.tpl"
 ynh_backup --src_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory
-
-ynh_backup --src_path="/etc/dnsmasq.$app/dnsmasq.conf.tpl"
-ynh_backup --src_path="/etc/dnsmasq.d/$app.conf" --not_mandatory
-
-ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl"
 ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory
-
-ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf.tpl"
 ynh_backup --src_path="/etc/dnsmasq.$app/dhcpdv4.conf" --not_mandatory
 
 ynh_backup --src_path="/usr/local/bin/$service_name"

+ 2 - 2
scripts/config

@@ -205,7 +205,6 @@ ynh_app_config_apply() {
 
     if [[ "${service_enabled}" -eq 1 ]]; then
         configure_hostapd
-        configure_dnsmasq
         configure_dhcp
 
         # Start hotspot
@@ -214,12 +213,13 @@ ynh_app_config_apply() {
     else
         ynh_print_info --message="Cleanup hotspot config files"
         ynh_secure_remove --file="/etc/hostapd/$app/hostapd.conf"
-        ynh_secure_remove --file="/etc/dnsmasq.d/$app.conf"
         ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv4.conf"
         ynh_secure_remove --file="/etc/dnsmasq.$app/dhcpdv6.conf"
 
         systemctl restart dnsmasq
     fi
+
+    yunohost tools regen-conf dnsmasq
 }
 
 ynh_app_config_run $1

+ 4 - 10
scripts/install

@@ -161,11 +161,6 @@ chown root: /etc/hostapd/$app/
 mkdir -pm 0755 /etc/dnsmasq.$app/
 chown root: /etc/dnsmasq.$app/
 
-install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/hostapd.conf.tpl
-install -b -o root -g root -m 0644 ../conf/dnsmasq.conf.tpl /etc/dnsmasq.$app/dnsmasq.conf.tpl
-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
-
 # Copy init script
 ynh_add_config --template="../conf/ynh-hotspot" --destination="/usr/local/bin/$service_name"
 chmod 0755 "/usr/local/bin/$service_name"
@@ -192,9 +187,8 @@ 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 
-	configure_hostapd
-	configure_dnsmasq
-	configure_dhcp
+    configure_hostapd
+    configure_dhcp
 fi
 
 #=================================================
@@ -212,7 +206,7 @@ ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_host
 #=================================================
 ynh_script_progression --message="Integrating service in YunoHost..."
 
-yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app"
+yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --need_lock
 
 #=================================================
 # START SYSTEMD SERVICE
@@ -223,7 +217,7 @@ ynh_script_progression --message="Starting a systemd service..."
 if [[ $wifi_device == "" ]]; then
 	echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
 else
-	ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
+    yunohost service start $service_name
 fi
 
 #=================================================

+ 2 - 11
scripts/restore

@@ -71,17 +71,8 @@ else
 	pkg_dependencies="$pkg_dependencies $free_firmware_packages"
 fi
 
-ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf.tpl"
 ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory
-
-ynh_restore_file --origin_path="/etc/dnsmasq.$app/dnsmasq.conf.tpl"
-ynh_restore_file --origin_path="/etc/dnsmasq.d/$app.conf" --not_mandatory
-systemctl restart dnsmasq
-
-ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf.tpl"
 ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory
-
-ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv4.conf.tpl"
 ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv4.conf" --not_mandatory
 
 ynh_restore_file --origin_path="/usr/local/bin/$service_name"
@@ -112,7 +103,7 @@ ynh_restore_file --origin_path="/etc/systemd/system/hostapd@$app.service"
 #=================================================
 ynh_script_progression --message="Integrating service in YunoHost..."
 
-yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app"
+yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --need_lock
 
 #=================================================
 # START SYSTEMD SERVICE
@@ -135,7 +126,7 @@ fi
 if [[ $wifi_device == "" ]]; then
 	echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
 else
-	ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
+    yunohost service start $service_name
 fi
 
 #=================================================

+ 8 - 12
scripts/upgrade

@@ -58,8 +58,7 @@ ynh_abort_if_errors
 # STOP SYSTEMD SERVICE
 #=================================================
 ynh_script_progression --message="Stopping the hotspot service ... (this may take some time)"
-
-ynh_systemd_action --service_name=$service_name --action="stop" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
+yunohost service stop $service_name
 
 #=================================================
 # ENSURE DOWNWARD COMPATIBILITY
@@ -70,6 +69,9 @@ if [ -d /var/www/wifiadmin/ ]; then
     ynh_secure_remove /var/www/wifiadmin/
 fi
 
+if [ -e /etc/dnsmasq.d/$app.conf ]; then
+    ynh_secure_remove /etc/dnsmasq.d/$app.conf
+fi
 
 if [ $firmware_nonfree = "yes" ]; then
 	firmware_nonfree=1
@@ -213,15 +215,9 @@ chown root: /etc/hostapd/$app/
 mkdir -pm 0755 /etc/dnsmasq.$app/
 chown root: /etc/dnsmasq.$app/
 
-install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl /etc/hostapd/$app/hostapd.conf.tpl
-install -b -o root -g root -m 0644 ../conf/dnsmasq.conf.tpl /etc/dnsmasq.$app/dnsmasq.conf.tpl
-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 
-	configure_hostapd
-	configure_dnsmasq
-	configure_dhcp
+    configure_hostapd
+    configure_dhcp
 fi
 
 # Copy init script
@@ -254,7 +250,7 @@ ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_host
 #=================================================
 ynh_script_progression --message="Integrating service in YunoHost..."
 
-yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app"
+yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --need_lock
 
 #=================================================
 # START SYSTEMD SERVICE
@@ -272,7 +268,7 @@ fi
 if [[ $wifi_device == "" ]]; then
 	echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
 else
-	ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
+    yunohost service start $service_name
 fi
 
 #=================================================