2017-01-05 23:37:07 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-01-31 21:26:13 +01:00
|
|
|
######## 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
|
|
|
|
|
2017-01-31 22:46:07 +01:00
|
|
|
md5sum="7314ad6fcd014a34c2e4e8a95455bcaa"
|
|
|
|
|
2017-01-31 21:26:13 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-01-31 22:46:07 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2017-01-31 21:26:13 +01:00
|
|
|
######## End of common fonctions
|
2017-01-05 23:37:07 +01:00
|
|
|
|
|
|
|
# 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
|
2017-01-31 21:26:13 +01:00
|
|
|
CHECK_PATH
|
2017-01-05 23:37:07 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
|
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"
|
|
|
|
|
|
|
|
|
|
|
|
# Restart webserver
|
|
|
|
sudo service nginx reload
|
2017-01-31 22:46:07 +01:00
|
|
|
sudo service monitorix restart
|