mirror of
https://github.com/YunoHost-Apps/gogs_ynh.git
synced 2024-09-03 20:36:23 +02:00
100 lines
3 KiB
Bash
100 lines
3 KiB
Bash
#!/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 gogs.service
|
|
|
|
# set directories variables
|
|
DESTDIR="/opt/$app"
|
|
REPO_PATH=/home/gogs/repositories
|
|
DATA_PATH=/home/gogs/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
|
|
# move re
|
|
old_repo_path=$(ynh_app_setting_get "$app" repopath)
|
|
sudo mv "$old_repo_path"/* "$REPO_PATH"
|
|
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
|
|
sudo mkdir -p "$DESTDIR"/custom/conf "$REPO_PATH" "$DATA_PATH"/avatars \
|
|
"$DATA_PATH"/avatars "$DATA_PATH"/attachments /var/log/gogs
|
|
sudo chown -R gogs:gogs /home/gogs /var/log/gogs
|
|
|
|
# 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 gogs.service
|
|
|
|
# Configure logrotate
|
|
sudo cp ../conf/logrotate /etc/logrotate.d/gogs
|
|
|
|
# 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 gogs.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
|