From 6a3c942eea20a3ef96b54c37606f084be1d3e3b2 Mon Sep 17 00:00:00 2001 From: frju365 Date: Fri, 15 May 2020 22:09:18 +0200 Subject: [PATCH] clean everything --- scripts/_common.sh | 2 -- scripts/backup | 6 ----- scripts/install | 56 ++++------------------------------------------ scripts/remove | 23 ------------------- scripts/restore | 6 ----- scripts/upgrade | 51 ++++++++++++++++------------------------- 6 files changed, 23 insertions(+), 121 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 599d029..60c255d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -29,8 +29,6 @@ installation_mailisearch() { else ynh_die --message="Your OS Architecture is not supported" fi - curl https://github.com/meilisearch/MeiliSearch/releases/download/$latest/mailisearch-linux-$arch -O mailisearch mv mailisearch /usr/bin/mailisearch - } diff --git a/scripts/backup b/scripts/backup index 66fed72..e469b29 100644 --- a/scripts/backup +++ b/scripts/backup @@ -79,12 +79,6 @@ ynh_script_progression --message="Backing up systemd configuration..." --time -- ynh_backup --src_path="/etc/systemd/system/$app.service" -#================================================= -# BACKUP A CRON FILE -#================================================= - -ynh_backup --src_path="/etc/cron.d/$app" - #================================================= # START SYSTEMD SERVICE #================================================= diff --git a/scripts/install b/scripts/install index 506234a..d93fe03 100644 --- a/scripts/install +++ b/scripts/install @@ -46,7 +46,8 @@ if [ $i_data_path -ne 0 ] then test ! -e "$final_path" || ynh_die --message="This path already contains a folder" else - test ! -e "$data_path" || ynh_die --message="This path already contains a folder" + test ! -e "$data_path" || mkdir "$data_path" + final_path=$data_path fi # Register (book) web path @@ -61,6 +62,7 @@ ynh_app_setting_set --app=$app --key=domain --value=$domain ynh_app_setting_set --app=$app --key=path --value=$path_url ynh_app_setting_set --app=$app --key=master_key --value=$master_key ynh_app_setting_set --app=$app --key=is_public --value=$is_public +ynh_app_setting_set --app=$app --key=final_path --value=$final_path #================================================= # STANDARD MODIFICATIONS @@ -105,54 +107,12 @@ ynh_system_user_create --username=$app #================================================= ynh_script_progression --message="Configuring a systemd service..." --time --weight=1 -### `ynh_systemd_config` is used to configure a systemd script for an app. -### It can be used for apps that use sysvinit (with adaptation) or systemd. -### Have a look at the app to be sure this app needs a systemd script. -### `ynh_systemd_config` will use the file conf/systemd.service -### If you're not using these lines: -### - You can remove those files in conf/. -### - Remove the section "BACKUP SYSTEMD" in the backup script -### - Remove also the section "STOP AND REMOVE SERVICE" in the remove script -### - As well as the section "RESTORE SYSTEMD" in the restore script -### - And the section "SETUP SYSTEMD" in the upgrade script - -ynh_replace_string "__PORT__" "$port" "conf/systemd.service" ynh_replace_string "__PORT__" "$port" "conf/systemd.service" +ynh_replace_string "__API_KEY__" "$master_key" "conf/systemd.service" # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# SETUP APPLICATION WITH CURL -#================================================= - -### Use these lines only if the app installation needs to be finalized through -### web forms. We generally don't want to ask the final user, -### so we're going to use curl to automatically fill the fields and submit the -### forms. - -# Set right permissions for curl install -chown -R $app: $final_path - -# Set the app as temporarily public for curl call -ynh_script_progression --message="Configuring SSOwat..." --time --weight=1 -ynh_app_setting_set --app=$app --key=skipped_uris --value="/" -# Reload SSOwat config -yunohost app ssowatconf - -# Reload Nginx -ynh_systemd_action --service_name=nginx --action=reload - -# Installation with curl -ynh_script_progression --message="Finalizing installation..." --time --weight=1 -ynh_local_curl "/INSTALL_PATH" "key1=value1" "key2=value2" "key3=value3" - -# Remove the public access -if [ $is_public -eq 0 ] -then - ynh_app_setting_delete --app=$app --key=skipped_uris -fi - #================================================= # GENERIC FINALIZATION #================================================= @@ -174,14 +134,6 @@ ynh_use_logrotate # INTEGRATE SERVICE IN YUNOHOST #================================================= -### `yunohost service add` integrates a service in YunoHost. It then gets -### displayed in the admin interface and through the others `yunohost service` commands. -### (N.B. : this line only makes sense if the app adds a service to the system!) -### If you're not using these lines: -### - You can remove these files in conf/. -### - Remove the section "REMOVE SERVICE FROM ADMIN PANEL" in the remove script -### - As well as the section "ADVERTISE SERVICE IN ADMIN PANEL" in the restore script - yunohost service add $app --description "A short description of the app" --log "/var/log/$app/$app.log" #================================================= diff --git a/scripts/remove b/scripts/remove index 81734c9..fbb2887 100644 --- a/scripts/remove +++ b/scripts/remove @@ -41,14 +41,6 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --time --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - #================================================= # REMOVE NGINX CONFIGURATION #================================================= @@ -91,21 +83,6 @@ ynh_script_progression --message="Removing fail2ban configuration..." --time --w # Remove the dedicated fail2ban config ynh_remove_fail2ban_config -#================================================= -# SPECIFIC REMOVE -#================================================= -# REMOVE THE CRON FILE -#================================================= - -# Remove a cron file -ynh_secure_remove --file="/etc/cron.d/$app" - -# Remove a directory securely -ynh_secure_remove --file="/etc/$app/" - -# Remove the log files -ynh_secure_remove --file="/var/log/$app/" - #================================================= # GENERIC FINALIZATION #================================================= diff --git a/scripts/restore b/scripts/restore index aa0675f..7545eb0 100644 --- a/scripts/restore +++ b/scripts/restore @@ -98,12 +98,6 @@ ynh_script_progression --message="Starting a systemd service..." --time --weight ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" -#================================================= -# RESTORE THE CRON FILE -#================================================= - -ynh_restore_file --origin_path="/etc/cron.d/$app" - #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index c1564fd..feb2120 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -21,6 +21,8 @@ domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +master_key=$(ynh_app_setting_get --app=$app --key=master_key) +$port=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # CHECK VERSION @@ -49,6 +51,16 @@ if [ -z "$final_path" ]; then ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi +#================================================= +# FIND AND OPEN A PORT +#================================================= + +ynh_script_progression --message="Configuring firewall..." --time --weight=1 + +# Find an available port +port=$(ynh_find_port --port=8095) +ynh_app_setting_set --app=$app --key=port --value=$port + #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= @@ -78,18 +90,6 @@ path_url=$(ynh_normalize_url_path --path_url=$path_url) ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" -#================================================= -# DOWNLOAD, CHECK AND UNPACK SOURCE -#================================================= - -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." --time --weight=1 - - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" -fi - #================================================= # NGINX CONFIGURATION #================================================= @@ -99,11 +99,11 @@ ynh_script_progression --message="Upgrading nginx web server configuration..." - ynh_add_nginx_config #================================================= -# UPGRADE DEPENDENCIES +# UPGRADING MAILISEARCH #================================================= -ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 +ynh_script_progression --message="Upgrading mailisearch..." --time --weight=1 -ynh_install_app_dependencies $pkg_dependencies +installation_mailisearch #================================================= # CREATE DEDICATED USER @@ -113,26 +113,10 @@ ynh_script_progression --message="Making sure dedicated system user exists..." - # Create a dedicated user (if not existing) ynh_system_user_create --username=$app -#================================================= -# PHP-FPM CONFIGURATION -#================================================= -ynh_script_progression --message="Upgrading php-fpm configuration..." --time --weight=1 - -# Create a dedicated php-fpm config -ynh_add_fpm_config - -#================================================= -# SPECIFIC UPGRADE -#================================================= -# ... -#================================================= - #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= -### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. -### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. ynh_backup_if_checksum_is_different --file="$final_path/CONFIG_FILE" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$final_path/CONFIG_FILE" @@ -148,7 +132,10 @@ ynh_use_logrotate --non-append #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 +ynh_script_progression --message="Configuring a systemd service..." --time --weight=1 + +ynh_replace_string "__PORT__" "$port" "conf/systemd.service" +ynh_replace_string "__API_KEY__" "$master_key" "conf/systemd.service" # Create a dedicated systemd config ynh_add_systemd_config