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
2024-01-19 16:44:31 +01:00

99 lines
3.1 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# INITIALIZE AND STORE SETTINGS
#=================================================
domain=$(yunohost domain list --json | jq -r '.["main"]')
path=/.well-known/yunomonitor/
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
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_setup_source --dest_dir="$install_dir"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R "$app:www-data" "$install_dir"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
_yunomonitor_add_nginx_config
#=================================================
# SPECIFIC SETUP
#=================================================
# BUILD YUNOMONITOR
#=================================================
ynh_script_progression --message="Building Yunomonitor..."
pushd "$install_dir"
python3 -m pip install pycryptodome pyyaml
popd
#=================================================
# SETUP SYSTEMD
#=================================================
ynh_script_progression --message="Configuring a systemd service..."
ynh_add_systemd_config
ynh_add_config --template="systemd.timer" --destination="/etc/systemd/system/$app.timer"
systemctl daemon-reload
systemctl enable "$app.timer" --quiet
systemctl start "$app.timer"
#=================================================
# ADD A CONFIGURATION
#=================================================
ynh_script_progression --message="Adding a configuration file..."
python3 -c '
import sys
import yaml
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]),
}))
' "$mails" "$sms_api" "$monitored_servers" "$monitoring_servers" \
> "$install_dir/conf/$app.yml"
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$install_dir/conf/$app.yml"
#=================================================
# INIT IGNORE FILE
#=================================================
echo "method level server message target" > "$install_dir/conf/ignore_alert.csv"
# Set permissions to app files
chmod u+x "$install_dir/yunomonitor.py"
chmod u+w "$install_dir/conf"
chmod u+w "$install_dir/well-known"
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Installation of $app completed" --last