2016-08-15 15:38:50 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
# Load common variables and helpers
|
2018-02-07 23:49:32 +01:00
|
|
|
source ../settings/scripts/_common.sh
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Retrieve old app settings
|
|
|
|
domain=$(ynh_app_setting_get "$app" domain)
|
2018-02-07 00:31:25 +01:00
|
|
|
path_url=$(ynh_app_setting_get "$app" path)
|
2016-08-15 15:38:50 +02:00
|
|
|
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
|
|
|
|
admin=$(ynh_app_setting_get "$app" adminusername)
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# 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."
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# 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
|
|
|
|
2018-02-07 00:31:25 +01: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
|
2018-02-07 00:31:25 +01:00
|
|
|
systemctl daemon-reload
|
|
|
|
systemctl enable "$app".service
|
|
|
|
|
2018-02-08 17:25:54 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
|
2018-02-08 11:42:15 +01:00
|
|
|
# Set permissions
|
|
|
|
set_permission
|
|
|
|
|
2018-02-07 00:31:25 +01:00
|
|
|
# Configure logrotate
|
|
|
|
ynh_use_logrotate "/var/log/$app"
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Add Gogs to YunoHost's monitored services
|
2018-02-07 00:31:25 +01:00
|
|
|
yunohost service add "$app" --log /var/log/"$app"/"$app".log
|
2016-08-15 15:38:50 +02:00
|
|
|
|
|
|
|
# Reload services
|
2018-02-07 00:31:25 +01:00
|
|
|
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"
|