2017-02-18 16:45:43 +01:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# GENERIC START
|
|
|
|
|
#=================================================
|
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
|
#=================================================
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
source _common.sh
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# LOAD SETTINGS
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Loading installation settings..." --weight=1
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
|
admin=$(ynh_app_setting_get --app=$app --key=admin)
|
|
|
|
|
is_public=$(ynh_app_setting_get --app=$app --key=is_public)
|
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
|
db_user=$db_name
|
|
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
|
|
|
|
|
port=$(ynh_app_setting_get --app=$app --key=port)
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# CHECK VERSION
|
|
|
|
|
#=================================================
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
2017-05-18 20:45:58 +02:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
|
|
|
|
|
|
# Fix is_public as a boolean value
|
|
|
|
|
if [ "$is_public" = "Yes" ]; then
|
|
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=1
|
|
|
|
|
is_public=1
|
|
|
|
|
elif [ "$is_public" = "No" ]; then
|
|
|
|
|
ynh_app_setting_set --app=$app --key=is_public --value=0
|
|
|
|
|
is_public=0
|
2017-05-18 20:45:58 +02:00
|
|
|
|
fi
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
# If db_name doesn't exist, create it
|
|
|
|
|
if [ -z "$db_name" ]; then
|
|
|
|
|
db_name=$(ynh_sanitize_dbid --db_name=$app)
|
|
|
|
|
ynh_app_setting_set --app=$app --key=db_name --value=$db_name
|
|
|
|
|
fi
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
2017-12-03 19:24:03 +01:00
|
|
|
|
#=================================================
|
2020-05-17 09:28:22 +02:00
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
2017-12-03 19:24:03 +01:00
|
|
|
|
#=================================================
|
2020-05-17 09:28:22 +02:00
|
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=4
|
2017-12-03 19:24:03 +01:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
# Backup the current version of the app
|
|
|
|
|
ynh_backup_before_upgrade
|
2017-12-03 19:24:03 +01:00
|
|
|
|
ynh_clean_setup () {
|
2020-05-17 09:28:22 +02:00
|
|
|
|
# restore it if the upgrade fails
|
|
|
|
|
ynh_restore_upgradebackup
|
2017-12-03 19:24:03 +01:00
|
|
|
|
}
|
2020-05-17 09:28:22 +02:00
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# CHECK THE PATH
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
# Normalize the URL path syntax
|
|
|
|
|
path_url=$(ynh_normalize_url_path --path_url=$path_url)
|
2017-12-03 19:24:03 +01:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# STANDARD UPGRADE STEPS
|
|
|
|
|
#=================================================
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Upgrading nginx web server configuration..." --weight=1
|
2017-05-18 20:45:58 +02:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
# Create a dedicated nginx config
|
|
|
|
|
ynh_add_nginx_config
|
2017-08-03 07:38:57 +02:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Upgrading dependencies..." --weight=12
|
2019-01-13 18:51:59 +01:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
# Migration: remove old repository if defined
|
|
|
|
|
if [ -f "/etc/apt/sources.list.d/grafana_stable.list" ] ; then
|
|
|
|
|
ynh_secure_remove --file="/etc/apt/sources.list.d/grafana_stable.list"
|
2017-02-18 16:45:43 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
ynh_install_extra_app_dependencies --repo="deb https://packages.grafana.com/oss/deb stable main" --package="grafana" --key="https://packages.grafana.com/gpg.key"
|
2017-02-18 16:45:43 +01:00
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
ynh_script_progression --message="Configuring Grafana and InfluxDB..." --weight=3
|
|
|
|
|
# If NetData is installed, configure it to feed InfluxDB
|
|
|
|
|
netdata_conf="/opt/netdata/etc/netdata/netdata.conf"
|
|
|
|
|
if [ -f "$netdata_conf" ] ; then
|
|
|
|
|
# If there is already a [backend] section
|
|
|
|
|
if [ -n "$(cat $netdata_conf | grep '\[backend\]')" ] ; then
|
|
|
|
|
# These regexps replaces patterns inside ini [sections] ([backend] section, here)
|
|
|
|
|
sed -i '/^\[backend\]$/,/^\[/ {
|
|
|
|
|
s/# enabled = no/enabled = yes/
|
|
|
|
|
s/# type = graphite/type = opentsdb/
|
|
|
|
|
s/# destination = localhost/destination = localhost:4242/
|
|
|
|
|
s/# update every = 10/update every = 60/
|
|
|
|
|
}' $netdata_conf
|
|
|
|
|
else
|
|
|
|
|
# Otherwise create the section
|
|
|
|
|
echo "[backend]
|
|
|
|
|
enabled = yes
|
|
|
|
|
type = opentsdb
|
|
|
|
|
destination = localhost:4242" | tee -a $netdata_conf
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Restart NetData
|
|
|
|
|
ynh_systemd_action --service_name=netdata --action="restart"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Update default dashboard for NetData (source: https://grafana.com/grafana/dashboards/2701)
|
|
|
|
|
# Remove new lines
|
|
|
|
|
tr -d '\n' < ../conf/netdata_dashboard.json > dashboard.json
|
|
|
|
|
# Fill the template with the defined data source
|
|
|
|
|
sed -i 's/${DS_CENTCOM-INFLUXDB}/InfluxDB/g' dashboard.json
|
|
|
|
|
# Escape the dashboard definition for MySQL query
|
|
|
|
|
dashboard=$(cat dashboard.json)
|
|
|
|
|
printf -v escaped_dashboard "%q" "$dashboard"
|
|
|
|
|
# Import dashboard into MySQL
|
|
|
|
|
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "UPDATE dashboard set data=\"$escaped_dashboard\" WHERE id=99999;"
|
|
|
|
|
# Insert dashboard version if non existent (for downward compatibility)
|
|
|
|
|
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name <<< "INSERT INTO dashboard_version (id, dashboard_id, parent_version, restored_from, version, created, created_by, message, data) VALUES (99999, 99999, 0, 0, 1, '2020-05-16 14:36:50', 1, 'YunoHost installer', \"$escaped_dashboard\");" > /dev/null 2>&1 || true
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# SETUP SSOWAT
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Upgrading SSOwat configuration..." --weight=1
|
|
|
|
|
|
|
|
|
|
# Make app public if necessary
|
|
|
|
|
if [ $is_public -eq 1 ]
|
|
|
|
|
then
|
|
|
|
|
# unprotected_uris allows SSO credentials to be passed anyway
|
|
|
|
|
ynh_app_setting_set --app=$app --key=unprotected_uris --value="/"
|
2017-02-18 16:45:43 +01:00
|
|
|
|
fi
|
|
|
|
|
|
2020-05-17 09:28:22 +02:00
|
|
|
|
#=================================================
|
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Restarting a systemd service..." --weight=2
|
|
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=grafana-server --action="restart" --log_path="/var/log/grafana/grafana.log" --line_match="HTTP Server Listen" --timeout=600
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# RELOAD NGINX
|
|
|
|
|
#=================================================
|
|
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --weight=1
|
|
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# END OF SCRIPT
|
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|