1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/yunomonitor_ynh.git synced 2024-09-03 17:46:11 +02:00
yunomonitor_ynh/scripts/install

100 lines
3.1 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
2024-01-19 16:41:23 +01:00
# INITIALIZE AND STORE SETTINGS
#=================================================
2023-12-11 12:37:28 +01:00
domain=$(yunohost domain list --json | jq -r '.["main"]')
path=/.well-known/yunomonitor/
2023-12-11 12:37:28 +01:00
ynh_app_setting_set --app="$app" --key="domain" --value="$domain"
ynh_app_setting_set --app="$app" --key="path" --value="$path"
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2020-10-04 22:11:03 +02:00
ynh_script_progression --message="Setting up source files..." --weight=1
2023-12-11 12:37:28 +01:00
ynh_setup_source --dest_dir="$install_dir"
2023-12-11 12:37:28 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
2021-08-23 11:55:13 +02:00
#=================================================
# NGINX CONFIGURATION
#=================================================
2021-08-23 09:13:30 +02:00
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
2023-12-11 12:37:28 +01:00
_yunomonitor_add_nginx_config
#=================================================
# SPECIFIC SETUP
2022-02-08 00:24:18 +01:00
#=================================================
# BUILD YUNOMONITOR
#=================================================
ynh_script_progression --message="Building Yunomonitor..."
2023-12-11 12:37:28 +01:00
pushd "$install_dir"
2024-01-19 16:41:23 +01:00
python3 -m pip install pycryptodome pyyaml
2022-02-08 00:24:18 +01:00
popd
#=================================================
2022-01-27 02:21:23 +01:00
# SETUP SYSTEMD
#=================================================
2022-01-27 02:21:23 +01:00
ynh_script_progression --message="Configuring a systemd service..."
2021-08-16 09:20:33 +02:00
ynh_add_systemd_config
2023-12-11 12:37:28 +01:00
ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$app.timer"
systemctl daemon-reload
2023-12-11 12:37:28 +01:00
systemctl enable "$app.timer" --quiet
systemctl start "$app.timer"
2021-08-16 09:20:33 +02:00
#=================================================
2022-01-27 02:21:23 +01:00
# ADD A CONFIGURATION
#=================================================
2022-01-27 02:21:23 +01:00
ynh_script_progression --message="Adding a configuration file..."
2024-01-19 16:41:23 +01:00
python3 -c '
import sys
import yaml
2024-01-19 16:44:13 +01:00
split_or_empty = lambda x: [] if x == "" else x.split(",")
print(yaml.dump({
"mails": split_or_empty(sys.argv[1]),
"sms_apis": split_or_empty(sys.argv[2]),
"monitored_servers": split_or_empty(sys.argv[3]),
"monitoring_servers": split_or_empty(sys.argv[4]),
2024-01-19 16:41:23 +01:00
}))
' "$mails" "$sms_api" "$monitored_servers" "$monitoring_servers" \
> "$install_dir/conf/$app.yml"
# Calculate and store the config file checksum into the app settings
2023-12-11 12:37:28 +01:00
ynh_store_file_checksum --file="$install_dir/conf/$app.yml"
2019-12-03 00:28:26 +01:00
#=================================================
# INIT IGNORE FILE
#=================================================
2023-12-11 12:37:28 +01:00
echo "method level server message target" > "$install_dir/conf/ignore_alert.csv"
2019-12-03 00:28:26 +01:00
# Set permissions to app files
2023-12-11 12:37:28 +01:00
chmod u+x "$install_dir/yunomonitor.py"
chmod u+w "$install_dir/conf"
chmod u+w "$install_dir/well-known"
#=================================================
# END OF SCRIPT
#=================================================
2020-10-04 22:11:03 +02:00
ynh_script_progression --message="Installation of $app completed" --last