mirror of
https://github.com/YunoHost-Apps/gogs_ynh.git
synced 2024-09-03 20:36:23 +02:00
84 lines
2.6 KiB
Bash
84 lines
2.6 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
#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
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
#### Remove this function if there's nothing to clean before calling the remove script.
|
|
true
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# 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)
|
|
dbpass=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
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."
|
|
|
|
# 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"
|
|
|
|
#=================================================
|
|
# STANDARD RESTORATION STEPS
|
|
#=================================================
|
|
|
|
# Add users
|
|
# 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"
|
|
|
|
# Restore all files
|
|
ynh_restore
|
|
|
|
# Create and restore the database
|
|
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
|
|
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./db.sql
|
|
|
|
# Restore systemd files
|
|
systemctl daemon-reload
|
|
systemctl enable "$app".service
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
|
|
# Set permissions
|
|
set_permission
|
|
|
|
# Configure logrotate
|
|
ynh_use_logrotate "/var/log/$app"
|
|
|
|
# Add Gogs to YunoHost's monitored services
|
|
yunohost service add "$app" --log /var/log/"$app"/"$app".log
|
|
|
|
# Reload services
|
|
systemctl reload nginx.service
|
|
ynh_check_starting "INFO] Listen: http://0.0.0.0:" "/var/log/$app/gogs.log"
|