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

156 lines
5.7 KiB
Text
Raw Normal View History

2016-08-15 15:38:50 +02:00
#!/bin/bash
2018-02-08 17:25:54 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
2020-11-18 17:59:20 +01:00
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
ynh_abort_if_errors
2016-08-15 15:38:50 +02:00
2020-11-18 17:59:20 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
2016-08-15 15:38:50 +02:00
2020-12-06 14:40:38 +01:00
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
2020-12-06 14:47:29 +01:00
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
2020-12-06 14:40:38 +01:00
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
admin=$(ynh_app_setting_get --app=$app --key=adminusername)
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
port=$(ynh_app_setting_get --app=$app --key=web_port)
#=================================================
# CHECK VERSION
#=================================================
upgrade_type=$(ynh_check_app_version_changed)
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
2016-08-15 15:38:50 +02:00
# Backup the current version of the app
2018-02-08 10:11:36 +01:00
ynh_backup_before_upgrade
ynh_clean_setup () {
2020-12-06 14:40:38 +01:00
# Restore it if the upgrade fails
2018-02-08 10:11:36 +01:00
ynh_restore_upgradebackup
}
2020-12-06 14:40:38 +01:00
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2020-12-06 14:40:38 +01:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --time --weight=1
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
2018-02-08 17:25:54 +01:00
#=================================================
2020-12-06 14:40:38 +01:00
# STANDARD UPGRADE STEPS
2018-02-08 17:25:54 +01:00
#=================================================
2020-12-06 14:40:38 +01:00
# Clean template to fix issue : https://github.com/gogits/gogs/issues/4585
ynh_secure_remove "/opt/$app/templates"
2020-12-06 14:40:38 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=3
2018-02-08 00:09:28 +01:00
2020-12-06 14:40:38 +01:00
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir=$final_path --source_id="$architecture"
ynh_backup_if_checksum_is_different "$final_path/custom/conf/app.ini"
ynh_backup_if_checksum_is_different "$final_path/custom/conf/auth.d/ldap.conf"
cp ../conf/app.ini "$final_path/custom/conf"
cp ../conf/ldap.conf "$final_path/custom/conf/auth.d/ldap.conf"
2020-12-06 14:40:38 +01:00
if [ "$path_url" = "/" ]
2018-02-08 17:25:54 +01:00
then
2020-12-06 14:40:38 +01:00
ynh_replace_string "__URL__" "$domain" "$final_path/custom/conf/app.ini"
else
ynh_replace_string "__URL__" "$domain${path_url%/}" "$final_path/custom/conf/app.ini"
2018-02-08 17:25:54 +01:00
fi
2020-12-06 14:40:38 +01:00
ynh_replace_string "__REPOS_PATH__" "$REPO_PATH" "$final_path/custom/conf/app.ini"
ynh_replace_string "__DB_PASSWORD__" "$dbpass" "$final_path/custom/conf/app.ini"
ynh_replace_string "__DB_USER__" "$dbuser" "$final_path/custom/conf/app.ini"
ynh_replace_string "__DOMAIN__" "$domain" "$final_path/custom/conf/app.ini"
ynh_replace_string "__KEY__" "$key" "$final_path/custom/conf/app.ini"
ynh_replace_string "__DATA_PATH__" "$DATA_PATH" "$final_path/custom/conf/app.ini"
ynh_replace_string "__PORT__" $port "$final_path/custom/conf/app.ini"
ynh_replace_string "__APP__" $app "$final_path/custom/conf/app.ini"
if [[ "$is_public" = '1' ]]
2018-06-07 22:18:45 +02:00
then
2020-12-06 14:40:38 +01:00
ynh_replace_string "__PRIVATE_MODE__" "false" "$final_path/custom/conf/app.ini"
else
ynh_replace_string "__PRIVATE_MODE__" "true" "$final_path/custom/conf/app.ini"
2018-06-07 22:18:45 +02:00
fi
2020-12-06 14:40:38 +01:00
ynh_replace_string "__ADMIN__" "$admin" "$final_path/custom/conf/auth.d/ldap.conf"
ynh_store_file_checksum "$final_path/custom/conf/app.ini"
ynh_store_file_checksum "$final_path/custom/conf/auth.d/ldap.conf"
2018-02-08 17:25:54 +01:00
#=================================================
2020-12-06 14:40:38 +01:00
# SETUP SYSTEMD
2018-02-08 17:25:54 +01:00
#=================================================
2020-12-06 14:40:38 +01:00
ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1
2018-02-08 17:25:54 +01:00
2020-12-06 14:40:38 +01:00
# Create a dedicated systemd config
ynh_add_systemd_config
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --time --weight=1
2018-02-08 11:42:15 +01:00
2020-12-06 14:40:38 +01:00
# Create a dedicated NGINX config
ynh_add_nginx_config
2016-08-15 15:38:50 +02:00
2020-12-06 14:40:38 +01:00
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
2016-08-15 15:38:50 +02:00
2020-12-06 14:40:38 +01:00
chown -R $app:$app "$final_path"
chown -R $app:$app "/home/$app"
chown -R $app:$app "/var/log/$app"
chmod u=rwX,g=rX,o= "$final_path"
chmod u=rwX,g=rX,o= "/home/$app"
chmod u=rwX,g=rX,o= "/var/log/$app"
2016-08-15 15:38:50 +02:00
2020-12-06 14:40:38 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2020-12-06 14:47:29 +01:00
yunohost service add $app --description="Lightweight Git forge" --log="/var/log/$app/$app.log"
2016-08-15 15:38:50 +02:00
2018-02-08 17:25:54 +01:00
#=================================================
2020-12-06 14:40:38 +01:00
# RELOAD NGINX
2018-02-08 17:25:54 +01:00
#=================================================
2020-12-06 14:40:38 +01:00
ynh_script_progression --message="Reloading NGINX web server..." --time --weight=1
2016-08-15 15:38:50 +02:00
2020-12-06 14:40:38 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2018-04-25 10:52:42 +02:00
2020-12-06 14:40:38 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2016-10-16 16:43:48 +02:00
2020-12-06 14:40:38 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last