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

145 lines
4.2 KiB
Text
Raw Normal View History

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-02-16 23:00:36 +01:00
## Adapt md5sum while you update app
2017-01-31 22:46:07 +01:00
md5sum="7314ad6fcd014a34c2e4e8a95455bcaa"
2017-02-16 23:00:36 +01:00
monitorix_version="3.9.0"
2017-01-31 22:46:07 +01:00
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() {
2017-02-16 23:00:36 +01:00
wget -q -O '/tmp/monitorix.deb' "http://www.monitorix.org/monitorix_${monitorix_version}-izzy1_all.deb"
2017-01-31 22:46:07 +01:00
if [[ ! -e '/tmp/monitorix.deb' ]] || [[ $(md5sum '/tmp/monitorix.deb' | cut -d' ' -f1) != $md5sum ]]
then
ynh_die "Error : can't get monitorix debian package"
fi
}
2017-02-16 23:00:36 +01:00
CHECK_VAR () { # Vérifie que la variable n'est pas vide.
# $1 = Variable à vérifier
# $2 = Texte à afficher en cas d'erreur
test -n "$1" || (echo "$2" >&2 && false)
}
# Ignore the yunohost-cli log to prevent errors with conditionals commands
# usage: NO_LOG COMMAND
# Simply duplicate the log, execute the yunohost command and replace the log without the result of this command
# It's a very badly hack...
# Petite copie perso à mon usage ;)
NO_LOG() {
ynh_cli_log=/var/log/yunohost/yunohost-cli.log
sudo cp -a ${ynh_cli_log} ${ynh_cli_log}-move
eval $@
exit_code=$?
sudo mv ${ynh_cli_log}-move ${ynh_cli_log}
return $?
}
2017-01-31 22:46:07 +01:00
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-02-16 23:00:36 +01:00
CHECK_DOMAINPATH () { # Vérifie la disponibilité du path et du domaine.
sudo yunohost app checkurl $domain$path -a $app
}
CHECK_FINALPATH () { # Vérifie que le dossier de destination n'est pas déjà utilisé.
final_path=/var/www/$app
if [ -e "$final_path" ]
then
echo "This path already contains a folder" >&2
false
fi
}
FIND_PORT () { # Cherche un port libre.
# $1 = Numéro de port pour débuter la recherche.
port=$1
while ! sudo yunohost app checkport $port ; do
port=$((port+1))
done
CHECK_VAR "$port" "port empty"
}
### REMOVE SCRIPT
REMOVE_NGINX_CONF () { # Suppression de la configuration nginx
if [ -e "/etc/nginx/conf.d/$domain.d/$app.conf" ]; then # Delete nginx config
echo "Delete nginx config"
sudo rm "/etc/nginx/conf.d/$domain.d/$app.conf"
sudo service nginx reload
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
2017-02-13 16:17:53 +01:00
sudo rm -rf /etc/monitorix/conf.d/00-debian.conf
2017-01-05 23:37:07 +01:00
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
2017-02-13 16:17:53 +01:00
sudo cp -a ./config/. "/etc/monitorix/."
sudo cp -a ./data/. "/var/lib/monitorix/."
2017-01-05 23:37:07 +01:00
# Restart webserver
sudo service nginx reload
2017-01-31 22:46:07 +01:00
sudo service monitorix restart