Browse Source

Merge pull request #72 from labriqueinternet/testing

Testing
Alexandre Aubin 4 years ago
parent
commit
7eea610de4
11 changed files with 55 additions and 77 deletions
  1. 0 0
      conf/config.php.tpl
  2. BIN
      conf/firmware_htc-7010.fw
  3. BIN
      conf/firmware_htc-9271.fw
  4. 2 1
      conf/systemd.service
  5. 2 11
      manifest.json
  6. 33 2
      scripts/_common.sh
  7. 0 5
      scripts/backup
  8. 7 24
      scripts/install
  9. 0 9
      scripts/remove
  10. 5 11
      scripts/restore
  11. 6 14
      scripts/upgrade

sources/config.php → conf/config.php.tpl


BIN
conf/firmware_htc-7010.fw


BIN
conf/firmware_htc-9271.fw


+ 2 - 1
conf/systemd.service

@@ -1,10 +1,11 @@
 [Unit]
-Description=YunoHost Wifi Hotspot.
+Description=YunoHost Wifi Hotspot
 Requires=network.target
 After=network.target
 
 [Service]
 Type=oneshot
+User=root
 ExecStart=/usr/local/bin/ynh-hotspot start
 ExecStop=/usr/local/bin/ynh-hotspot stop
 RemainAfterExit=yes

+ 2 - 11
manifest.json

@@ -3,8 +3,8 @@
   "id": "hotspot",
   "packaging_format": 1,
   "description": {
-    "en": "Wifi Hotspot",
-    "fr": "Hotspot Wifi"
+    "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"
   },
   "url": "https://github.com/labriqueinternet/hotspot_ynh",
   "version": "1.2.0~ynh3",
@@ -27,20 +27,11 @@
       {
         "name": "domain",
         "type": "domain",
-        "ask": {
-            "en": "Choose a domain for the web administration",
-            "fr": "Choisissez un domaine pour l'administration web"
-        },
         "example": "domain.org"
       },
       {
         "name": "path",
         "type": "path",
-        "ask": {
-            "en": "Choose a path for the web administration",
-            "fr": "Choisissez un chemin pour l'administration web"
-        },
-        "example": "/wifiadmin",
         "default": "/wifiadmin"
       },
       {

+ 33 - 2
scripts/_common.sh

@@ -5,13 +5,44 @@
 #=================================================
 
 pkg_dependencies="sipcalc hostapd iptables iw dnsmasq"
-nonfree_packages="firmware-linux-free firmware-linux-nonfree firmware-atheros firmware-realtek firmware-ralink firmware-libertas atmel-firmware zd1211-firmware"
-free_packages="firmware-linux-free"
+nonfree_firmware_packages="firmware-atheros firmware-realtek firmware-ralink firmware-libertas atmel-firmware firmware-zd1211"
+free_firmware_packages="firmware-ath9k-htc"
 
 #=================================================
 # PERSONAL HELPERS
 #=================================================
 
+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//')
+  fi
+
+}
+
+
+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
+}
+
 #=================================================
 # EXPERIMENTAL HELPERS
 #=================================================

+ 0 - 5
scripts/backup

@@ -41,11 +41,6 @@ ynh_print_info --message="Declaring files to be backed up..."
 
 ynh_backup --src_path="$final_path"
 
-if [[ $firmware_nonfree -eq 0 ]]; then
-	ynh_backup --src_path="/lib/firmware/htc_7010.fw"
-	ynh_backup --src_path="/lib/firmware/htc_9271.fw"
-fi
-
 ynh_backup --src_path="/etc/sudoers.d/${app}_ynh"
 
 ynh_backup --src_path="/usr/local/bin/iw_multissid"

+ 7 - 24
scripts/install

@@ -59,14 +59,6 @@ test ! -e "$final_path" || ynh_die --message="This path already contains a folde
 # Register (book) web path
 ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
 
-# If we're on armbian, force $firmware_nonfree
-# because armbian-firmware conflicts with the non-free packages ...
-if dpkg --list | grep -q armbian-firmware; then
-  echo "You are running Armbian and non-free firmware are known to conflict with armbian-firwmare. " >&2
-  firmware_nonfree=0
-  echo "Variable firmware_non_free has been forced to 'no'" >&2
-fi
-
 if [ $firmware_nonfree = "no" ]; then
   firmware_nonfree=0
 elif [ $firmware_nonfree = "yes" ]; then
@@ -121,19 +113,10 @@ export DEBIAN_FRONTEND=noninteractive
 # Packaged USB Wireless Device firmwares
 # Based on https://wiki.debian.org/WiFi#USB_Devices
 if [[ $firmware_nonfree -eq 1 ]]; then
-  # check if non-free is set on sources.list
-  if ! grep -q non-free /etc/apt/sources.list ; then
-    sed '/debian/{s/main/& non-free/}' -i /etc/apt/sources.list
-  fi
-  packages=$nonfree_packages
+  check_armbian_nonfree_conflict
+  ynh_install_extra_app_dependencies --repo="deb http://deb.debian.org/debian $(ynh_get_debian_release) non-free" --package="$nonfree_firmware_packages"
 else
-  packages=$free_packages
-  # Extract from http://packages.trisquel.info/toutatis-updates/open-ath9k-htc-firmware
-  # https://www.fsf.org/news/ryf-certification-thinkpenguin-usb-with-atheros-chip
-  # https://wiki.debian.org/ath9k_htc/open_firmware
-  mkdir -p /lib/firmware
-  install -b -o root -g root -m 0644 ../conf/firmware_htc-7010.fw /lib/firmware/htc_7010.fw
-  install -b -o root -g root -m 0644 ../conf/firmware_htc-9271.fw /lib/firmware/htc_9271.fw
+  pkg_dependencies="$pkg_dependencies $free_firmware_packages"
 fi
 
 #=================================================
@@ -141,7 +124,7 @@ fi
 #=================================================
 ynh_script_progression --message="Installing dependencies"
 
-ynh_install_app_dependencies "$pkg_dependencies" "$packages"
+ynh_install_app_dependencies "$pkg_dependencies"
 
 #=================================================
 # CREATE DEDICATED USER
@@ -181,6 +164,7 @@ if [[ ! -v ip6_net ]]; then # if ip6_net not set
   fi
 fi
 
+hot_reload_usb_wifi_cards
 wifi_device=$(bash ../conf/iw_devices | awk -F\| '{ print $1 }')
 
 ynh_app_setting_set --app=$app --key=multissid --value=1
@@ -263,8 +247,8 @@ ynh_replace_string --match_string="^DAEMON_CONF=$" --replace_string="&/etc/hosta
 # isnt used ... instead the service is "pure systemd" ...
 echo "DAEMON_CONF=/etc/hostapd/hostapd.conf" > /etc/default/hostapd
 
-# Fix sources
-ynh_replace_string --match_string="__PATH__" --replace_string="${path_url}" --target_file="$final_path/config.php"
+# Apply configuration
+ynh_add_config --template="config.php.tpl" --destination="$final_path/config.php"
 
 # Set default inits
 # The boot order of these services are important, so they are disabled by default
@@ -279,7 +263,6 @@ systemctl unmask hostapd # On some system e.g. RPi, for some reason hostapd is m
 ynh_script_progression --message="Storing the config file checksum..."
 
 # Calculate and store the config file checksum into the app settings
-ynh_store_file_checksum --file="$final_path/config.php"
 ynh_store_file_checksum --file="/etc/init.d/hostapd"
 
 #=================================================

+ 0 - 9
scripts/remove

@@ -99,15 +99,6 @@ do
     ynh_secure_remove --file="$FILE"
 done
 
-# Remove packages
-if [[ $firmware_nonfree -eq 0 ]]; then
-  # Remove free firmwares
-  if ! dpkg -l firmware-atheros &> /dev/null; then
-    ynh_secure_remove --file="/lib/firmware/htc_7010.fw"
-    ynh_secure_remove --file="/lib/firmware/htc_9271.fw"
-  fi
-fi
-
 #=================================================
 # REMOVE NGINX CONFIGURATION
 #=================================================

+ 5 - 11
scripts/restore

@@ -58,17 +58,10 @@ ynh_script_progression --message="Restoring the app main directory..."
 ynh_restore_file --origin_path="$final_path"
 
 if [[ $firmware_nonfree -eq 1 ]]; then
-  # check if non-free is set on sources.list
-  if ! grep -q non-free /etc/apt/sources.list ; then
-    sed '/debian/{s/main/& non-free/}' -i /etc/apt/sources.list
-  fi
-
-  packages=$nonfree_packages
+  check_armbian_nonfree_conflict
+  ynh_install_extra_app_dependencies --repo="deb http://deb.debian.org/debian $(ynh_get_debian_release) non-free" --package="$nonfree_firmware_packages"
 else
-  packages=$free_packages
-
-  ynh_restore_file --origin_path="/lib/firmware/htc_7010.fw"
-  ynh_restore_file --origin_path="/lib/firmware/htc_9271.fw"
+  pkg_dependencies="$pkg_dependencies $free_firmware_packages"
 fi
 
 ynh_restore_file --origin_path="/etc/sudoers.d/${app}_ynh"
@@ -121,7 +114,7 @@ ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
 ynh_script_progression --message="Reinstalling dependencies..."
 
 # Define and install dependencies
-ynh_install_app_dependencies "$pkg_dependencies" "$packages"
+ynh_install_app_dependencies "$pkg_dependencies"
 
 #=================================================
 # RESTORE SYSTEMD
@@ -143,6 +136,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
 wifi_device=$(bash ../settings/conf/iw_devices | awk -F\| '{ print $1 }')
 
 if [[ -z $wifi_device ]]; then

+ 6 - 14
scripts/upgrade

@@ -81,13 +81,6 @@ ynh_clean_setup () {
 ynh_abort_if_errors
 
 #=================================================
-# CHECK THE PATH
-#=================================================
-
-# Normalize the URL path syntax
-path_url=$(ynh_normalize_url_path --path_url=$path_url)
-
-#=================================================
 # STANDARD UPGRADE STEPS
 #=================================================
 # STOP SYSTEMD SERVICE
@@ -122,12 +115,13 @@ ynh_add_nginx_config
 ynh_script_progression --message="Upgrading dependencies..."
 
 if [[ $firmware_nonfree -eq 1 ]]; then
-  packages=$nonfree_packages
+  check_armbian_nonfree_conflict
+  ynh_install_extra_app_dependencies --repo="deb http://deb.debian.org/debian $(ynh_get_debian_release) non-free" --package="$nonfree_firmware_packages"
 else
-  packages=$free_packages
+  pkg_dependencies="$pkg_dependencies $free_firmware_packages"
 fi
 
-ynh_install_app_dependencies "$pkg_dependencies" "$packages"
+ynh_install_app_dependencies "$pkg_dependencies"
 
 #=================================================
 # CREATE DEDICATED USER
@@ -168,10 +162,7 @@ ynh_replace_string --match_string="__PHPVERSION__" --replace_string="${phpversio
 #=================================================
 ynh_script_progression --message="Modifying a config file..."
 
-ynh_backup_if_checksum_is_different --file="$final_path/config.php"
-ynh_replace_string --match_string="__PATH__" --replace_string="${path_url}" --target_file="$final_path/config.php"
-# Recalculate and store the checksum of the file for the next upgrade.
-ynh_store_file_checksum --file="$final_path/config.php"
+ynh_add_config --template="config.php.tpl" --destination="$final_path/config.php"
 
 #=================================================
 # SETUP SYSTEMD
@@ -205,6 +196,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
 wifi_device=$(bash ../conf/iw_devices | awk -F\| '{ print $1 }')
 
 if [[ -z $wifi_device ]]; then