1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/monitorix_ynh.git synced 2024-09-03 19:46:06 +02:00
monitorix_ynh/scripts/restore
2017-02-13 16:17:53 +01:00

89 lines
No EOL
2.7 KiB
Bash
Executable file

#!/bin/bash
######## Actually we cant use common script in backup / restore script see this issue for more informations : https://dev.yunohost.org/issues/621
# # Import common cmd
# source ./_common.sh
#
######## We implement manually this fonctions
md5sum="7314ad6fcd014a34c2e4e8a95455bcaa"
init_script() {
# Exit on command errors and treat unset variables as an error
set -eu
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Retrieve arguments
app=$YNH_APP_INSTANCE_NAME
}
get_source() {
wget -q -O '/tmp/monitorix.deb' 'http://www.monitorix.org/monitorix_3.9.0-izzy1_all.deb'
if [[ ! -e '/tmp/monitorix.deb' ]] || [[ $(md5sum '/tmp/monitorix.deb' | cut -d' ' -f1) != $md5sum ]]
then
ynh_die "Error : can't get monitorix debian package"
fi
}
CHECK_PATH () { # Vérifie la présence du / en début de path. Et son absence à la fin.
if [ "${path:0:1}" != "/" ]; then # Si le premier caractère n'est pas un /
path="/$path" # Ajoute un / en début de path
fi
if [ "${path:${#path}-1}" == "/" ] && [ ${#path} -gt 1 ]; then # Si le dernier caractère est un / et que ce n'est pas le seul caractère.
path="${path:0:${#path}-1}" # Supprime le dernier caractère
fi
}
######## End of common fonctions
# Init script
init_script
# Note: each files and directories you've saved using the ynh_backup helper
# will be located in the current directory, regarding the last argument.
# Retrieve old app settings
domain=$(ynh_app_setting_get "$app" domain)
path=$(ynh_app_setting_get "$app" path)
# Correct path if it is not correct
CHECK_PATH
# Check domain/path availability
sudo yunohost app checkurl "${domain}${path}" -a "$app" \
|| ynh_die "Path not available: ${domain}${path}"
# Download package
get_source
# Install package
ynh_package_update
ynh_package_install rrdtool perl libwww-perl libmailtools-perl libmime-lite-perl librrds-perl libdbi-perl libxml-simple-perl libhttp-server-simple-perl libconfig-general-perl
sudo dpkg -i /tmp/monitorix.deb
sudo rm -rf /etc/monitorix/conf.d/00-debian.conf
ynh_package_install -f
# # Create and restore the database
dbname=$app
dbuser=$app
dbpass=$(ynh_app_setting_get "$app" mysqlpwd)
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
ynh_mysql_connect_as "$dbuser" "$dbpass" "$dbname" < ./dump.sql
# Restore NGINX configuration
sudo cp -a ./nginx.conf "/etc/nginx/conf.d/${domain}.d/${app}.conf"
sudo cp -a ./monitorix_status.conf "/etc/nginx/conf.d/monitorix_status.conf"
# Restore Monitorix configuration
sudo cp -a ./config/. "/etc/monitorix/."
sudo cp -a ./data/. "/var/lib/monitorix/."
# Restart webserver
sudo service nginx reload
sudo service monitorix restart