mirror of
https://github.com/YunoHost-Apps/gogs_ynh.git
synced 2024-09-03 20:36:23 +02:00
172 lines
5.7 KiB
Bash
172 lines
5.7 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
dbpass=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
admin=$(ynh_app_setting_get --app=$app --key=adminusername)
|
|
key=$(ynh_app_setting_get --app=$app --key=secret_key)
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
port=$(ynh_app_setting_get --app=$app --key=web_port)
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# MIGRATION FROM OLD VERSION
|
|
#=================================================
|
|
|
|
# Update settings is_public to new standard
|
|
if [ "$is_public" = "Yes" ]; then
|
|
ynh_app_setting_set $app is_public 1 # Fixe is_public en booléen
|
|
is_public=1
|
|
elif [ "$is_public" = "No" ]; then
|
|
ynh_app_setting_set $app is_public 0
|
|
is_public=0
|
|
fi
|
|
|
|
if [[ $port == "" ]]
|
|
then
|
|
port=$(ynh_find_port 6000)
|
|
ynh_app_setting_set $app web_port $port
|
|
fi
|
|
|
|
# handle upgrade from old package installation
|
|
# this test that /etc/gogs exist since this was used in the old package
|
|
# but not in the new
|
|
# this code will be removed in the future
|
|
if [ -d "/etc/gogs" ]
|
|
then
|
|
# create needed directories if not already created
|
|
create_dir
|
|
|
|
# move repositories to new dir
|
|
old_repo_path=$(ynh_app_setting_get "$app" repopath)
|
|
mv "${old_repo_path:-/home/yunohost.app/gogs}"/* "$REPO_PATH" || true # Avoid if the directory is empty
|
|
# cleanup old dir and conf
|
|
ynh_secure_remove /opt/gogs
|
|
ynh_secure_remove /etc/gogs
|
|
ynh_secure_remove /opt/gogs_src
|
|
|
|
# create needed directories if not already created
|
|
create_dir
|
|
fi
|
|
# end of old package upgrade
|
|
|
|
# test if user gogs is locked because of an old installation of the package.
|
|
# if it's blocked, unlock it to allow ssh usage with git
|
|
if [[ $(grep "$app" /etc/shadow | cut -d: -f2) == '!' ]]
|
|
then
|
|
usermod -p '*' "$app"
|
|
fi
|
|
|
|
# Remove old authentification mecanisme, actually the registry in the database has been replaced by a config file
|
|
if [[ ! -e "$final_path/custom/conf/auth.d/ldap.conf" ]]
|
|
then
|
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" <<< "DELETE FROM login_source WHERE name = 'Yunohost LDAP';"
|
|
mkdir -p "$final_path/custom/conf/auth.d"
|
|
fi
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
|
|
# Clean template to fix issue : https://github.com/gogits/gogs/issues/4585
|
|
ynh_secure_remove "/opt/gogs/templates"
|
|
|
|
# Install Gogs
|
|
ynh_setup_source --dest_dir="$final_path" $architecture
|
|
|
|
# Configure gogs with app.ini file
|
|
config_gogs
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
|
|
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
|
|
# Unprotect root from SSO if public
|
|
set_access_settings
|
|
|
|
# Set permissions
|
|
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"
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
|
|
|
|
yunohost service add $app --description="Lightweight Git forge" --log="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|