1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/hotspot_ynh.git synced 2024-09-03 19:25:53 +02:00
hotspot_ynh/scripts/upgrade

158 lines
4.8 KiB
Text
Raw Normal View History

2015-07-13 15:59:05 +02:00
#!/bin/bash
#=================================================
2019-02-23 23:47:45 +01:00
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2015-07-24 19:09:56 +02:00
source _common.sh
source /usr/share/yunohost/helpers
2015-07-13 15:59:05 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
2019-02-23 23:47:45 +01:00
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)
2019-02-23 23:47:45 +01:00
firmware_nonfree=$(ynh_app_setting_get $app firmware_nonfree)
packages=$(ynh_app_setting_get $app packages)
#=================================================
# 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 [ -z $packages ]; then
if [[ $firmware_nonfree -eq 1 ]]; then
packages=$nonfree_packages
else
packages=$free_packages
fi
ynh_app_setting_set $app packages $packages
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
2015-07-13 15:59:05 +02:00
#=================================================
# CHECK THE PATH
#=================================================
2015-07-26 10:43:44 +02:00
# Normalize the URL path syntax
path_url=$(ynh_normalize_url_path $path_url)
2015-07-13 15:59:05 +02:00
2019-02-23 23:47:45 +01:00
#=================================================
# 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}/
chown -R www-data: ${final_path}/
chmod -R 0644 ${final_path}/*
find ${final_path}/ -type d -exec chmod +x {} \;
#=================================================
# 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..."
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
#=================================================
2019-02-23 23:47:45 +01:00
# FIX CONFIGS
#=================================================
2019-02-23 23:47:45 +01:00
### 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"
2015-07-26 10:43:44 +02:00
2019-02-23 23:47:45 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_print_info "Upgrading systemd configuration..."
2015-07-24 23:48:24 +02:00
2019-02-23 23:47:45 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config
2015-07-24 23:48:24 +02:00
2019-02-23 23:47:45 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions on app files
chown -R www-data: $final_path
#=================================================
# SETUP SSOWAT
#=================================================
ynh_print_info "Upgrading SSOwat configuration..."
#=================================================
# RELOAD NGINX
#=================================================
ynh_print_info "Reloading nginx web server..."
systemctl restart php7.0-fpm
systemctl reload nginx
#=================================================
# END OF SCRIPT
#=================================================
2015-07-24 23:48:24 +02:00
2019-02-23 23:47:45 +01:00
ynh_print_info "Upgrade of $app completed"