#!/bin/bash #================================================= # GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= ynh_print_info "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get $app domain) path_url=$(ynh_app_setting_get $app path) final_path=$(ynh_app_setting_get $app final_path) firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree) service_name=$(ynh_app_setting_get $app service_name) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= ynh_print_info "Ensuring downward compatibility..." # If final_path doesn't exist, create it if [ -z $final_path ]; then final_path=/var/www/$app ynh_app_setting_set $app final_path $final_path fi if [ -d /var/www/wifiadmin/ ]; then mv /var/www/wifiadmin $final_path mv /etc/php/7.0/fpm/pool.d/wifiadmin.conf /etc/php/7.0/fpm/pool.d/$app.conf ynh_replace_string "wifiadmin" "$app" /etc/php/7.0/fpm/pool.d/$app.conf systemctl reload php7.0-fpm fi if [ $firmware_nonfree = "yes" ]; then firmware_nonfree=1 ynh_app_setting_set $app firmware_nonfree $firmware_nonfree elif [ $firmware_nonfree = "no" ]; then firmware_nonfree=0 ynh_app_setting_set $app firmware_nonfree $firmware_nonfree fi if [ -z $service_name ]; then service_name="ynh-hotspot" ynh_app_setting_set $app service_name $service_name fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= ynh_print_info "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 #================================================= # CHECK THE PATH #================================================= # Normalize the URL path syntax path_url=$(ynh_normalize_url_path $path_url) #================================================= # STANDARD UPGRADE STEPS #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_print_info "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src cp -a ../sources/* ${final_path}/ #================================================= # NGINX CONFIGURATION #================================================= ynh_print_info "Upgrading nginx web server configuration..." # Create a dedicated nginx config ynh_add_nginx_config #================================================= # UPGRADE DEPENDENCIES #================================================= ynh_print_info "Upgrading dependencies..." if [[ $firmware_nonfree -eq 1 ]]; then packages=$nonfree_packages else packages=$free_packages fi ynh_install_app_dependencies "$pkg_dependencies" "$packages" #================================================= # CREATE DEDICATED USER #================================================= ynh_print_info "Making sure dedicated system user exists..." # Create a dedicated user (if not existing) ynh_system_user_create $app #================================================= # PHP-FPM CONFIGURATION #================================================= ynh_print_info "Upgrading php-fpm configuration..." # Create a dedicated php-fpm config ynh_add_fpm_config #================================================= # SPECIFIC UPGRADE #================================================= # FIX CONFIGS #================================================= ### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. ynh_backup_if_checksum_is_different "$final_path/config.php" ynh_replace_string "__PATH__" "${path_url}" "$final_path/config.php" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum "$final_path/config.php" #================================================= # SETUP SYSTEMD #================================================= ynh_print_info "Upgrading systemd configuration..." # Create a dedicated systemd config ynh_add_systemd_config $service_name # Make sure that the yunohost service has a description and need-lock enabled yunohost service add $service_name --description "Creates a Wi-Fi access point" --need_lock yunohost service start $service_name #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= # Set permissions on app files chown -R $app: ${final_path}/ chmod -R 0644 ${final_path}/* find ${final_path}/ -type d -exec chmod +x {} \; #================================================= # RELOAD NGINX #================================================= ynh_print_info "Reloading nginx web server..." systemctl restart php7.0-fpm systemctl reload nginx #================================================= # END OF SCRIPT #================================================= ynh_print_info "Upgrade of $app completed"