2016-10-25 23:34:42 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-10-14 16:28:52 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2017-10-14 16:28:52 +02:00
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2017-10-14 16:28:52 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2017-10-14 16:28:52 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-10-25 23:34:42 +02:00
|
|
|
|
2017-10-14 16:28:52 +02:00
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
2017-10-14 16:43:37 +02:00
|
|
|
path_url=$(ynh_app_setting_get $app path_url)
|
2017-10-14 16:28:52 +02:00
|
|
|
is_public=$(ynh_app_setting_get $app is_public)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
port=$(ynh_app_setting_get $app port)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Fix is_public as a boolean value
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
|
|
|
ynh_app_setting_set $app is_public 1
|
|
|
|
is_public=1
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
|
|
|
ynh_app_setting_set $app is_public 0
|
|
|
|
is_public=0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# STOP HASTE
|
2017-10-14 16:28:52 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
systemctl stop $app
|
|
|
|
|
2017-10-14 16:28:52 +02:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_setup_source "$final_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CREATE DEDICATED USER
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_system_user_create $app
|
|
|
|
|
2017-10-14 16:36:30 +02:00
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE NODEJS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_install_nodejs 4
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE NPM MODULES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
npm cache clean
|
|
|
|
npm update
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_use_logrotate
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
2017-10-14 16:36:30 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
|
|
|
|
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
|
2017-11-29 15:42:21 +01:00
|
|
|
ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" "../conf/systemd.service"
|
|
|
|
|
2017-10-14 16:36:30 +02:00
|
|
|
ynh_add_systemd_config
|
2017-11-29 15:42:21 +01:00
|
|
|
|
2017-10-14 16:28:52 +02:00
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# UPGRADE HASTE CONFIGURATION
|
2017-10-14 16:28:52 +02:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Verify the checksum and backup the file if it's different
|
|
|
|
ynh_backup_if_checksum_is_different "$final_path/config.js"
|
2017-11-29 15:42:21 +01:00
|
|
|
|
|
|
|
cp ../conf/config.js "$final_path/config.js"
|
|
|
|
ynh_replace_string "__PORT__" "$port" "$final_path/config.js"
|
|
|
|
data_path="/home/yunohost.app/$app"
|
|
|
|
ynh_replace_string "__YNH_DATA_PATH__" "$data_path" "$final_path/config.js"
|
|
|
|
|
2017-10-14 16:28:52 +02:00
|
|
|
# Recalculate and store the config file checksum into the app settings
|
|
|
|
ynh_store_file_checksum "$final_path/config.js"
|
|
|
|
|
|
|
|
#=================================================
|
2017-11-29 15:42:21 +01:00
|
|
|
# UPGRADE HASTE BINARY
|
2017-10-14 16:28:52 +02:00
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
ynh_replace_string "__YNH_HASTE_URL__" "${domain}${path_url}" "../conf/haste.sh"
|
|
|
|
sudo cp ../conf/haste.sh /usr/bin/$app
|
|
|
|
sudo chmod +x /usr/bin/"$app"
|
2017-10-14 16:28:52 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SECURE FILES AND DIRECTORIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
chown -R root: $final_path
|
2017-11-29 15:42:21 +01:00
|
|
|
chown -R $app "$final_path/static"
|
|
|
|
chown -R $app "$data_path"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START HASTEBIN
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
systemctl start $app
|
2017-10-14 16:28:52 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SSOWAT
|
|
|
|
#=================================================
|
|
|
|
|
2017-11-29 15:42:21 +01:00
|
|
|
if [ $is_public -eq 1 ];
|
2017-10-14 16:28:52 +02:00
|
|
|
then
|
2017-11-29 15:42:21 +01:00
|
|
|
ynh_app_setting_set $app skipped_uris "/"
|
2017-10-14 16:28:52 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
systemctl reload nginx
|