From 7cbd23c1ec1144c85ed1d096e359319bd1f105d8 Mon Sep 17 00:00:00 2001 From: Keoma Brun Date: Fri, 4 May 2018 00:33:01 +0200 Subject: [PATCH] using new helpers and script formatting --- manifest.json | 20 ++- scripts/{helpers => _common.sh} | 12 +- scripts/backup | 16 +- scripts/install | 281 ++++++++++++++++++++------------ scripts/prerequisites | 16 +- scripts/remove | 55 +++++-- scripts/restore | 22 ++- scripts/upgrade | 71 ++++---- 8 files changed, 316 insertions(+), 177 deletions(-) rename scripts/{helpers => _common.sh} (72%) diff --git a/manifest.json b/manifest.json index ae91350..b5260f4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,21 +1,32 @@ { "name": "Wifi Hotspot", "id": "hotspot", + "packaging_format": 1, "description": { "en": "Wifi Hotspot", "fr": "Hotspot Wifi" }, - "license": "AGPL-3", - "developer": { + "url": "https://github.com/labriqueinternet/hotspot_ynh", + "version": "1.1.0", + "license": "AGPL-3.0", + "maintainer": { "name": "Julien Vaubourg", "email": "julien@vaubourg.com", "url": "http://julien.vaubourg.com" }, - "multi_instance": "false", + "requirements": { + "yunohost": ">= 2.2.0", + "moulinette": ">= 2.4.0" + }, + "multi_instance": false, + "services": [ + "php5-fpm" + ], "arguments": { "install" : [ { "name": "domain", + "type": "domain", "ask": { "en": "Choose a domain for the web administration", "fr": "Choisissez un domaine pour l'administration web" @@ -24,6 +35,7 @@ }, { "name": "path", + "type": "path", "ask": { "en": "Choose a path for the web administration", "fr": "Choisissez un chemin pour l'administration web" @@ -42,6 +54,7 @@ }, { "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)" @@ -50,6 +63,7 @@ }, { "name": "firmware_nonfree", + "choice": ["yes", "no"], "ask": { "en": "Install non-free firmwares - in addition to the free ones - for the wifi dongle (yes/no)", "fr": "Installer des firmwares non-libres (en plus des libres) pour la clé USB wifi (yes/no)" diff --git a/scripts/helpers b/scripts/_common.sh similarity index 72% rename from scripts/helpers rename to scripts/_common.sh index f91730f..247bd4d 100644 --- a/scripts/helpers +++ b/scripts/_common.sh @@ -1,12 +1,18 @@ #!/bin/bash -source /usr/share/yunohost/helpers +# +# Common variables +# + +pkg_dependencies="php5-fpm 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" # # Helper to start/stop/.. a systemd service from a yunohost context, # *and* the systemd service itself needs to be able to run yunohost # commands. -# +# # Hence the need to release the lock during the operation # # usage : ynh_systemctl yolo restart @@ -24,7 +30,7 @@ function ynh_systemctl() # Save and release the lock... cp $LOCKFILE $LOCKFILE.bkp.$$ rm $LOCKFILE - + # Wait for the end of the action wait $SYSCTLACTION diff --git a/scripts/backup b/scripts/backup index 5761e69..f495de7 100644 --- a/scripts/backup +++ b/scripts/backup @@ -2,4 +2,18 @@ # nothing to do... -exit 0 +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors diff --git a/scripts/install b/scripts/install index 3d8e28a..931157a 100644 --- a/scripts/install +++ b/scripts/install @@ -1,75 +1,130 @@ #!/bin/bash -# Wifi Hotspot app for YunoHost +# Wifi Hotspot app for YunoHost # Copyright (C) 2015 Julien Vaubourg # Contribute at https://github.com/labriqueinternet/hotspot_ynh -# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -# This is an upgrade? -upgrade=$([ "${HOTSPOT_UPGRADE}" == 1 ] && echo true || echo false) +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# RETRIEVE ARGUMENTS FROM THE MANIFEST +#================================================= # Retrieve arguments -domain=${1} -url_path=${2} -wifi_ssid=${3} -wifi_passphrase=${4} -firmware_nonfree=${5} +domain=$YNH_APP_ARG_DOMAIN +path_url=$YNH_APP_ARG_PATH +wifi_ssid=$YNH_APP_ARG_WIFI_SSID +wifi_passphrase=$YNH_APP_ARG_WIFI_PASSPHRASE +firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE -if ! $upgrade; then +app=$YNH_APP_INSTANCE_NAME - source ./helpers - source ./prerequisites +#================================================= +# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS +#================================================= - # Check arguments - if [ -z "${wifi_ssid}" -o -z "${wifi_passphrase}" ]; then - echo "ERROR: Your Wifi Hotspot needs a name and a password" >&2 - exit 1 - fi - - wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)" - if [ "${wifi_passphrase_length}" -lt 8 -o "${wifi_passphrase_length}" -gt 63 ]; then - echo "ERROR: Your password must from 8 to 63 characters (WPA2 passphrase)" >&2 - exit 1 - fi - - echo "${wifi_passphrase}" | grep -qP '[^[:print:]]' - if [ $? -eq 0 ]; then - echo "ERROR: Only printable ASCII characters are permitted in your password (WPA2 passphrase)" >&2 - exit 1 - fi +# Check destination directory +final_path="/var/www/$app" +test ! -e "$final_path" || ynh_die "This path already contains a folder" +# Normalize the url path syntax +path_url=$(ynh_normalize_url_path "$path_url") + +# Check web path availability +ynh_webpath_available "$domain" "$path_url" +# Register (book) web path +ynh_webpath_register "$app" "$domain" "$path_url" + +#================================================= +# STORE SETTINGS FROM MANIFEST +#================================================= + +ynh_app_setting_set "$app" domain "$domain" +ynh_app_setting_set "$app" final_path "$final_path" +ynh_app_setting_set "$app" wifi_ssid "$wifi_ssid" +ynh_app_setting_set "$app" wifi_passphrase "$wifi_passphrase" +ynh_app_setting_set "$app" firmware_nonfree "$firmware_nonfree" + +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# INSTALL DEPENDENCIES +#================================================= + +ynh_install_app_dependencies "$pkg_dependencies" + +#================================================= +# SPECIFIC SETUP +#================================================= +# RUN PREREQUISITES +#================================================= + +source ./prerequisites + +#================================================= +# CHECK PARAMETERS +#================================================= + +# Check arguments +if [[ -z $wifi_ssid || -z $wifi_passphrase ]]; then + ynh_die "Your Wifi Hotspot needs a name and a password" fi - -# Check domain/path availability -ynh_webpath_register hotspot $domain $url_path || exit 1 -# Install packages -packages='php5-fpm sipcalc hostapd iptables iw dnsmasq' +# Check passphrase length +wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)" +if [[ $wifi_passphrase_length -lt 8 || $wifi_passphrase_length -gt 63 ]]; then + ynh_die "Your password must from 8 to 63 characters (WPA2 passphrase)" +fi + +# Check no special characters are present in the passphrase +if [[ $wifi_passphrase =~ [^[:print:]] ]]; then + ynh_die "Only printable ASCII characters are permitted in your password (WPA2 passphrase)" +fi + +#================================================= +# INSTALL NONFREE FIRWARE IF REQUESTED +#================================================= + export DEBIAN_FRONTEND=noninteractive # Packaged USB Wireless Device firmwares # Based on https://wiki.debian.org/WiFi#USB_Devices -if [ "${firmware_nonfree}" == yes ]; then +if [[ $firmware_nonfree == yes ]]; then # check if non-free is set on sources.list if ! grep -q non-free /etc/apt/sources.list ; then sudo sed '/debian/{s/main/& non-free/}' -i /etc/apt/sources.list fi - packages="$packages firmware-linux-free firmware-linux-nonfree firmware-atheros firmware-realtek firmware-ralink firmware-libertas atmel-firmware zd1211-firmware" + packages=$nonfree_packages else - packages="$packages firmware-linux-free" + 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 @@ -80,66 +135,76 @@ fi sudo apt-get --assume-yes --force-yes install ${packages} -if [ $? -ne 0 ]; then +if [[ $? -ne 0 ]]; then sudo apt-get update sudo apt-get --assume-yes --force-yes install ${packages} fi -if ! $upgrade; then +#================================================= +# CHECK PARAMETERS +#================================================= - # Compute extra arguments - if [ -z "${ip6_net}" ]; then - ip6_net=none - ip6_addr=none - - if [ -e /tmp/.ynh-vpnclient-started ]; then - vpnclient_ip6_net=$(sudo yunohost app setting vpnclient ip6_net 2>&1) - vpnclient_ip6_addr=$(sudo yunohost app setting vpnclient ip6_addr 2>&1) - - if [[ "${vpnclient_ip6_net}" =~ :: && "${vpnclient_ip6_addr}" =~ :: ]]; then - ip6_net=${vpnclient_ip6_net} - ip6_addr=${vpnclient_ip6_addr} - fi +if [[ ! -v ip6_net ]]; then # if ip6_net not set + ip6_net=none + ip6_addr=none + + if [[ -e /tmp/.ynh-vpnclient-started ]]; then + vpnclient_ip6_net=$(sudo yunohost app setting vpnclient ip6_net 2>&1) + vpnclient_ip6_addr=$(sudo yunohost app setting vpnclient ip6_addr 2>&1) + + if [[ $vpnclient_ip6_net =~ :: && $vpnclient_ip6_addr =~ :: ]]; then + ip6_net=${vpnclient_ip6_net} + ip6_addr=${vpnclient_ip6_addr} fi fi - - wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }') - - # Save arguments - - if [ -z "${wifi_device}" ]; then - sudo yunohost app setting hotspot service_enabled -v 0 - wifi_device=none - else - sudo yunohost app setting hotspot service_enabled -v 1 - fi - - sudo yunohost app setting hotspot multissid -v 1 - sudo yunohost app setting hotspot wifi_ssid -v "${wifi_ssid}" - sudo yunohost app setting hotspot wifi_secure -v 1 - sudo yunohost app setting hotspot wifi_passphrase -v "${wifi_passphrase}" - sudo yunohost app setting hotspot wifi_device -v "${wifi_device}" - sudo yunohost app setting hotspot wifi_channel -v 6 - sudo yunohost app setting hotspot ip6_addr -v "${ip6_addr}" - sudo yunohost app setting hotspot ip6_firewall -v 1 - sudo yunohost app setting hotspot ip6_net -v "${ip6_net}" - sudo yunohost app setting hotspot ip6_dns0 -v 2001:913::8 - sudo yunohost app setting hotspot ip6_dns1 -v 2001:910:800::12 - sudo yunohost app setting hotspot ip4_dns0 -v 80.67.188.188 - sudo yunohost app setting hotspot ip4_dns1 -v 80.67.169.12 - sudo yunohost app setting hotspot ip4_nat_prefix -v 10.0.242 - sudo yunohost app setting hotspot vpnclient -v no - fi -# Install custom scripts +wifi_device=$(sudo bash ../conf/iw_devices | awk -F\| '{ print $1 }') + +# Save arguments + +if [[ -z $wifi_device ]]; then + ynh_app_setting_set $app service_enabled -v 0 + wifi_device=none +else + ynh_app_setting_set $app service_enabled -v 1 +fi + +#================================================= +# SAVE SETTINGS +#================================================= + +ynh_app_setting_set $app multissid -v 1 +ynh_app_setting_set $app wifi_ssid -v "${wifi_ssid}" +ynh_app_setting_set $app wifi_secure -v 1 +ynh_app_setting_set $app wifi_passphrase -v "${wifi_passphrase}" +ynh_app_setting_set $app wifi_device -v "${wifi_device}" +ynh_app_setting_set $app wifi_channel -v 6 +ynh_app_setting_set $app ip6_addr -v "${ip6_addr}" +ynh_app_setting_set $app ip6_firewall -v 1 +ynh_app_setting_set $app ip6_net -v "${ip6_net}" +ynh_app_setting_set $app ip6_dns0 -v 2001:913::8 +ynh_app_setting_set $app ip6_dns1 -v 2001:910:800::12 +ynh_app_setting_set $app ip4_dns0 -v 80.67.188.188 +ynh_app_setting_set $app ip4_dns1 -v 80.67.169.12 +ynh_app_setting_set $app ip4_nat_prefix -v 10.0.242 +ynh_app_setting_set $app vpnclient -v no + + +#================================================= +# INSTALL CUSTOM SCRIPTS +#================================================= + sudo install -o root -g root -m 0755 ../conf/iw_multissid /usr/local/bin/ sudo install -o root -g root -m 0755 ../conf/iw_devices /usr/local/bin/ sudo install -o root -g root -m 0755 ../conf/iw_ssids /usr/local/bin/ sudo install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/ sudo install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/ -# Copy confs +#================================================= +# COPY CONFIGS +#================================================= + sudo mkdir -pm 0755 /var/log/nginx/ sudo mkdir -pm 0755 /etc/dnsmasq.dhcpd/ sudo chown root: /etc/dnsmasq.dhcpd/ @@ -150,7 +215,10 @@ sudo install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dn sudo install -b -o root -g root -m 0644 ../conf/nginx_wifiadmin.conf "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf" sudo install -b -o root -g root -m 0644 ../conf/phpfpm_wifiadmin.conf /etc/php5/fpm/pool.d/wifiadmin.conf -# Copy web sources +#================================================= +# COPY WEB SOURCES +#================================================= + sudo mkdir -pm 0755 /var/www/wifiadmin/ sudo cp -a ../sources/* /var/www/wifiadmin/ @@ -158,12 +226,15 @@ sudo chown -R root: /var/www/wifiadmin/ sudo chmod -R 0644 /var/www/wifiadmin/* sudo find /var/www/wifiadmin/ -type d -exec chmod +x {} \; -# Fix confs +#================================================= +# FIX CONFIGS +#================================================= + ## hostapd sudo sed 's|^DAEMON_CONF=$|&/etc/hostapd/hostapd.conf|' -i /etc/init.d/hostapd ## nginx -sudo sed "s||${url_path}|g" -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf" +sudo sed "s||${path_url}|g" -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf" sudo sed 's||/var/www/wifiadmin/|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf" sudo sed 's||wifiadmin|g' -i "/etc/nginx/conf.d/${domain}.d/wifiadmin.conf" @@ -174,44 +245,42 @@ sudo sed 's||admins|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf sudo sed 's||/var/www/wifiadmin/|g' -i /etc/php5/fpm/pool.d/wifiadmin.conf # Fix sources -sudo sed "s||${url_path}|g" -i /var/www/wifiadmin/config.php +sudo sed "s||${path_url}|g" -i /var/www/wifiadmin/config.php # Copy init script sudo install -o root -g root -m 0755 ../conf/ynh-hotspot /usr/local/bin/ sudo install -o root -g root -m 0644 ../conf/ynh-hotspot.service /etc/systemd/system/ # Update firewall for DHCP -sudo yunohost firewall allow --no-upnp --ipv6 UDP 547 -sudo yunohost firewall allow --no-upnp UDP 67 +yunohost firewall allow --no-upnp --ipv6 UDP 547 +yunohost firewall allow --no-upnp UDP 67 # Set default inits # The boot order of these services are important, so they are disabled by default # and the ynh-hotspot service handles them. -sudo systemctl disable hostapd -sudo systemctl stop hostapd -sudo systemctl enable php5-fpm -sudo systemctl restart php5-fpm -sudo systemctl reload nginx +systemctl disable hostapd +systemctl stop hostapd +systemctl enable php5-fpm +systemctl restart php5-fpm +systemctl reload nginx # Remove IPv6 address set if there is a VPN installed -if [ "${ip6_addr}" != none ]; then +if [[ $ip6_addr != none ]]; then sudo ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/" - if [ "$?" -eq 0 ]; then + if [[ "$?" -eq 0 ]]; then sudo ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null fi fi -sudo systemctl enable ynh-hotspot -sudo yunohost service add ynh-hotspot +systemctl enable ynh-hotspot +yunohost service add ynh-hotspot -if [ "${wifi_device}" == none ]; then +if [[ $wifi_device == none ]]; then echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2 fi -if ! $upgrade; then - ynh_systemctl start ynh-hotspot -fi +# start the app +ynh_systemctl start ynh-hotspot -sudo yunohost app ssowatconf - -exit 0 +# Reload SSOwat config +yunohost app ssowatconf diff --git a/scripts/prerequisites b/scripts/prerequisites index 5a22763..aad9c32 100644 --- a/scripts/prerequisites +++ b/scripts/prerequisites @@ -1,16 +1,8 @@ # Source me -# Check YunoHost version (dnsmasq) -ynh_version=$(sudo dpkg -l yunohost | grep ii | awk '{ print $3 }' | sed 's/\.//g') +# Check if dnsmasq is active +systemctl is-active dnsmasq &> /dev/null -if [ "${ynh_version}" -lt 220 ]; then - echo "ERROR: You need a YunoHost version equals or greater than 2.2.0" >&2 - exit 1 -fi - -sudo systemctl is-active dnsmasq &> /dev/null - -if [ $? -ne 0 ]; then - echo "ERROR: You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)" >&2 - exit 1 +if [[ $? -ne 0 ]]; then + ynh_die "You need to enable dnsmasq instead of bind9 (apt-get remove bind9 && systemctl start dnsmasq)" fi diff --git a/scripts/remove b/scripts/remove index 9d7681d..7d7c87d 100644 --- a/scripts/remove +++ b/scripts/remove @@ -1,31 +1,44 @@ #!/bin/bash -# Wifi Hotspot app for YunoHost +# Wifi Hotspot app for YunoHost # Copyright (C) 2015 Julien Vaubourg # Contribute at https://github.com/labriqueinternet/hotspot_ynh -# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. -# +# # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -source ./helpers +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= -# Retrieve arguments -domain=$(sudo yunohost app setting hotspot domain) +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get $app domain) +firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree) # The End -ynh_systemctl stop ynh-hotspot -sudo systemctl disable ynh-hotspot -sudo yunohost service remove ynh-hotspot +systemctl stop ynh-hotspot +systemctl disable ynh-hotspot +yunohost service remove ynh-hotspot sudo rm -f /etc/systemd/system/ynh-hotspot.service /usr/local/bin/ynh-hotspot sudo rm -f /tmp/.ynh-hotspot-* @@ -39,17 +52,23 @@ sudo rm -f /etc/hostapd/hostapd.conf{.tpl?,} sudo rm -f /etc/nginx/conf.d/${domain}.d/wifiadmin.conf sudo rm -f /etc/php5/fpm/pool.d/wifiadmin.conf -# Remove free firmwares -if ! dpkg -l firmware-atheros &> /dev/null; then - sudo rm -f /lib/firmware/htc_7010.fw - sudo rm -f /lib/firmware/htc_9271.fw +# Remove packages +if [[ $firmware_nonfree == yes ]]; then + packages=$nonfree_packages +else + packages=$free_packages + + # Remove free firmwares + if ! dpkg -l firmware-atheros &> /dev/null; then + sudo rm -f /lib/firmware/htc_7010.fw + sudo rm -f /lib/firmware/htc_9271.fw + fi fi +sudo apt-get --assume-yes --force-yes remove ${packages} # Restart services -sudo systemctl restart php5-fpm -sudo systemctl reload nginx +systemctl restart php5-fpm +systemctl reload nginx # Remove sources sudo rm -rf /var/www/wifiadmin/ - -exit 0 diff --git a/scripts/restore b/scripts/restore index 9e7d150..4af1fd5 100644 --- a/scripts/restore +++ b/scripts/restore @@ -1,5 +1,23 @@ #!/bin/bash +#================================================= +# GENERIC START +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= + gitcommit=$(sudo grep revision /etc/yunohost/apps/hotspot/status.json | sed 's/.*"revision": "\([^"]\+\)".*/\1/') tmpdir=$(mktemp -dp /tmp/ hotspot-restore-XXXXX) @@ -7,8 +25,6 @@ git clone https://github.com/labriqueinternet/hotspot_ynh.git "${tmpdir}/" git --work-tree "${tmpdir}/" --git-dir "${tmpdir}/.git/" reset --hard "${gitcommit}" cd "${tmpdir}/scripts/" -bash ./upgrade +bash ./upgrade sudo rm -r "${tmpdir}/" - -exit 0 diff --git a/scripts/upgrade b/scripts/upgrade index 5174922..dfedc7a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,46 +1,55 @@ #!/bin/bash -ynh_setting() { - app=${1} - setting=${2} +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= - sudo grep "^${setting}:" "/etc/yunohost/apps/${app}/settings.yml" | sed s/^[^:]\\+:\\s*[\"\']\\?// | sed s/\\s*[\"\']\$// -} +source _common.sh +source /usr/share/yunohost/helpers -domain=$(ynh_setting hotspot domain) -path=$(ynh_setting hotspot path) -wifi_ssid=$(ynh_setting hotspot wifi_ssid) -wifi_passphrase=$(ynh_setting hotspot wifi_passphrase) +#================================================= +# MANAGE SCRIPT FAILURE +#================================================= + +# Exit if an error occurs during the execution of the script +ynh_abort_if_errors + +#================================================= +# LOAD SETTINGS +#================================================= + +app=$YNH_APP_INSTANCE_NAME + +domain=$(ynh_app_setting_get $app domain) +path_url=$(ynh_app_setting_get $app path) +wifi_ssid=$(ynh_app_setting_get $app wifi_ssid) +wifi_passphrase=$(ynh_app_setting_get $app wifi_passphrase) +firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree) +final_path=$(ynh_app_setting_get $app final_path) +multissid=$(ynh_app_setting_get $app multissid) + +#================================================= +# CHECK THE PATH +#================================================= + +# Normalize the URL path syntax +path_url=$(ynh_normalize_url_path $path_url) + +#================================================= +# SPECIFIC UPGRADE +#================================================= -source ./helpers source ./prerequisites -if dpkg -l firmware-linux-nonfree &> /dev/null; then - firmware_nonfree=yes -else - firmware_nonfree=no -fi - -tmpdir=$(mktemp -dp /tmp/ hotspot-upgrade-XXXXX) -sudo cp -a /etc/yunohost/apps/hotspot/settings.yml "${tmpdir}/" - -export HOTSPOT_UPGRADE=1 -sudo bash /etc/yunohost/apps/hotspot/scripts/remove &> /dev/null -bash ./install "${domain}" "${path}" "${wifi_ssid}" "${wifi_passphrase}" "${firmware_nonfree}" - -sudo cp -a "${tmpdir}/settings.yml" /etc/yunohost/apps/hotspot/ -sudo rm -r "${tmpdir}/" - # Changes -if [ -z "$(ynh_setting hotspot ip6_firewall)" ]; then - multissid=$(ynh_setting hotspot multissid) +if [[ -z $(ynh_app_setting_get $app ip6_firewall) ]]; then ip6_firewall=$(printf '1|%.0s' $(seq "${multissid}")) ip6_firewall=$(echo "${ip6_firewall%?}") - sudo yunohost app setting hotspot ip6_firewall -v "${ip6_firewall}" + ynh_app_setting_set "${app}" ip6_firewall -v "${ip6_firewall}" fi ynh_systemctl start ynh-hotspot - -exit 0