2016-08-15 15:38:50 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
|
|
|
# Set app specific variables
|
2016-10-18 00:01:49 +02:00
|
|
|
app=${APPNAME:-gogs}
|
2016-08-15 15:38:50 +02:00
|
|
|
dbname=$app
|
|
|
|
dbuser=$app
|
|
|
|
|
|
|
|
# Source app helpers
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Retrieve old 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)
|
|
|
|
|
|
|
|
# TODO: Check domain/path availability with app helper
|
|
|
|
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|
|
|
|
|| ynh_die "The path ${domain}${path} is not available for app installation."
|
|
|
|
|
|
|
|
# Check user parameter
|
|
|
|
ynh_user_exists "$admin" \
|
|
|
|
|| ynh_die "The chosen admin user does not exist."
|
|
|
|
|
|
|
|
# Check destination directory
|
|
|
|
DESTDIR="/opt/$app"
|
|
|
|
[[ -d $DESTDIR ]] && ynh_die \
|
|
|
|
"The destination directory '$DESTDIR' already exists.\
|
|
|
|
You should safely delete it before restoring this app."
|
|
|
|
|
|
|
|
# Add users
|
2016-10-11 22:18:56 +02:00
|
|
|
id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet
|
2016-10-16 16:43:48 +02:00
|
|
|
id -u "$app" &>/dev/null || sudo adduser "$app" \
|
2016-10-11 22:18:56 +02:00
|
|
|
--ingroup "$app" --system --quiet --shell /bin/bash
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Check configuration files
|
|
|
|
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
|
|
|
|
[[ -f $nginx_conf ]] && ynh_die \
|
|
|
|
"The NGINX configuration already exists at '${nginx_conf}'.
|
|
|
|
You should safely delete it before restoring this app."
|
|
|
|
|
|
|
|
# Restore the app files
|
|
|
|
sudo cp -a ./www "$DESTDIR"
|
|
|
|
|
|
|
|
# Restore the data
|
|
|
|
sudo cp -a ./data/. "/home/gogs"
|
|
|
|
|
|
|
|
# Create and restore the database
|
|
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
|
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
|
|
|
|
|
|
|
|
# Restore directories and permissions
|
2016-10-11 22:18:56 +02:00
|
|
|
sudo mkdir -p /var/log/"$app"
|
2016-08-15 15:38:50 +02:00
|
|
|
sudo chown -R root:root "$DESTDIR"
|
2016-10-11 22:18:56 +02:00
|
|
|
sudo chown -R "$app":"$app" "/home/gogs" "/var/log/$app"
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Restore configuration files
|
|
|
|
sudo cp -a ./conf/nginx.conf "$nginx_conf"
|
2016-10-11 22:18:56 +02:00
|
|
|
sudo cp -a ./conf/logrotate /etc/logrotate.d/"$app"
|
|
|
|
sudo cp -a ./conf/systemd.service /etc/systemd/system/"$app".service
|
2016-08-15 15:38:50 +02:00
|
|
|
sudo systemctl daemon-reload
|
2016-10-11 22:18:56 +02:00
|
|
|
sudo systemctl enable "$app".service
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Add Gogs to YunoHost's monitored services
|
2016-10-11 22:18:56 +02:00
|
|
|
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Reload services
|
2016-10-11 21:55:26 +02:00
|
|
|
sudo systemctl restart rsyslog.service || true
|
|
|
|
sudo systemctl reload nginx.service || true
|
2016-10-11 22:18:56 +02:00
|
|
|
sudo systemctl restart "$app".service || true
|