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

144 lines
4.5 KiB
Text
Raw Normal View History

2018-04-03 19:00:18 +02:00
#!/bin/bash
#=================================================
# GENERIC STARTING
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source _variables
#=================================================
# LOAD 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)
port=$(ynh_app_setting_get $app port)
#=================================================
# CHECK VERSION
#=================================================
# Wait for etherpad to be fully started
2018-04-03 19:18:35 +02:00
# ynh_check_starting "You can access your Etherpad instance at" "/var/log/$app/etherpad.log" "120"
2018-04-03 19:00:18 +02:00
ynh_abort_if_up_to_date
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# Cleanup installatioNettoyage des résidus d'installation non pris en charge par le script remove.
ynh_clean_check_starting
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# STOP ETHERPAD
#=================================================
systemctl stop $app
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_setup_source "$final_path" # Download, check integrity and uncompress the source from app.src
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_replace_string "__PATH__/" "${path_url%/}/" "../conf/nginx.conf"
ynh_add_nginx_config
#=================================================
# UPGRADE NODEJS
#=================================================
ynh_install_nodejs $nodejs_version
#=================================================
# UPGRADE NPM MODULES
#=================================================
nodedir=$(ynh_get_nodejs_bindir $nodejs_version)
PATH=$nodedir:$PATH npm cache clean
PATH=$nodedir:$PATH npm update
2018-04-03 19:00:18 +02:00
#=================================================
# SPECIFIC UPGRADE
#=================================================
# CONFIGURE ETHERPAD
#=================================================
2018-04-03 19:18:35 +02:00
ynh_backup_if_checksum_is_different "$final_path/config/app.json"
ynh_backup_if_checksum_is_different "$final_path/config/db.json"
cp ../conf/app.json "$final_path/config/app.json"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/config/app.json"
cp ../conf/db.json "$final_path/config/db.json"
2018-04-03 19:00:18 +02:00
2018-04-03 19:18:35 +02:00
ynh_store_file_checksum "$final_path/config/app.json"
ynh_store_file_checksum "$final_path/config/db.json"
2018-04-03 19:00:18 +02:00
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_system_user_create $app $final_path # Create the dedicated user, if it doesn't exist
#=================================================
# SECURING FILES AND DIRECTORIES
#=================================================
# Set files ownership to etherpad
chown -R $app: $final_path
2018-04-03 19:18:35 +02:00
chmod 600 "$final_path/config/db.json" # Restrict access to credentials.json
chown $app -R /var/log/$app/timeoff.log
2018-04-03 19:00:18 +02:00
#=================================================
# UPGRADE FAIL2BAN
#=================================================
2018-04-03 19:18:35 +02:00
# ynh_add_fail2ban_config "/var/log/nginx/$domain-access.log" "<HOST> .* \"POST /mypads/api/auth/login HTTP/1.1\" 400" 5
2018-04-03 19:00:18 +02:00
#=================================================
# SETUP LOGROTATE
#=================================================
ynh_use_logrotate --non-append
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_replace_string "__NODEJS__" "$nodejs_use_version" "../conf/systemd.service"
ynh_replace_string "__ENV_PATH__" "$PATH" "../conf/systemd.service"
2018-04-03 19:18:35 +02:00
ynh_replace_string "__PORT__" "$port" "../conf/systemd.service"
ynh_replace_string "__FINAL_PATH__" "$final_path" "../conf/systemd.service"
2018-04-03 19:00:18 +02:00
ynh_add_systemd_config
systemctl restart $app.service
2018-04-03 19:00:18 +02:00
#=================================================
# RELOAD NGINX
#=================================================
systemctl reload nginx