2016-08-15 15:38:50 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
2018-02-07 00:31:25 +01:00
|
|
|
# IMPORT GENERIC HELPERS
|
2020-11-18 17:59:20 +01:00
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2018-02-07 00:31:25 +01:00
|
|
|
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)
|
2020-12-30 15:07:15 +01:00
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
2020-12-29 23:52:57 +01:00
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
2020-12-06 15:04:29 +01:00
|
|
|
architecture=$(ynh_detect_arch)
|
2021-11-06 19:10:24 +01:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
|
|
|
|
2020-12-06 14:40:38 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# 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
|
|
|
|
2018-02-07 00:31:25 +01: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
|
2018-02-07 00:31:25 +01:00
|
|
|
|
2021-11-06 19:10:24 +01:00
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
|
|
|
|
# Cleaning legacy permissions
|
|
|
|
if ynh_legacy_permissions_exists; then
|
|
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
|
|
fi
|
|
|
|
|
2020-12-06 14:40:38 +01:00
|
|
|
#=================================================
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2020-12-06 15:08:51 +01:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=2
|
2020-12-06 14:40:38 +01:00
|
|
|
|
|
|
|
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
|
2021-08-14 23:09:55 +02:00
|
|
|
ynh_secure_remove --file="/opt/$app/templates"
|
2018-02-07 00:31:25 +01:00
|
|
|
|
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
|
|
|
|
2021-11-06 23:44:53 +01:00
|
|
|
REPO_PATH="$datadir/repositories"
|
2021-11-06 19:10:24 +01:00
|
|
|
DATA_PATH="$datadir/data"
|
2020-12-06 15:23:22 +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"
|
|
|
|
|
2021-08-14 23:17:26 +02:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
|
|
|
|
2020-12-06 14:40:38 +01:00
|
|
|
ynh_backup_if_checksum_is_different "$final_path/custom/conf/app.ini"
|
|
|
|
|
|
|
|
cp ../conf/app.ini "$final_path/custom/conf"
|
2016-10-11 22:11:21 +02:00
|
|
|
|
2020-12-06 14:40:38 +01:00
|
|
|
if [ "$path_url" = "/" ]
|
2018-02-08 17:25:54 +01:00
|
|
|
then
|
2020-12-30 15:07:15 +01:00
|
|
|
ynh_replace_string --match_string="__URL__" --replace_string="$domain" --target_file="$final_path/custom/conf/app.ini"
|
2020-12-06 14:40:38 +01:00
|
|
|
else
|
2020-12-30 15:07:15 +01:00
|
|
|
ynh_replace_string --match_string="__URL__" --replace_string="$domain${path_url%/}" --target_file="$final_path/custom/conf/app.ini"
|
2018-02-08 17:25:54 +01:00
|
|
|
fi
|
|
|
|
|
2021-06-25 18:42:27 +02:00
|
|
|
ynh_replace_string --match_string="__REPOS_PATH__" --replace_string="$REPO_PATH" --target_file="$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string --match_string="__DB_PWD__" --replace_string="$db_pwd" --target_file="$final_path/custom/conf/app.ini"
|
2021-11-06 19:10:24 +01:00
|
|
|
ynh_replace_string --match_string="__DB_NAME__" --replace_string="$db_name" --target_file="$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string --match_string="__DB_USER__" --replace_string="$db_user" --target_file="$final_path/custom/conf/app.ini"
|
2021-06-25 18:42:27 +02:00
|
|
|
ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string --match_string="__KEY__" --replace_string="$(ynh_string_random)" --target_file="$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string --match_string="__DATA_PATH__" --replace_string="$DATA_PATH" --target_file="$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_file="$final_path/custom/conf/app.ini"
|
|
|
|
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="$final_path/custom/conf/app.ini"
|
2020-12-06 14:40:38 +01:00
|
|
|
|
|
|
|
if [[ "$is_public" = '1' ]]
|
2018-06-07 22:18:45 +02:00
|
|
|
then
|
2020-12-06 14:56:01 +01:00
|
|
|
ynh_replace_string --match_string="__PRIVATE_MODE__" --replace_string="false" --target_file="$final_path/custom/conf/app.ini"
|
2020-12-06 14:40:38 +01:00
|
|
|
else
|
2020-12-06 14:56:01 +01:00
|
|
|
ynh_replace_string --match_string="__PRIVATE_MODE__" --replace_string="true" --target_file="$final_path/custom/conf/app.ini"
|
2018-06-07 22:18:45 +02:00
|
|
|
fi
|
|
|
|
|
2021-04-23 07:57:08 +02:00
|
|
|
ynh_add_config --template="../conf/ldap.conf" --destination="$final_path/custom/conf/auth.d/ldap.conf"
|
2020-12-06 14:40:38 +01:00
|
|
|
|
|
|
|
ynh_store_file_checksum "$final_path/custom/conf/app.ini"
|
|
|
|
|
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:56:01 +01:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --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
|
|
|
|
#=================================================
|
2020-12-06 14:56:01 +01:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=2
|
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
|
|
|
#=================================================
|
2021-11-06 19:10:24 +01:00
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
2020-12-06 14:40:38 +01:00
|
|
|
#=================================================
|
2021-11-06 19:10:24 +01:00
|
|
|
ynh_script_progression --message="Configuring log rotation..." --weight=1
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2021-11-06 19:10:24 +01:00
|
|
|
# Use logrotate to manage application logfile(s)
|
|
|
|
ynh_use_logrotate
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2021-11-07 08:58:19 +01:00
|
|
|
chown -R $app:$app "/var/log/$app"
|
|
|
|
chmod u=rwX,g=rX,o= "/var/log/$app"
|
|
|
|
|
2020-12-06 14:40:38 +01:00
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2020-12-06 14:56:01 +01:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=2
|
2020-12-06 14:40:38 +01:00
|
|
|
|
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
|
|
|
|
2020-12-06 14:56:01 +01:00
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
|
|
|
|
# Start a systemd service
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
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:56:01 +01:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --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
|