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
ericgaspar 917d2f0592 Fix
2021-08-23 11:55:13 +02:00

156 lines
5.6 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
### Remove this function if there's nothing to clean before calling the remove script.
true
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS FROM THE MANIFEST
#=================================================
export domain=$(cat /etc/yunohost/current_host)
export path_url=/.well-known/yunomonitor/
ynh_export monitored_servers monitoring_servers mails sms_api
app=$YNH_APP_INSTANCE_NAME
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
#=================================================
ynh_script_progression --message="Validating installation parameters..." --weight=1
final_path=/opt/$app
test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
#=================================================
# STORE SETTINGS FROM MANIFEST
#=================================================
ynh_script_progression --message="Storing installation settings..." --weight=1
ynh_save_args domain path_url monitored_servers monitoring_servers mails sms_api
#=================================================
# CREATE DEDICATED USER
#=================================================
ynh_script_progression --message="Configuring system user..." --weight=1
# Create a system user
ynh_system_user_create --username=$app --home_dir="$final_path"
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# INSTALL DEPENDENCIES
#=================================================
ynh_script_progression --message="Installing dependencies..." --weight=1
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
ynh_script_progression --message="Setting up source files..." --weight=1
ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
#=================================================
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Configuring NGINX web server..." --weight=1
# Create a dedicated nginx config
# Note: i don't use the helper because i need this file to be named "000-"
finalnginxconf="/etc/nginx/conf.d/$domain.d/000-$app.conf"
ynh_backup_if_checksum_is_different --file="$finalnginxconf"
cp ../conf/nginx.conf "$finalnginxconf"
ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$finalnginxconf"
ynh_store_file_checksum --file="$finalnginxconf"
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE SYSTEMD TIMER
#=================================================
ynh_add_systemd_config
cp ../conf/systemd.timer "/etc/systemd/system/$app.timer"
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/etc/systemd/system/$app.timer"
systemctl daemon-reload
systemctl enable $app.timer --quiet
systemctl start $app.timer
#=================================================
#=================================================
# MODIFY A CONFIG FILE
#=================================================
echo "mails: [$mails]" > $final_path/conf/$app.yml
echo "sms_apis: [$sms_api]" >> $final_path/conf/$app.yml
echo "monitored_servers: [$monitored_servers]" >> $final_path/conf/$app.yml
echo "monitoring_servers: [$monitoring_servers]" >> $final_path/conf/$app.yml
echo "cachet_apis: []" >> $final_path/conf/$app.yml
sed -i 's/,/","/g' $final_path/conf/$app.yml
sed -i 's/\[/["/g' $final_path/conf/$app.yml
sed -i 's/\]/"]/g' $final_path/conf/$app.yml
sed -i 's/\[""\]/[]/g' $final_path/conf/$app.yml
#=================================================
# STORE THE CONFIG FILE CHECKSUM
#=================================================
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$final_path/conf/$app.yml"
#=================================================
# INIT IGNORE FILE
#=================================================
echo "method level server message target" > $final_path/conf/ignore_alert.csv
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
# Set permissions to app files
chmod u+x $final_path/yunomonitor.py
chmod u+w $final_path/conf
chmod u+w $final_path/well-known
#=================================================
# 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="Installation of $app completed" --last