1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/lstu_ynh.git synced 2024-09-03 19:36:12 +02:00

update restore script

This commit is contained in:
Pierre Bourré 2019-02-03 01:04:22 +01:00
parent bec4c2407b
commit 790fb2a42e

View file

@ -1,97 +1,101 @@
#!/bin/bash #!/bin/bash
# vim:set noexpandtab:
# This restore script is adapted to Yunohost >=2.4
# Exit on command errors and treat unset variables as an error #=================================================
set -eu # GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
# Source app helpers source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers source /usr/share/yunohost/helpers
# The parameter $app is the id of the app instance ex: ynhexample__2 #=================================================
# 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
#=================================================
app=$YNH_APP_INSTANCE_NAME app=$YNH_APP_INSTANCE_NAME
# Get old parameter of the app
domain=$(ynh_app_setting_get $app domain) domain=$(ynh_app_setting_get $app domain)
path=$(ynh_app_setting_get $app path) path_url=$(ynh_app_setting_get $app path)
is_public=$(ynh_app_setting_get $app is_public) final_path=$(ynh_app_setting_get $app final_path)
db_name=$(ynh_app_setting_get $app db_name)
ynh_package_update #=================================================
ynh_package_install build-essential libssl-dev libpq-dev # CHECK IF THE APP CAN BE RESTORED
echo yes | sudo cpan Carton #=================================================
# Check domain/path availability ynh_webpath_available $domain $path_url \
sudo yunohost app checkurl "${domain}${path}" -a "${app}" \ || ynh_die "Path not available: ${domain}${path_url}"
|| ynh_die "Path not available: ${domain}${path}" test ! -d $final_path \
|| ynh_die "There is already a directory: $final_path "
# Check $final_path #=================================================
final_path="/var/www/${app}" # STANDARD RESTORATION STEPS
if [ -d "${final_path}" ]; then #=================================================
ynh_die "There is already a directory: ${final_path}" # RESTORE THE NGINX CONFIGURATION
fi #=================================================
# Check configuration files nginx ynh_restore_file "/etc/nginx/conf.d/$domain.d/$app.conf"
nginx_conf="/etc/nginx/conf.d/${domain}.d/${app}.conf"
if [ -f "${nginx_conf}" ]; then
ynh_die "The NGINX configuration already exists at '${nginx_conf}'. You should safely delete it before restoring this app."
fi
# Check configuration files lstu #=================================================
lstu_conf="${final_path}/${app}.conf" # RESTORE THE APP MAIN DIR
if [ -f "${lstu_conf}" ]; then #=================================================
ynh_die "The LSTU CONF configuration already exists at '${lstu_conf}'. You should safely delete it before restoring this app."
fi
lstu_systemd="/etc/systemd/system/${app}.service" ynh_restore_file "$final_path"
if [ -f "${lstu_systemd}" ]; then
ynh_die "The LSTU SYSTEMD configuration already exists at '${lstu_systemd}'. You should safely delete it before restoring this app."
fi
lstu_logrotate="/etc/logrotate.d/${app}" #=================================================
if [ -f "${lstu_logrotate}" ]; then # RESTORE THE MYSQL DATABASE
ynh_die "The LSTU LOGROTATE configuration already exists at '${lstu_logrotate}'. You should safely delete it before restoring this app." #=================================================
fi
lstu_log="/var/log/${app}/production.log" db_pwd=$(ynh_app_setting_get $app psqlpwd)
if [ -f "${lstu_log}" ]; then ynh_psql_setup_db $db_name $db_name $db_pwd
ynh_die "The LSTU LOG configuration already exists at '${lstu_log}'. You should safely delete it before restoring this app." ynh_psql_connect_as $db_name $db_pwd $db_name < ./db.sql
fi
# Restore sources & data #=================================================
sudo cp -a ./sources "${final_path}" # SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
# Set permissions # Define and install dependencies
sudo chown -R www-data: "${final_path}" ynh_install_app_dependencies build-essential libssl-dev zlib1g-dev libpng-dev libpq-dev memcached postgresql
# Restore nginx configuration files #=================================================
sudo cp -a ./nginx.conf "${nginx_conf}" # RESTORE SYSTEMD
#=================================================
# Restore lstu configuration files ynh_restore_file "/etc/systemd/system/$app.service"
sudo cp -a ./lstu.conf "${lstu_conf}" systemctl enable $app.service
systemctl start $app
# Restore service #=================================================
sudo cp -a ./systemd_lstu.service "${lstu_systemd}" # ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
sudo cp -a ./logrotate_lstu "${lstu_logrotate}" yunohost service add $app --log "/var/log/$app.log"
# Create log production #=================================================
sudo mkdir "/var/log/${app}/" # RESTORE THE LOGROTATE CONFIGURATION
sudo cp -a ./production.log "${lstu_log}" #=================================================
# Delete symbolic link and restore
sudo rm -fr "${final_path}/log/production.log"
sudo ln -s "/var/log/${app}/production.log" "${final_path}/log/production.log"
# Reload lstu service ynh_restore_file "/etc/logrotate.d/$app"
sudo systemctl daemon-reload
sudo systemctl start lstu.service
sudo systemctl enable lstu.service
# Set ssowat config #=================================================
if [ $is_public -eq 0 ]; # GENERIC FINALIZATION
then #=================================================
ynh_app_setting_delete $app skipped_uris # RELOAD NGINX
fi #=================================================
# Reload services systemctl reload nginx
sudo systemctl reload nginx yunohost app ssowatconf
sudo yunohost app ssowatconf