2017-01-05 23:37:07 +01:00
#!/bin/bash
2018-01-31 16:07:43 +01:00
#=================================================
# GENERIC START
#=================================================
2017-07-21 22:11:45 +02:00
# Source YunoHost helpers
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
2017-01-05 23:37:07 +01:00
# Import common cmd
2018-01-31 16:07:43 +01:00
source ./experimental_helper.sh
2017-01-05 23:37:07 +01:00
source ./_common.sh
2019-06-07 23:09:30 +02:00
ynh_script_progression --message="Validating installation parameters..."
2017-01-05 23:37:07 +01:00
# Retrieve arguments
domain=$YNH_APP_ARG_DOMAIN
2019-06-07 23:09:30 +02:00
path_url=$(ynh_normalize_url_path --path_url $YNH_APP_ARG_PATH)
2017-01-05 23:37:07 +01:00
# Check domain/path availability
2019-06-07 23:09:30 +02:00
test $(ynh_webpath_available --domain $domain --path_url $path_url) == 'True' || ynh_die --message "$domain$path_url is not available, please use an other domain or path."
2018-05-07 23:08:03 +02:00
ynh_webpath_register $app $domain $path_url
2017-01-05 23:37:07 +01:00
2018-01-31 16:07:43 +01:00
# Find a port for built-in monitorix HTTP server
2019-06-07 23:09:30 +02:00
ynh_script_progression --message="Finding available ports..."
port=$(ynh_find_port --port 8080)
nginx_status_port=$(ynh_find_port --port $(($port +1)))
2018-01-31 16:07:43 +01:00
2019-06-07 23:09:30 +02:00
# store config in yunohost
ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app $app --key http_port --value $port
ynh_app_setting_set --app $app --key nginx_status_port --value $nginx_status_port
2018-01-31 16:07:43 +01:00
#=================================================
# STANDARD MODIFICATIONS
#=================================================
2019-06-07 23:09:30 +02:00
# Install package
ynh_script_progression --message="Installing dependencies..." --weight=7
2017-07-21 22:11:45 +02:00
install_dependances
2017-01-05 23:37:07 +01:00
2017-10-31 23:08:23 +01:00
# Download package and install it
2019-06-07 23:09:30 +02:00
ynh_script_progression --message="Installing sources files..." --weight=7
2017-10-31 23:08:23 +01:00
get_install_source
2017-07-21 22:11:45 +02:00
# # Generate MySQL user
2019-06-07 23:09:30 +02:00
ynh_script_progression --message="Configuring MySQL database..."
2017-01-05 23:37:07 +01:00
dbuser=$app
dbpass=$(ynh_string_random 12)
2019-06-07 23:09:30 +02:00
ynh_app_setting_set --app $app --key mysqlpwd --value "$dbpass"
2017-07-21 22:11:45 +02:00
ynh_mysql_create_user $dbuser $dbpass
2017-01-05 23:37:07 +01:00
2017-07-21 22:11:45 +02:00
# Config nginx
2019-06-07 23:09:30 +02:00
ynh_script_progression --message="Configuring nginx..." --weight=1
2017-07-21 22:11:45 +02:00
config_nginx
2017-01-05 23:37:07 +01:00
# Update monitorix configuration
2019-06-07 23:09:30 +02:00
ynh_script_progression --message="Configuring application..." --weight=3
2017-07-21 22:11:45 +02:00
config_monitorix
2017-01-05 23:37:07 +01:00
2018-04-30 21:41:07 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2018-01-29 18:57:10 +01:00
# Set access
2019-06-07 23:09:30 +02:00
ynh_script_progression --message="Protecting directory..."
2018-01-29 18:57:10 +01:00
set_permission
2017-05-26 15:02:19 +02:00
# register yunohost service
2017-07-21 22:11:45 +02:00
yunohost service add monitorix
2017-05-26 15:02:19 +02:00
2018-05-01 21:00:07 +02:00
# Reload monitorix
2019-06-07 23:09:30 +02:00
ynh_script_progression --message="Starting monitorix services..." --weight=3
2018-05-07 23:08:03 +02:00
# While we stop monitorix sometime the built-in web server is not stopped cleanly. So are sure that everything is cleanly stoped by that
2018-05-01 21:00:07 +02:00
# So this fix that
2019-06-07 23:09:30 +02:00
systemctl stop monitorix.service
2018-05-01 21:00:07 +02:00
sleep 1
2018-05-07 23:08:03 +02:00
pkill -f "monitorix-httpd listening on" || true
2019-06-07 23:09:30 +02:00
ynh_systemd_action -l ' - Ok, ready.' -p '/var/log/monitorix'
ynh_script_progression --message="Installation of $app completed" --last