2016-08-15 15:38:50 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Load common variables and helpers
|
2018-02-07 00:31:25 +01:00
|
|
|
source ./experimental_helper.sh
|
2016-08-15 15:38:50 +02:00
|
|
|
source ./_common.sh
|
|
|
|
|
|
|
|
# Retrieve app settings
|
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
2018-02-07 00:31:25 +01:00
|
|
|
path_url=$(ynh_app_setting_get "$app" path)
|
2016-08-15 15:38:50 +02:00
|
|
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
|
|
admin=$(ynh_app_setting_get "$app" adminusername)
|
|
|
|
key=$(ynh_app_setting_get "$app" secret_key)
|
|
|
|
is_public=$(ynh_app_setting_get "$app" is_public)
|
2018-02-08 00:09:28 +01:00
|
|
|
port=$(ynh_app_setting_get "$app" web_port)
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# Backup the current version of the app
|
|
|
|
if [[ $(ynh_app_setting_get $app disable_backup_before_upgrade) != '1' ]]
|
|
|
|
then
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_restore_upgradebackup
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# Stop service
|
2018-02-07 00:31:25 +01:00
|
|
|
systemctl stop "$app".service
|
2016-08-15 15:38:50 +02:00
|
|
|
|
2018-02-08 00:09:28 +01:00
|
|
|
if [[ $port == "" ]]
|
|
|
|
then
|
|
|
|
port=$(ynh_find_port 6000)
|
|
|
|
ynh_app_setting_set $app web_port $port
|
|
|
|
fi
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# create needed directories if not already created
|
|
|
|
create_dir
|
2016-10-11 22:11:21 +02:00
|
|
|
|
|
|
|
# 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
|
2016-10-11 22:22:47 +02:00
|
|
|
# move repositories to new dir
|
2016-10-11 22:11:21 +02:00
|
|
|
old_repo_path=$(ynh_app_setting_get "$app" repopath)
|
2018-02-07 00:31:25 +01:00
|
|
|
mv "${old_repo_path:-/home/yunohost.app/gogs}"/* "$REPO_PATH"
|
2016-10-11 22:22:47 +02:00
|
|
|
# cleanup old dir and conf
|
2018-02-07 00:31:25 +01:00
|
|
|
unlink /opt/gogs
|
|
|
|
ynh_secure_remove /etc/gogs
|
|
|
|
ynh_secure_remove /opt/gogs_src
|
2016-10-11 22:11:21 +02:00
|
|
|
fi
|
|
|
|
# end of old package upgrade
|
|
|
|
|
2016-08-15 15:38:50 +02:00
|
|
|
# Install Gogs
|
2018-02-07 00:31:25 +01:00
|
|
|
ynh_setup_source $final_path $architecture
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Configure gogs with app.ini file
|
2018-02-07 00:31:25 +01:00
|
|
|
config_gogs
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Configure init script
|
2018-02-07 00:31:25 +01:00
|
|
|
ynh_add_systemd_config
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Modify Nginx configuration file and copy it to Nginx conf directory
|
2018-02-07 00:31:25 +01:00
|
|
|
config_nginx
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Unprotect root from SSO if public
|
2018-02-07 00:31:25 +01:00
|
|
|
if [ "$is_public" ]
|
2016-08-15 15:38:50 +02:00
|
|
|
then
|
|
|
|
ynh_app_setting_set $app unprotected_uris "/"
|
|
|
|
fi
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# Set permissions
|
|
|
|
set_permission
|
2016-10-16 16:43:48 +02:00
|
|
|
|
|
|
|
# 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
|
2018-02-07 00:31:25 +01:00
|
|
|
if [[ $(grep "$app" /etc/shadow | cut -d: -f2) == '!' ]]
|
2016-10-16 16:43:48 +02:00
|
|
|
then
|
2018-02-07 00:31:25 +01:00
|
|
|
usermod -p '*' "$app"
|
2016-10-16 16:43:48 +02:00
|
|
|
fi
|
2018-02-07 00:31:25 +01:00
|
|
|
|
|
|
|
# Reload services
|
|
|
|
systemctl restart "$app".service
|