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

82 lines
2.5 KiB
Text
Raw Normal View History

2016-08-15 15:38:50 +02:00
#!/bin/bash
2018-02-08 17:25:54 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
2020-11-18 17:59:20 +01:00
#=================================================
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
2020-11-18 17:59:20 +01:00
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2020-11-18 17:59:20 +01:00
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading installation settings..." --weight=1
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
2020-11-20 09:28:52 +01:00
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
2020-11-18 17:59:20 +01:00
admin=$(ynh_app_setting_get --app=$app --key=adminusername)
# Check domain/path availability with app helper
ynh_webpath_available $domain $path_url || ynh_die "$domain is not available as domain, please use an other domain."
2016-08-15 15:38:50 +02:00
# Check user parameter
ynh_user_exists "$admin" \
|| ynh_die "The chosen admin user does not exist."
# Check Final Path availability
test ! -e "$final_path" || ynh_die "This path already contains a folder"
2016-08-15 15:38:50 +02:00
2018-02-08 17:25:54 +01:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
2016-08-15 15:38:50 +02:00
# Add users
2018-03-04 16:48:08 +01:00
# We can't use the official helper because we need to set the shell for the login
test getent passwd "$app" &>/dev/null || \
useradd -d "$DATADIR" --system --user-group "$app" --shell /bin/bash || \
ynh_die "Unable to create $app system account"
2016-08-15 15:38:50 +02:00
# Restore all files
ynh_restore
2016-08-15 15:38:50 +02:00
# Create and restore the database
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
2018-02-08 17:25:54 +01:00
# Restore systemd files
systemctl daemon-reload
2020-12-06 14:08:58 +01:00
systemctl enable "$app".service --quiet
2018-02-08 17:25:54 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2018-02-08 11:42:15 +01:00
# Set permissions
set_permission
# Configure logrotate
ynh_use_logrotate "/var/log/$app"
2016-08-15 15:38:50 +02:00
# Add Gogs to YunoHost's monitored services
yunohost service add "$app" --log /var/log/"$app"/"$app".log
2016-08-15 15:38:50 +02:00
# Reload services
systemctl reload nginx.service
2018-02-08 15:06:12 +01:00
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"