1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/yourls_ynh.git synced 2024-09-03 20:35:59 +02:00
yourls_ynh/scripts/upgrade

127 lines
3.6 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
admin=$(ynh_app_setting_get $app admin)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
if [ -z $db_name ]; then # If db_name doesn't exist, create it
db_name=$(ynh_sanitize_dbid $app)
ynh_app_setting_set $app db_name $db_name
fi
2018-06-04 22:57:21 +02:00
# 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
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# 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
#=================================================
2018-06-04 22:57:21 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2018-06-07 21:28:54 +02:00
# Create a temporary directory along with /user/plugin sub directory in it
2018-06-04 22:57:21 +02:00
tmpdir="$(mktemp -d)"
2018-06-09 14:02:58 +02:00
mkdir -p "$tmpdir/user/"
2018-06-04 22:57:21 +02:00
# Backup the app files in the temp dir
2018-06-09 14:02:58 +02:00
sudo cp -a "$final_path/index.php" "$tmpdir"
2018-06-04 22:57:21 +02:00
sudo cp -a "$final_path/.htaccess" "$tmpdir"
sudo cp -a "$final_path/user/config.php" "$tmpdir/user"
# Remove the app directory securely
ynh_secure_remove "$final_path"
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source "$final_path"
2018-06-04 22:57:21 +02:00
# Copy the app files from tmp to final_path
2018-06-09 14:02:58 +02:00
sudo cp -a "$tmpdir/index.php" "$final_path"
2018-06-04 22:57:21 +02:00
sudo cp -a "$tmpdir/.htaccess" "$final_path"
sudo cp -a "$tmpdir/user/config.php" "$final_path/user"
#remove tmp dir
sudo rm -Rf "$tmpdir"
#=================================================
# NGINX CONFIGURATION
#=================================================
# Create a dedicated nginx config
2018-06-04 22:57:21 +02:00
ynh_add_nginx_config
2018-06-04 22:57:21 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
# Create a system user
ynh_system_user_create $app
#=================================================
2018-06-04 22:57:21 +02:00
# PHP-FPM CONFIGURATION
#=================================================
2018-06-04 22:57:21 +02:00
# Create a dedicated php-fpm config
ynh_add_fpm_config
2018-06-04 22:57:21 +02:00
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "$final_path/user/config.php"
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/user/config.php"
# Set right permissions for curl installation
chown -R $app: $final_path
2018-06-04 22:57:21 +02:00
#=================================================
# SETUP SSOWAT
#=================================================
ynh_app_setting_set $app unprotected_uris "/"
2018-06-09 14:02:58 +02:00
#=================================================
# RELOAD NGINX
#=================================================
sudo systemctl reload nginx