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/install

77 lines
2.2 KiB
Text
Raw Normal View History

2017-01-05 23:37:07 +01:00
#!/bin/bash
# Import common cmd
source ./_common.sh
# Init script
init_script
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
path=$YNH_APP_ARG_PATH
# Correct path if it is not correct
correct_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 pflogsumm
sudo dpkg -i /tmp/monitorix.deb
sudo rm -rf /etc/monitorix/conf.d/00-debian.conf
ynh_package_install -f
# # Generate MySQL password and create database
dbuser=$app
dbname=$app
dbpass=$(ynh_string_random 12)
ynh_app_setting_set "$app" mysqlpwd "$dbpass"
ynh_mysql_create_db "$dbname" "$dbuser" "$dbpass"
# Find a port for built-in monitorix HTTP server
port=''
findPort () {
port=$1
while ! sudo yunohost app checkport $port ; do
port=$(($port + 1))
done
}
findPort 8080
http_port=$port
ynh_app_setting_set $app http_port $http_port
findPort $(($port +1))
nginx_status_port=$port
ynh_app_setting_set $app nginx_status_port $nginx_status_port
# Modify Nginx configuration file and copy it to Nginx conf directory
nginx_conf=../conf/nginx.conf
sed -i "s@YNH_WWW_PATH@$path@g" $nginx_conf
sed -i "s@SERVICE_PORT@$http_port@g" $nginx_conf
sudo cp $nginx_conf /etc/nginx/conf.d/$domain.d/$app.conf
# Add special hostname for monitorix status
nginx_status_conf=../conf/nginx_status.conf
sed -i "s@PORT@$nginx_status_port@g" $nginx_status_conf
sudo cp $nginx_status_conf /etc/nginx/conf.d/monitorix_status.conf
# Update monitorix configuration
monitorix_conf=../conf/monitorix.conf
sed -i "s@SERVICE_PORT@$http_port@g" $monitorix_conf
sed -i "s@YNH_DOMAIN@$domain@g" $monitorix_conf
sed -i "s@NGINX_STATUS_PORT@$nginx_status_port@g" $monitorix_conf
sed -i "s@YNH_WWW_PATH@$path@g" $monitorix_conf
sed -i "s@MYSQL_USER@$dbuser@g" $monitorix_conf
sed -i "s@MYSQL_PASSWORD@$dbpass@g" $monitorix_conf
sudo cp $monitorix_conf /etc/monitorix/monitorix.conf
# Reload services
sudo service nginx reload
sudo service monitorix restart