#!/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..." --time --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..." --time --weight=1 ynh_save_args domain path_url monitored_servers monitoring_servers mails sms_api #================================================= # STANDARD MODIFICATIONS #================================================= #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." --time --weight=1 ynh_install_app_dependencies $pkg_dependencies #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_script_progression --message="Setting up source files..." --time --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" #================================================= # NGINX CONFIGURATION #================================================= ynh_script_progression --message="Configuring nginx web server..." --time --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 #================================================= # CREATE DEDICATED USER #================================================= ynh_script_progression --message="Configuring system user..." --time --weight=1 # Create a system user ynh_system_user_create --username=$app #================================================= # 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 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" #================================================= # GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= # Set permissions to app files chown -R root: $final_path chown $app:$app $final_path/yunomonitor.py chmod u+x $final_path/yunomonitor.py chmod u+w $final_path/conf chmod u+w $final_path/well-known #================================================= # SETUP SSOWAT #================================================= ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" #================================================= # RELOAD NGINX #================================================= ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression --message="Installation of $app completed" --time --last