#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= 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) #================================================= # 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 #================================================= # STOP SYSTEMD SERVICE #================================================= ynh_script_progression --message="Stopping a systemd service..." ynh_systemd_action --service_name=$service_name --action="stop" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_script_progression --message="Ensuring downward compatibility..." if [ -d /etc/nginx/conf.d/*.d/$app.conf ]; then ynh_secure_remove /etc/nginx/conf.d/*.d/$app.conf fi if [ -d /etc/php/*/fpm/pool.d/$app.conf ]; then ynh_secure_remove /etc/php/*/fpm/pool.d/$app.conf fi if [ -d /var/www/$app ]; then ynh_secure_remove /var/www/$app fi if [ -d /var/www/wifiadmin/ ]; then ynh_secure_remove /var/www/wifiadmin/ fi 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 firmware_nonfree=0 ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree fi if [ -z $service_name ]; then service_name="ynh-hotspot" ynh_app_setting_set --app=$app --key=service_name --value=$service_name 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 #================================================= # COPY CONFIGS #================================================= ynh_script_progression --message="Copying configuration..." mkdir -pm 0755 /etc/dnsmasq.dhcpd/ chown root: /etc/dnsmasq.dhcpd/ install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl? /etc/hostapd/ install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl # 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" #================================================= # SETUP SYSTEMD #================================================= ynh_script_progression --message="Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config --service=$service_name #================================================= # 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" #================================================= # 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 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 else ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot" fi #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Upgrade of $app completed"