#!/bin/bash set -euo pipefail # Set app specific variables app=${APPNAME:-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