2015-07-13 15:59:05 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
2019-02-23 23:47:45 +01:00
|
|
|
# GENERIC START
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2015-07-24 19:09:56 +02:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2015-07-13 15:59:05 +02:00
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2018-05-04 00:33:01 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
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)
|
|
|
|
phpversion=$(ynh_app_setting_get --app=$app --key=phpversion)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2019-02-23 23:47:45 +01:00
|
|
|
|
2021-05-22 11:53:07 +02:00
|
|
|
#=================================================
|
|
|
|
# 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"
|
|
|
|
|
2019-02-23 23:47:45 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2019-02-23 23:47:45 +01:00
|
|
|
|
2020-06-02 23:50:44 +02:00
|
|
|
if [ -z $phpversion ]; then
|
2020-11-29 03:42:47 +01:00
|
|
|
phpversion=$YNH_PHP_VERSION
|
2020-06-02 23:50:44 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=phpversion --value=$phpversion
|
|
|
|
fi
|
|
|
|
|
2019-02-23 23:47:45 +01:00
|
|
|
# If final_path doesn't exist, create it
|
2020-05-31 05:33:17 +02:00
|
|
|
if [ -z "$final_path" ]; then
|
2019-02-23 23:47:45 +01:00
|
|
|
final_path=/var/www/$app
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
|
2019-02-23 23:47:45 +01:00
|
|
|
fi
|
|
|
|
|
2019-03-10 23:39:25 +01:00
|
|
|
if [ -d /var/www/wifiadmin/ ]; then
|
|
|
|
mv /var/www/wifiadmin $final_path
|
2020-05-31 05:33:17 +02:00
|
|
|
mv /etc/php/7.0/fpm/pool.d/wifiadmin.conf /etc/php/$phpversion/fpm/pool.d/$app.conf
|
|
|
|
ynh_replace_string --match_string="wifiadmin" --replace_string="$app" --target_file=/etc/php/$phpversion/fpm/pool.d/$app.conf
|
|
|
|
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
|
2019-03-10 23:39:25 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $firmware_nonfree = "yes" ]; then
|
|
|
|
firmware_nonfree=1
|
2020-06-02 23:50:44 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree
|
2019-03-10 23:39:25 +01:00
|
|
|
elif [ $firmware_nonfree = "no" ]; then
|
|
|
|
firmware_nonfree=0
|
2020-06-02 23:50:44 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=firmware_nonfree --value=$firmware_nonfree
|
2019-03-10 23:39:25 +01:00
|
|
|
fi
|
|
|
|
|
2019-03-11 00:44:58 +01:00
|
|
|
if [ -z $service_name ]; then
|
|
|
|
service_name="ynh-hotspot"
|
2020-06-02 23:50:44 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=service_name --value=$service_name
|
2019-03-11 00:44:58 +01:00
|
|
|
fi
|
|
|
|
|
2021-05-15 20:52:43 +02:00
|
|
|
#=================================================
|
|
|
|
# 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 --home_dir=$final_path
|
|
|
|
|
2019-02-23 23:47:45 +01:00
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
|
|
then
|
|
|
|
ynh_script_progression --message="Upgrading source files..."
|
|
|
|
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
|
|
cp -a ../sources/* ${final_path}/
|
|
|
|
fi
|
2019-02-23 23:47:45 +01:00
|
|
|
|
2021-05-22 11:53:07 +02:00
|
|
|
# Restore permissions on app files
|
|
|
|
chmod -R 0644 ${final_path}/*
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:$app "$final_path"
|
|
|
|
|
2019-02-23 23:47:45 +01:00
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2019-02-23 23:47:45 +01:00
|
|
|
|
2021-05-15 20:52:43 +02:00
|
|
|
# Create a dedicated NGINX config
|
2019-02-23 23:47:45 +01:00
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2019-02-23 23:47:45 +01:00
|
|
|
|
2019-02-26 01:27:39 +01:00
|
|
|
if [[ $firmware_nonfree -eq 1 ]]; then
|
2021-05-15 20:52:43 +02:00
|
|
|
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"
|
2019-02-26 01:27:39 +01:00
|
|
|
else
|
2021-05-15 20:52:43 +02:00
|
|
|
pkg_dependencies="$pkg_dependencies $free_firmware_packages"
|
2019-02-26 01:27:39 +01:00
|
|
|
fi
|
|
|
|
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2019-02-23 23:47:45 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# PHP-FPM CONFIGURATION
|
|
|
|
#=================================================
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_script_progression --message="Upgrading PHP-FPM configuration..."
|
2019-02-23 23:47:45 +01:00
|
|
|
|
2021-05-15 20:52:43 +02:00
|
|
|
# Create a dedicated PHP-FPM config
|
2019-02-23 23:47:45 +01:00
|
|
|
ynh_add_fpm_config
|
|
|
|
|
2018-05-04 00:33:01 +02:00
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
# 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"
|
|
|
|
|
|
|
|
#=================================================
|
2021-05-15 20:52:43 +02:00
|
|
|
# UPDATE A CONFIG FILE
|
2019-02-23 23:47:45 +01:00
|
|
|
#=================================================
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
2018-05-04 00:33:01 +02:00
|
|
|
|
2021-03-27 12:22:28 +01:00
|
|
|
ynh_add_config --template="config.php.tpl" --destination="$final_path/config.php"
|
2021-05-15 20:52:43 +02:00
|
|
|
|
|
|
|
chmod 400 "$final_path/config.php"
|
2021-05-13 16:19:09 +02:00
|
|
|
chown $app:$app "$final_path/config.php"
|
2015-07-26 10:43:44 +02:00
|
|
|
|
2019-02-23 23:47:45 +01:00
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2015-07-24 23:48:24 +02:00
|
|
|
|
2019-02-23 23:47:45 +01:00
|
|
|
# Create a dedicated systemd config
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_add_systemd_config --service=$service_name
|
2015-07-24 23:48:24 +02:00
|
|
|
|
2019-02-23 23:47:45 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
2020-05-31 05:33:17 +02:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
|
2021-05-15 20:52:43 +02:00
|
|
|
yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd" --needs_exposed_ports 67 547
|
2020-05-31 05:33:17 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
|
2021-03-17 01:03:07 +01:00
|
|
|
hot_reload_usb_wifi_cards
|
2020-05-31 05:33:17 +02:00
|
|
|
wifi_device=$(bash ../conf/iw_devices | awk -F\| '{ print $1 }')
|
|
|
|
|
|
|
|
if [[ -z $wifi_device ]]; then
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=service_enabled --value=0
|
|
|
|
wifi_device=none
|
2020-05-31 05:33:17 +02:00
|
|
|
else
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=service_enabled --value=1
|
2020-05-31 05:33:17 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Start a systemd service if device is present
|
|
|
|
if [[ $wifi_device == none ]]; then
|
2021-05-15 20:52:43 +02:00
|
|
|
echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
|
2020-05-31 05:33:17 +02:00
|
|
|
else
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd #--line_match="Started YunoHost Wifi Hotspot"
|
2020-05-31 05:33:17 +02:00
|
|
|
fi
|
|
|
|
|
2019-02-23 23:47:45 +01:00
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2021-05-15 20:52:43 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2019-02-23 23:47:45 +01:00
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-02-23 23:47:45 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
2015-07-24 23:48:24 +02:00
|
|
|
|
2020-05-31 05:33:17 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|