1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/haste_ynh.git synced 2024-09-03 20:36:28 +02:00
haste_ynh/scripts/upgrade
2017-11-29 15:42:21 +01:00

172 lines
4.8 KiB
Bash
Executable file

#!/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_url)
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)
#=================================================
# STOP HASTE
#=================================================
systemctl stop $app
#=================================================
# 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
#=================================================
# SPECIFIC UPGRADE
#=================================================
# UPGRADE NODEJS
#=================================================
ynh_install_nodejs 4
#=================================================
# UPGRADE NPM MODULES
#=================================================
npm cache clean
npm update
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_use_logrotate
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
ynh_replace_string "__NODEPATH__" "$(dirname "$nodejs_path")" "../conf/systemd.service"
ynh_add_systemd_config
#=================================================
# UPGRADE HASTE CONFIGURATION
#=================================================
# Verify the checksum and backup the file if it's different
ynh_backup_if_checksum_is_different "$final_path/config.js"
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"
# Recalculate and store the config file checksum into the app settings
ynh_store_file_checksum "$final_path/config.js"
#=================================================
# UPGRADE HASTE BINARY
#=================================================
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"
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
chown -R root: $final_path
chown -R $app "$final_path/static"
chown -R $app "$data_path"
#=================================================
# START HASTEBIN
#=================================================
systemctl start $app
#=================================================
# SETUP SSOWAT
#=================================================
if [ $is_public -eq 1 ];
then
ynh_app_setting_set $app skipped_uris "/"
fi
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx