Browse Source

Merge pull request #71 from HugoPoi/fix/buster-armbian-enhancements

Buster armbian enhancements
Alexandre Aubin 4 years ago
parent
commit
e026be7911

+ 0 - 11
check_process

@@ -20,17 +20,6 @@
 		incorrect_path=1
 		port_already_use=0
 		change_url=0
-;;; Levels
-	Level 1=auto
-	Level 2=auto
-	Level 3=auto
-	Level 4=na
-	Level 5=auto
-	Level 6=auto
-	Level 7=auto
-	Level 8=0
-	Level 9=0
-	Level 10=0
 ;;; Upgrade options
 	; commit=546fd17712c7a9df428a4f26e7f8e4394884aaaf
 		name=29 Jan 2019

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"

+ 36 - 60
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
@@ -90,12 +82,6 @@ if [[ $wifi_passphrase =~ [^[:print:]] ]]; then
 fi
 
 #=================================================
-# RUN PREREQUISITES
-#=================================================
-
-source ./prerequisites
-
-#=================================================
 # STORE SETTINGS FROM MANIFEST
 #=================================================
 ynh_script_progression --message="Storing installation settings..."
@@ -104,6 +90,7 @@ ynh_app_setting_set --app=$app --key=domain --value="$domain"
 ynh_app_setting_set --app=$app --key=wifi_ssid --value="$wifi_ssid"
 ynh_app_setting_set --app=$app --key=wifi_passphrase --value="$wifi_passphrase"
 ynh_app_setting_set --app=$app --key=firmware_nonfree --value="$firmware_nonfree"
+ynh_app_setting_set --app=$app --key=service_name --value=$service_name
 
 #=================================================
 # STANDARD MODIFICATIONS
@@ -126,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
 
 #=================================================
@@ -146,15 +124,7 @@ fi
 #=================================================
 ynh_script_progression --message="Installing dependencies"
 
-ynh_install_app_dependencies "$pkg_dependencies" "$packages"
-
-#=================================================
-# NGINX CONFIGURATION
-#=================================================
-ynh_script_progression --message="Configuring nginx web server..."
-
-# Create a dedicated nginx config
-ynh_add_nginx_config
+ynh_install_app_dependencies "$pkg_dependencies"
 
 #=================================================
 # CREATE DEDICATED USER
@@ -169,15 +139,6 @@ install -b -o root -g root -m 0440 ../conf/sudoers.conf /etc/sudoers.d/${app}_yn
 ynh_replace_string --match_string="__HOTSPOT_SYSUSER__" --replace_string="${app}" --target_file="/etc/sudoers.d/${app}_ynh"
 
 #=================================================
-# PHP-FPM CONFIGURATION
-#=================================================
-ynh_script_progression --message="Configuring php-fpm..."
-
-# Create a dedicated php-fpm config
-ynh_add_fpm_config
-phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
-
-#=================================================
 # INSTALL CUSTOM SCRIPTS
 #=================================================
 ynh_script_progression --message="Installing custom script..."
@@ -203,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
@@ -220,7 +182,6 @@ ynh_app_setting_set --app=$app --key=ip4_dns0 --value=80.67.188.188
 ynh_app_setting_set --app=$app --key=ip4_dns1 --value=80.67.169.12
 ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242
 ynh_app_setting_set --app=$app --key=vpnclient --value=no
-ynh_app_setting_set --app=$app --key=service_name --value=$service_name
 
 if [[ -z $wifi_device ]]; then
   ynh_app_setting_set --app=$app --key=service_enabled --value=0
@@ -243,12 +204,12 @@ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq
 
 # Copy init script
 install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
-ynh_replace_string --match_string="__PHPVERSION__" --replace_string="${phpversion}" --target_file="/usr/local/bin/$service_name"
+ynh_replace_string --match_string="__PHPVERSION__" --replace_string="${YNH_PHP_VERSION}" --target_file="/usr/local/bin/$service_name"
 
 #=================================================
 # COPY WEB SOURCES
 #=================================================
-ynh_script_progression --message="Copy web sources..."
+ynh_script_progression --message="Setting up source files..."
 
 ynh_app_setting_set --app=$app --key=final_path --value=$final_path
 mkdir -pm 0755 ${final_path}/
@@ -259,9 +220,25 @@ chmod -R 0644 ${final_path}/*
 find ${final_path}/ -type d -exec chmod +x {} \;
 
 #=================================================
-# FIX CONFIGS
+# NGINX CONFIGURATION
+#=================================================
+ynh_script_progression --message="Configuring nginx web server..."
+
+# Create a dedicated nginx config
+ynh_add_nginx_config
+
+#=================================================
+# PHP-FPM CONFIGURATION
 #=================================================
-ynh_script_progression --message="Fix config..."
+ynh_script_progression --message="Configuring php-fpm..."
+
+# Create a dedicated php-fpm config
+ynh_add_fpm_config
+
+#=================================================
+# CONFIGURE HOSTAPD
+#=================================================
+ynh_script_progression --message="Configuring hostapd..."
 
 ## hostapd
 ynh_replace_string --match_string="^DAEMON_CONF=$" --replace_string="&/etc/hostapd/hostapd.conf" --target_file=/etc/init.d/hostapd
@@ -270,8 +247,15 @@ 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
+# and the ynh-hotspot service handles them.
+systemctl disable hostapd --quiet
+systemctl stop hostapd
+systemctl unmask hostapd # On some system e.g. RPi, for some reason hostapd is masked after install ...
 
 #=================================================
 # STORE THE CONFIG FILE CHECKSUM
@@ -279,7 +263,6 @@ ynh_replace_string --match_string="__PATH__" --replace_string="${path_url}" --ta
 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"
 
 #=================================================
@@ -290,13 +273,6 @@ ynh_script_progression --message="Configuring a systemd service..."
 # Create a dedicated systemd config
 ynh_add_systemd_config --service=$service_name
 
-# Set default inits
-# The boot order of these services are important, so they are disabled by default
-# and the ynh-hotspot service handles them.
-systemctl disable hostapd
-systemctl stop hostapd
-systemctl unmask hostapd # On some system e.g. RPi, for some reason hostapd is masked after install ...
-
 # Remove IPv6 address set if there is a VPN installed
 if [[ $ip6_addr != none ]]; then
   if ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"; then
@@ -309,7 +285,7 @@ fi
 #=================================================
 ynh_script_progression --message="Integrating service in YunoHost..."
 
-yunohost service add $service_name --description "Creates a Wi-Fi access point"
+yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd"
 
 #=================================================
 # START SYSTEMD SERVICE

+ 0 - 8
scripts/prerequisites

@@ -1,8 +0,0 @@
-# Source me
-
-# Check if dnsmasq is active
-systemctl is-active dnsmasq &> /dev/null
-
-if [[ $? -ne 0 ]]; then
-  ynh_die --message="You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)"
-fi

+ 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
 #=================================================

+ 7 - 13
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
@@ -129,20 +122,21 @@ ynh_install_app_dependencies "$pkg_dependencies" "$packages"
 ynh_script_progression --message="Restoring the systemd configuration..."
 
 ynh_restore_file --origin_path="/etc/systemd/system/$service_name.service"
-systemctl enable $service_name.service
+systemctl enable $service_name.service --quiet
 
 #=================================================
 # INTEGRATE SERVICE IN YUNOHOST
 #=================================================
 ynh_script_progression --message="Integrating service in YunoHost..."
 
-yunohost service add $service_name --description "Creates a Wi-Fi access point"
+yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd"
 
 #=================================================
 # START SYSTEMD SERVICE
 #=================================================
 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

+ 8 - 17
scripts/upgrade

@@ -36,7 +36,7 @@ upgrade_type=$(ynh_check_app_version_changed)
 ynh_script_progression --message="Ensuring downward compatibility..."
 
 if [ -z $phpversion ]; then
-	phpversion=7.0
+	phpversion=$YNH_PHP_VERSION
 	ynh_app_setting_set --app=$app --key=phpversion --value=$phpversion
 fi
 
@@ -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
@@ -144,7 +138,6 @@ ynh_script_progression --message="Upgrading php-fpm configuration..."
 
 # Create a dedicated php-fpm config
 ynh_add_fpm_config
-phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
 
 #=================================================
 # SPECIFIC UPGRADE
@@ -169,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
@@ -199,13 +189,14 @@ find ${final_path}/ -type d -exec chmod +x {} \;
 #=================================================
 ynh_script_progression --message="Integrating service in YunoHost..."
 
-yunohost service add $service_name --description "Creates a Wi-Fi access point"
+yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd"
 
 #=================================================
 # START SYSTEMD SERVICE
 #=================================================
 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