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