diff --git a/doc/PRE_INSTALL.md b/doc/PRE_INSTALL.md new file mode 100644 index 0000000..1b77a3b --- /dev/null +++ b/doc/PRE_INSTALL.md @@ -0,0 +1 @@ +After the installation, you will be able to configure the application from YunoHost's webadmin in Applications > Hotspot > Configuration. diff --git a/doc/PRE_INSTALL_fr.md b/doc/PRE_INSTALL_fr.md new file mode 100644 index 0000000..e210e68 --- /dev/null +++ b/doc/PRE_INSTALL_fr.md @@ -0,0 +1 @@ +Après l'application, vous pourrez configurer l'application depuis la webadmin de YunoHost dans Applications > Hotspot > Configuration. diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 369f0f2..0000000 --- a/manifest.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "name": "Wifi Hotspot", - "id": "hotspot", - "packaging_format": 1, - "description": { - "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.2.0~ynh1", - "url": "https://github.com/labriqueinternet/hotspot_ynh", - "license": "AGPL-3.0", - "maintainer": { - "name": "Julien Vaubourg", - "email": "julien@vaubourg.com", - "url": "http://julien.vaubourg.com" - }, - "upstream": { - "license": "AGPL-3.0", - "website": "https://internetcu.be/" - }, - "requirements": { - "yunohost": ">= 4.3.2" - }, - "multi_instance": true, - "services": [], - "arguments": { - "install" : [ - { - "name": "disclaimer", - "type": "display_text", - "style": "info", - "ask": { - "en": "After installation, you will be able to configure the application from YunoHost's webadmin in Applications > Hotspot > Configuration.", - "fr": "Après l'application, vous pourrez configurer l'application depuis la webadmin de YunoHost dans Applications > Hotspot > Configuration." - } - }, - { - "name": "wifi_ssid", - "type": "string", - "ask": { - "en": "Choose a wifi name (SSID)", - "fr": "Choisissez un nom pour le wifi (SSID)" - }, - "example": "myNeutralNetwork", - "default": "myNeutralNetwork" - }, - { - "name": "wifi_passphrase", - "type": "password", - "ask": { - "en": "Choose a wifi password (at least 8 characters for WPA2)", - "fr": "Choisissez un mot de passe wifi (au minimum 8 caractères pour le WPA2)" - } - }, - { - "name": "firmware_nonfree", - "type": "boolean", - "ask": { - "en": "Install non-free WiFi firmwares? (Only needed if you're using a proprietary WiFi antenna/dongle)", - "fr": "Installer des firmwares WiFi non-libres ? (Nécessaire seulement si vous utilisez une antenne/clé WiFi propriétaire)" - }, - "default": false - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..95d1d72 --- /dev/null +++ b/manifest.toml @@ -0,0 +1,73 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "hotspot" +name = "Wifi Hotspot" +description.en = "Create and configure a WiFi hotspot" +description.fr = "Créez et gérez un point d'accès WiFi" + +version = "2.3.0~ynh1" + +maintainers = [] + +[upstream] +license = "AGPL-3.0" +website = "https://internetcu.be/" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = true +ldap = "not_relevant" +sso = "not_relevant" +disk = "50M" +ram.build = "50M" +ram.runtime = "50M" + +[install] + [install.wifi_ssid] + ask.en = "Choose a wifi name (SSID)" + ask.fr = "Choisissez un nom pour le wifi (SSID)" + type = "string" + example = "myNeutralNetwork" + default = "myNeutralNetwork" + + [install.wifi_passphrase] + ask.en = "Choose a wifi password (at least 8 characters for WPA2)" + ask.fr = "Choisissez un mot de passe wifi (au minimum 8 caractères pour le WPA2)" + type = "password" + + [install.firmware_nonfree] + ask.en = "Install non-free WiFi firmwares? (Only needed if you're using a proprietary WiFi antenna/dongle)" + ask.fr = "Installer des firmwares WiFi non-libres ? (Nécessaire seulement si vous utilisez une antenne/clé WiFi propriétaire)" + type = "boolean" + default = false + +[resources] + [resources.system_user] + + [resources.apt] + packages = "sipcalc, hostapd, iw, kmod" + +# ========================================= +# FIXME FIXME FIXME FIXME FIXME FIXME FIXME +# Gotta find a way to conditionally install the non-free packages +# So far the "packages_from_raw_bash" thing doesnt allow conditional packages from extra repo (here, the non-free component..) +# FIXME FIXME FIXME FIXME FIXME FIXME FIXME +# ========================================= +# +# # Packaged USB Wireless Device firmwares +# # Based on https://wiki.debian.org/WiFi#USB_Devices +# if [[ $firmware_nonfree -eq 1 ]]; then +# # FIXME : if armbian-firmware is detected, we should remove ra-link.... +# #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 +# echo "firmware-atheros firmware-realtek firmware-ralink firmware-libertas atmel-firmware firmware-zd1211" +# else +# echo "firmware-ath9k-htc" +# fi diff --git a/scripts/_common.sh b/scripts/_common.sh index 942715a..6d440ed 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,17 +1,5 @@ #!/bin/bash -#================================================= -# COMMON VARIABLES -#================================================= - -pkg_dependencies="sipcalc hostapd iw kmod" -nonfree_firmware_packages="firmware-atheros firmware-realtek firmware-ralink firmware-libertas atmel-firmware firmware-zd1211" -free_firmware_packages="firmware-ath9k-htc" - -#================================================= -# PERSONAL HELPERS -#================================================= - function other_hotspot_apps() { local app_shortname="${app%%__*}" @@ -41,20 +29,6 @@ function unused_iw_devices() iw_devices | grep -F -v -f <(used_iw_devices) } -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() { diff --git a/scripts/backup b/scripts/backup index ce94889..d01e26d 100644 --- a/scripts/backup +++ b/scripts/backup @@ -10,27 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) -service_name=$(ynh_app_setting_get --app=$app --key=service_name) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -49,12 +28,6 @@ ynh_backup --src_path="/usr/local/bin/$service_name" ynh_backup --src_path="/etc/openvpn/scripts/route-up.d/90-$service_name" ynh_backup --src_path="/etc/openvpn/scripts/route-down.d/90-$service_name" -#================================================= -# SPECIFIC BACKUP -#================================================= -# BACKUP SYSTEMD -#================================================= - ynh_backup --src_path="/etc/systemd/system/$service_name.service" ynh_backup --src_path="/etc/systemd/system/hostapd@$app.service" diff --git a/scripts/config b/scripts/config index ad92a84..c353476 100644 --- a/scripts/config +++ b/scripts/config @@ -16,12 +16,6 @@ source /usr/share/yunohost/helpers # Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -final_path=$(ynh_app_setting_get $app final_path) - #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= diff --git a/scripts/install b/scripts/install index 13640b1..b3335cf 100644 --- a/scripts/install +++ b/scripts/install @@ -9,32 +9,14 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST -#================================================= - -wifi_ssid=$YNH_APP_ARG_WIFI_SSID -wifi_passphrase=$YNH_APP_ARG_WIFI_PASSPHRASE -firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE - -app=$YNH_APP_INSTANCE_NAME - -# the service name must match the service template files service_name=ynh-$app +ynh_app_setting_set --app=$app --key=service_name --value=$service_name #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= + +# FIXME : we could probably implement all these checks in manifest.toml directly ? ynh_script_progression --message="Validating installation parameters..." # Check arguments @@ -45,7 +27,7 @@ fi # Check passphrase length wifi_passphrase_length="$(wc -c <<< "${wifi_passphrase}")" if [[ $wifi_passphrase_length -lt 8 ]] || [[ $wifi_passphrase_length -gt 63 ]]; then - ynh_die --message="Your password must from 8 to 63 characters (WPA2 passphrase)" + ynh_die --message="Your password must have between 8 and 63 characters (WPA2 passphrase)" fi # Check no special characters are present in the passphrase @@ -53,16 +35,6 @@ if [[ $wifi_passphrase =~ [^[:print:]] ]]; then ynh_die --message="Only printable ASCII characters are permitted in your password (WPA2 passphrase)" fi -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." - -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 #================================================= @@ -71,6 +43,7 @@ ynh_app_setting_set --app=$app --key=service_name --value=$service_name ynh_script_progression --message="Configuring firewall..." # Update firewall for DHCP +# FIXME : move to manifest.toml ynh_exec_warn_less yunohost firewall allow --no-upnp --ipv6 UDP 547 ynh_exec_warn_less yunohost firewall allow --no-upnp UDP 67 @@ -81,37 +54,6 @@ then /usr/sbin/rfkill unblock wlan fi -#================================================= -# INSTALL NONFREE FIRWARE IF REQUESTED -#================================================= -ynh_script_progression --message="Installing firmware..." - -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_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 - pkg_dependencies="$pkg_dependencies $free_firmware_packages" -fi - -#================================================= -# INSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Installing dependencies..." - -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." - -# Create a system user -ynh_system_user_create --username=$app - #================================================= # SPECIFIC SETTINGS #================================================= @@ -132,9 +74,7 @@ wifi_device=$(unused_iw_devices | head -n 1) wifi_secure=1 wifi_channel=6 -ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}" ynh_app_setting_set --app=$app --key=wifi_secure --value="${wifi_secure}" -ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}" ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" ynh_app_setting_set --app=$app --key=wifi_channel --value="${wifi_channel}" ynh_app_setting_set --app=$app --key=advanced --value=0 @@ -144,7 +84,7 @@ ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}" ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value="${ip4_nat_prefix}" -if [[ -z $wifi_device ]]; then +if [[ -z "$wifi_device" ]]; then ynh_app_setting_set --app=$app --key=service_enabled --value=0 else ynh_app_setting_set --app=$app --key=service_enabled --value=1 @@ -194,28 +134,23 @@ fi #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." +ynh_script_progression --message="Configuring systemd service..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name # Create custom systemd config for hostapd to handle multiple wifi devices ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_hostapd.service" -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -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" --need_lock #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting the hotspot..." # Start a systemd service if device is present if [[ $wifi_device == "" ]]; then - echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2 + echo "WARNING: Wifi Hotspot is not started because no wifi device was found (check the Hotspot configuration in the webadmin > Applications > Hotspot > the config panel)" >&2 else yunohost service start $service_name fi diff --git a/scripts/remove b/scripts/remove index 7b3d158..edaa762 100644 --- a/scripts/remove +++ b/scripts/remove @@ -9,16 +9,6 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) -service_name=$(ynh_app_setting_get --app=$app --key=service_name) - #================================================= # STANDARD REMOVE #================================================= @@ -30,32 +20,16 @@ ynh_script_progression --message="Removing $app service" yunohost service stop $service_name yunohost service remove $service_name -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." - -# Remove the dedicated systemd config ynh_remove_systemd_config --service=$service_name ynh_remove_systemd_config --service="hostapd@$app" -#================================================= -# REMOVE DEPENDENCIES -#================================================= -ynh_script_progression --message="Removing dependencies..." - -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." +ynh_script_progression --message="Removing $app configurations..." ynh_secure_remove --file="/etc/openvpn/scripts/route-up.d/90-${service_name}" ynh_secure_remove --file="/etc/openvpn/scripts/route-down.d/90-${service_name}" - -# Remove the app directory securely ynh_secure_remove --file="/usr/local/bin/$service_name" for FILE in $(ls /tmp/.${service_name}-* 2>/dev/null); do @@ -84,19 +58,3 @@ if [[ -z "$(other_hotspot_apps)" ]]; then ynh_exec_warn_less yunohost firewall disallow TCP 67 fi fi - -#================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER -#================================================= -ynh_script_progression --message="Removing the dedicated system user..." - -# Delete a system user -ynh_system_user_delete --username=$app - -#================================================= -# END OF SCRIPT -#================================================= - -ynh_script_progression --message="Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 8232152..4d93dce 100644 --- a/scripts/restore +++ b/scripts/restore @@ -10,32 +10,6 @@ source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# MANAGE SCRIPT FAILURE -#================================================= - -ynh_clean_setup () { - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) -service_name=$(ynh_app_setting_get --app=$app --key=service_name) -wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." - #================================================= # FIND AND OPEN A PORT #================================================= @@ -55,21 +29,8 @@ fi #================================================= # STANDARD RESTORATION STEPS #================================================= -#================================================= -# RECREATE THE DEDICATED USER -#================================================= -ynh_script_progression --message="Recreating the dedicated system user..." -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app - - -if [[ $firmware_nonfree -eq 1 ]]; then - 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 - pkg_dependencies="$pkg_dependencies $free_firmware_packages" -fi +ynh_script_progression --message="Restoring configurations ..." ynh_restore_file --origin_path="/etc/hostapd/$app/hostapd.conf" --not_mandatory ynh_restore_file --origin_path="/etc/dnsmasq.$app/dhcpdv6.conf" --not_mandatory @@ -80,50 +41,30 @@ ynh_restore_file --origin_path="/usr/local/bin/$service_name" ynh_restore_file --origin_path="/etc/openvpn/scripts/route-up.d/90-${service_name}" ynh_restore_file --origin_path="/etc/openvpn/scripts/route-down.d/90-${service_name}" -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." - -# Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." - ynh_restore_file --origin_path="/etc/systemd/system/$service_name.service" ynh_restore_file --origin_path="/etc/systemd/system/hostapd@$app.service" -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -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" --need_lock +yunohost service add "$service_name" --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd@$app" --need_lock #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression --message="Starting the hotspot 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 -if [[ -z $wifi_device ]]; then +if [[ -z "${wifi_device:-}" ]]; then ynh_app_setting_set --app=$app --key=service_enabled --value=0 else ynh_app_setting_set --app=$app --key=service_enabled --value=1 fi # Start a systemd service if device is present -if [[ $wifi_device == "" ]]; then +if [[ "${wifi_device:-}" == "" ]]; then echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2 else yunohost service start $service_name diff --git a/scripts/upgrade b/scripts/upgrade index 3d3ecbd..7b14ae9 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,49 +9,8 @@ source _common.sh source /usr/share/yunohost/helpers -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -firmware_nonfree=$(ynh_app_setting_get --app=$app --key=firmware_nonfree) -service_name=$(ynh_app_setting_get --app=$app --key=service_name) - -wifi_device=$(ynh_app_setting_get --app=$app --key=wifi_device) -wifi_ssid=$(ynh_app_setting_get --app=$app --key=wifi_ssid) -wifi_secure=$(ynh_app_setting_get --app=$app --key=wifi_secure) -wifi_passphrase=$(ynh_app_setting_get --app=$app --key=wifi_passphrase) -wifi_channel=$(ynh_app_setting_get --app=$app --key=wifi_channel) -advanced=$(ynh_app_setting_get --app=$app --key=advanced) -ip4_nat_prefix=$(ynh_app_setting_get --app=$app --key=ip4_nat_prefix) -ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) -ip6_firewall=$(ynh_app_setting_get --app=$app --key=ip6_firewall) -dns=$(ynh_app_setting_get --app=$app --key=dns) -multissid=$(ynh_app_setting_get --app=$app --key=multissid) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." - upgrade_type=$(ynh_check_app_version_changed) -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -73,20 +32,20 @@ if [ -e /etc/dnsmasq.d/$app.conf ]; then ynh_secure_remove /etc/dnsmasq.d/$app.conf fi -if [ $firmware_nonfree = "yes" ]; then +if [ ${firmware_nonfree:-} = "yes" ]; then firmware_nonfree=1 ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree -elif [ $firmware_nonfree = "no" ]; then +elif [ ${firmware_nonfree:-} = "no" ]; then firmware_nonfree=0 ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree fi -if [ -z $service_name ]; then +if [ -z ${service_name:-} ]; then service_name="ynh-$app" 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}) @@ -104,7 +63,7 @@ if [[ -n "${multissid}" ]] && [[ "${multissid}" -gt 1 ]]; then ynh_app_setting_set --app=$app --key=ip6_firewall --value="${ip6_firewall}" fi -if [[ -n "${dns}" ]]; then +if [[ -n "${dns:-}" ]]; then ip6_dns="" ip4_dns="" for ip in $(echo "${dns}" | tr ',' ' '); do @@ -118,20 +77,17 @@ if [[ -n "${dns}" ]]; then ip6_dns="${ip6_dns%%,}" ip4_dns="${ip4_dns%%,}" - if [[ -z "$(ynh_app_setting_get --app=$app --key=ip6_dns)" ]]; then + if [[ -z "$(ynh_app_setting_get --app=$app --key=ip6_dns)" ]]; then ynh_app_setting_set --app=$app --key=ip6_dns --value="${ip6_dns}" fi - if [[ -z "$(ynh_app_setting_get --app=$app --key=ip4_dns)" ]]; then + if [[ -z "$(ynh_app_setting_get --app=$app --key=ip4_dns)" ]]; then ynh_app_setting_set --app=$app --key=ip4_dns --value="${ip4_dns}" fi ynh_app_setting_delete $app dns -else - ip6_dns=$(ynh_app_setting_get --app=$app --key=ip6_dns) - 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" @@ -140,14 +96,13 @@ 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 # Old stuff prior to 2.x -ip6_net=$(ynh_app_setting_get --app=$app --key=ip6_net) -if [ "$ip6_net" == "none" ] +if [ "${ip6_net:-}" == "none" ] then ip6_net="" ynh_app_setting_set --app=$app --key=ip6_net --value="$ip6_net" @@ -166,36 +121,14 @@ if [ -d /var/www/$app ]; then ynh_secure_remove /var/www/$app fi -[ -z "$(ynh_app_setting_get $app domain)" ] || ynh_app_setting_delete $app domain -[ -z "$(ynh_app_setting_get $app path)" ] || ynh_app_setting_delete $app path -[ -z "$(ynh_app_setting_get $app final_path)" ] || ynh_app_setting_delete $app final_path +[ -z "${domain:-}" ] || ynh_app_setting_delete $app domain +[ -z "${path:-}" ] || ynh_app_setting_delete $app path +[ -z "${install_dir:-}" ] || ynh_app_setting_delete $app install_dir if [ -e "/etc/sudoers.d/${app}_ynh" ]; then ynh_secure_remove "/etc/sudoers.d/${app}_ynh" fi -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." - -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." - -if [[ $firmware_nonfree -eq 1 ]]; then - 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 - pkg_dependencies="$pkg_dependencies $free_firmware_packages" -fi - -ynh_install_app_dependencies $pkg_dependencies - #================================================= # SPECIFIC UPGRADE #================================================= @@ -204,6 +137,7 @@ 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)" ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}" @@ -215,9 +149,13 @@ chown root: /etc/hostapd/$app/ mkdir -pm 0755 /etc/dnsmasq.$app/ chown root: /etc/dnsmasq.$app/ -if [[ -n "${wifi_device}" ]]; then +if [[ -n "${wifi_device:-}" ]]; then configure_hostapd configure_dhcp + ynh_app_setting_set --app=$app --key=service_enabled --value=1 +else + ynh_app_setting_set --app=$app --key=service_enabled --value=0 + wifi_device="" fi # Copy init script @@ -243,13 +181,6 @@ ynh_add_systemd_config --service=$service_name # Create custom systemd config for hostapd to handle multiple wifi devices ynh_add_systemd_config --service="hostapd@$app" --template="../conf/systemd_hostapd.service" -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -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" --need_lock #================================================= @@ -257,16 +188,9 @@ yunohost service add $service_name --description "Creates a Wi-Fi access point" #================================================= ynh_script_progression --message="Starting the hotspot service..." -if [[ -z $wifi_device ]]; then - ynh_app_setting_set --app=$app --key=service_enabled --value=0 - wifi_device="" -else - ynh_app_setting_set --app=$app --key=service_enabled --value=1 -fi - # Start a systemd service if device is present if [[ $wifi_device == "" ]]; then - echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2 + echo "WARNING: Wifi Hotspot is not started because no wifi device was found (check the Hotspot configuration in the webadmin > Applications > Hotspot > the config panel)" >&2 else yunohost service start $service_name fi