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

103 lines
3.1 KiB
Text
Raw Normal View History

2016-08-15 15:38:50 +02:00
#!/bin/bash
set -eu
# Load common variables and helpers
source ./_common.sh
# Set app specific variables
app=$APPNAME
dbname=$app
dbuser=$app
# Source app helpers
source /usr/share/yunohost/helpers
# Retrieve app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
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)
# Stop service
sudo systemctl stop "$app".service
2016-08-15 15:38:50 +02:00
# set directories variables
2016-08-15 15:38:50 +02:00
DESTDIR="/opt/$app"
REPO_PATH=/home/"$app"/repositories
DATA_PATH=/home/"$app"/data
# 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
sudo mkdir -p "$REPO_PATH"
old_repo_path=$(ynh_app_setting_get "$app" repopath)
sudo mv "$old_repo_path"/* "$REPO_PATH"
2016-10-11 22:22:47 +02:00
# cleanup old dir and conf
sudo unlink /opt/gogs
sudo rm -rf /etc/gogs /opt/gogs_src
fi
# end of old package upgrade
# create needed directories and give correct acl
2016-08-15 15:38:50 +02:00
sudo mkdir -p "$DESTDIR"/custom/conf "$REPO_PATH" "$DATA_PATH"/avatars \
"$DATA_PATH"/avatars "$DATA_PATH"/attachments /var/log/"$app"
sudo chown -R "$app":"$app" /home/"$app" /var/log/"$app"
2016-08-15 15:38:50 +02:00
# Install Gogs
extract_gogs $DESTDIR
# Configure gogs with app.ini file
sudo cp ../conf/app.ini "$DESTDIR"/custom/conf
sudo sed -i "s@yuno_repo_path@"$REPO_PATH"@g" "$DESTDIR"/custom/conf/app.ini
if [ "$path" = "/" ]
then
sudo sed -i "s@yuno_url@$domain@g" "$DESTDIR"/custom/conf/app.ini
else
sudo sed -i "s@yuno_url@$domain${path%/}@g" "$DESTDIR"/custom/conf/app.ini
fi
sudo sed -i "s@yuno_dbpdw@$dbpass@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_dbuser@$dbuser@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_domain@$domain@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_key@$key@g" "$DESTDIR"/custom/conf/app.ini
sudo sed -i "s@yuno_data_path@$DATA_PATH@g" "$DESTDIR"/custom/conf/app.ini
# Configure init script
sudo cp ../conf/gogs.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable "$app".service
2016-08-15 15:38:50 +02:00
# Configure logrotate
sudo cp ../conf/logrotate /etc/logrotate.d/"$app"
2016-08-15 15:38:50 +02:00
# Modify Nginx configuration file and copy it to Nginx conf directory
sed -i "s@PATHTOCHANGE@${path%/}@g" ../conf/nginx.conf
if [ "$path" = "/" ]
then
sed -i "s@COMMENT_IF_ROOT@#@g" ../conf/nginx.conf
else
sed -i "s@COMMENT_IF_ROOT@@g" ../conf/nginx.conf
fi
sudo cp ../conf/nginx.conf /etc/nginx/conf.d/$domain.d/$app.conf
# Unprotect root from SSO if public
if [ "$is_public" = "Yes" ]
then
ynh_app_setting_set $app unprotected_uris "/"
fi
# Reload services
sudo systemctl restart rsyslog.service || true
sudo systemctl reload nginx.service || true
sudo systemctl restart "$app".service || true
# Restore ldap config
sudo sed -i "s@yuno_admin@$admin@g" ../conf/login_source.sql
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ../conf/login_source.sql