1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/etherpad_mypads_ynh.git synced 2024-09-03 18:36:09 +02:00
etherpad_mypads_ynh/scripts/restore
2019-01-19 11:57:22 +01:00

193 lines
6 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
# Load common variables for all scripts.
source ../settings/scripts/_variables
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
# Clean installation remaining that are not handle by the remove script.
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get $app domain)
path_url=$(ynh_app_setting_get $app path)
final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
export=$(ynh_app_setting_get $app export)
mypads=$(ynh_app_setting_get $app mypads)
admin=$(ynh_app_setting_get $app admin)
ynh_print_OFF; password=$(ynh_app_setting_get $app password); ynh_print_ON
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
ynh_webpath_available $domain $path_url \
|| ynh_die "Path not available: ${domain}${path_url}"
test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
#=================================================
# ACTIVATE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_ON
#=================================================
# STANDARD RESTORE STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_restore_file "$final_path"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
db_pwd=$(ynh_app_setting_get $app mysqlpwd)
ynh_mysql_setup_db $db_name $db_name $db_pwd
ynh_mysql_connect_as $db_name $db_pwd $db_name < ./db.sql
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
# Create the dedicated user (if not existing)
ynh_system_user_create $app
#=================================================
# SPECIFIC RESTORE
#=================================================
# HANDLE LOG FILES AND LOGROTATE
#=================================================
mkdir -p /var/log/$app
touch /var/log/$app/etherpad.log
install_log=/var/log/$app/installation.log
touch $install_log
chown $app -R /var/log/$app
chown admin -R $install_log
# Restore logrotate configuration
ynh_restore_file "/etc/logrotate.d/$app"
#=================================================
# INSTALL DEPENDENCIES
#=================================================
if [ "$export" = "abiword" ]; then
ynh_install_app_dependencies $abiword_app_depencencies
elif [ "$export" = "libreoffice" ]; then
ynh_install_app_dependencies $libreoffice_app_dependencies
fi
#=================================================
# INSTALL NODEJS
#=================================================
ynh_install_nodejs $nodejs_version
#=================================================
# INSTALL ETHERPAD DEPENDENCIES
#=================================================
ynh_use_nodejs
npm cache clean
npm install forever -g >> $install_log 2>&1
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
chown -R $app: $final_path
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add $app --log "/var/log/$app/etherpad.log"
#=================================================
# RESTORE SYSTEMD
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
systemctl enable $app.service
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
ynh_restore_file "/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file "/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
#=================================================
# RELOAD NGINX
#=================================================
ynh_systemd_action --action=reload --service_name=nginx
#=================================================
# CHECK ETHERPAD STARTING
#=================================================
# Wait for etherpad to be fully started
ynh_systemd_action --action=restart --line_match="You can access your Etherpad instance at" --log_path="/var/log/$app/etherpad.log" --timeout="120"
#=================================================
# DEACTIVE MAINTENANCE MODE
#=================================================
ynh_maintenance_mode_OFF
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
if [ $mypads -eq 1 ]
then
Informations="You can access 2 different admin panels, for etherpad by accessing https://$domain${path_url%/}/admin and for mypads by accessing https://$domain${path_url%/}/mypads/?/admin."
else
Informations="You can access to the admin panel, by accessing https://$domain${path_url%/}/admin."
fi
ynh_print_OFF
message="$Informations
Or, you can find a config file for etherpad at this path /var/www/etherpad_mypads/settings.json.
Your credentials for the admin panel are:
- login : $admin
- password : $password
If you are facing an issue or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/etherpad_mypads_ynh"
ynh_send_readme_to_admin "$message" "$admin"
ynh_print_ON