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/restore
2016-10-16 16:43:48 +02:00

72 lines
2.2 KiB
Bash

#!/bin/bash
set -eu
# Set app specific variables
app="gogs"
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
id -g "$app" &>/dev/null || sudo addgroup "$app" --system --quiet
id -u "$app" &>/dev/null || sudo adduser "$app" \
--ingroup "$app" --system --quiet --shell /bin/bash
# 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
sudo mkdir -p /var/log/"$app"
sudo chown -R root:root "$DESTDIR"
sudo chown -R "$app":"$app" "/home/gogs" "/var/log/$app"
# Restore configuration files
sudo cp -a ./conf/nginx.conf "$nginx_conf"
sudo cp -a ./conf/logrotate /etc/logrotate.d/"$app"
sudo cp -a ./conf/systemd.service /etc/systemd/system/"$app".service
sudo systemctl daemon-reload
sudo systemctl enable "$app".service
# Add Gogs to YunoHost's monitored services
sudo yunohost service add "$app" --log /var/log/"$app"/"$app".log
# Reload services
sudo systemctl restart rsyslog.service || true
sudo systemctl reload nginx.service || true
sudo systemctl restart "$app".service || true