diff --git a/scripts/change_url b/scripts/change_url index 74e8caf..5ab9bed 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -30,6 +30,9 @@ ynh_print_info --message="Loading installation settings..." final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Add settings here as needed by your application +#db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#db_user=$db_name +#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) port=$(ynh_app_setting_get --app=$app --key=port) #================================================= @@ -50,6 +53,13 @@ fi #================================================= # STANDARD MODIFICATIONS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Stopping a systemd service..." + +ynh_systemd_action --service_name=$app --action=stop --log_path=systemd --line_match="Stopped Distbin Service" + #================================================= # MODIFY URL IN NGINX CONF #================================================= @@ -81,15 +91,10 @@ fi #================================================= # SPECIFIC MODIFICATIONS -#================================================= -# STOP SERVICE -#================================================= - -ynh_systemd_action --action=stop --service_name=$app --log_path=systemd --line_match="Stopped Distbin Service" - #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_print_info --message="Modifying config file..." # Change the URL in the configuration file @@ -102,19 +107,25 @@ fi ynh_replace_string --match_string="EXTERNAL_URL=.*" --replace_string="EXTERNAL_URL=https://$new_domain_uri/" --target_file="$final_path/.env" +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= +ynh_print_info --message="Storing the config file checksum..." + ynh_backup_if_checksum_is_different --file="$final_path/.env" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$final_path/.env" #================================================= -# START SERVICE +# GENERIC FINALISATION #================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Starting a systemd service..." ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Started Distbin Service" sleep 10 -#================================================= -# GENERIC FINALISATION #================================================= # RELOAD NGINX #================================================= diff --git a/scripts/install b/scripts/install index 99333d9..899e2b7 100644 --- a/scripts/install +++ b/scripts/install @@ -54,24 +54,24 @@ ynh_app_setting_set --app=$app --key=is_public --value=$is_public #================================================= # FIND AND OPEN A PORT #================================================= -ynh_print_info --message="Configuring firewall ..." +ynh_print_info --message="Configuring firewall..." # Find a free port -port=$(ynh_find_port 8095) +port=$(ynh_find_port --port=8095) ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_print_info --message="Installing dependencies ..." +ynh_print_info --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs 10 +ynh_install_nodejs --nodejs_version="10" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_print_info --message="Setting up source files ..." +ynh_print_info --message="Setting up source files..." ynh_app_setting_set --app=$app --key=final_path --value=$final_path # Download, check integrity, uncompress and patch the source from app.src @@ -88,16 +88,17 @@ ynh_add_nginx_config #================================================= # CREATE DEDICATED USER #================================================= -ynh_print_info --message="Configuring system user ..." +ynh_print_info --message="Configuring system user..." # Create a system user -ynh_system_user_create "$app" "$final_path" +ynh_system_user_create --username="$app" --home_dir="$final_path" #================================================= # SPECIFIC SETUP #================================================= # CREATE LOG FOLDER #================================================= +ynh_print_info --message="Creating log folder..." mkdir -p "/var/log/$app" chown -R "$app":"$app" "/var/log/$app" @@ -105,16 +106,19 @@ chown -R "$app":"$app" "/var/log/$app" #================================================= # CREATE DB FOLDER #================================================= +ynh_print_info --message="Creating DB folder..." mkdir -p "$final_path/distbin-db" mkdir -p "$final_path/distbin-db/activities" mkdir -p "$final_path/distbin-db/inbox" #================================================= -# MAKE SETUP +# INSTALLING DISTBIN #================================================= +ynh_print_info --message="Installing distin..." chown -R "$app":"$app" "$final_path" + pushd $final_path ynh_use_nodejs sudo -u $app env PATH=$PATH npm install --ignore-scripts @@ -126,11 +130,10 @@ pushd $final_path/dist sudo -u $app env PATH=$PATH npm install --ignore-scripts --production popd - #================================================= # SETUP SYSTEMD #================================================= -ynh_print_info --message="Configuring a systemd service ..." +ynh_print_info --message="Configuring a systemd service..." # Create a dedicated systemd config ynh_add_systemd_config @@ -138,6 +141,7 @@ ynh_add_systemd_config #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_print_info --message="Modifying a config file..." cp "../conf/.env" "$final_path/.env" @@ -156,6 +160,7 @@ ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= +ynh_print_info --message="Storing the config file checksum..." # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$final_path/.env" @@ -165,6 +170,7 @@ ynh_store_file_checksum --file="$final_path/.env" #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_print_info --message="Securing files and directories..." # Set permissions to app files chown -R "$app":"$app" "$final_path" @@ -172,7 +178,7 @@ chown -R "$app":"$app" "$final_path" #================================================= # SETUP LOGROTATE #================================================= -ynh_print_info --message="Configuring log rotation ..." +ynh_print_info --message="Configuring log rotation..." # Use logrotate to manage application logfile(s) ynh_use_logrotate @@ -180,15 +186,24 @@ ynh_use_logrotate #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= +ynh_print_info --message="Advertising service in admin panel..." #yunohost service add $app --log "/var/log/$app/$app.log" # if using yunohost version 3.2 or more in the 'manifest.json', a description can be added yunohost service add $app --description "$app daemon for distbin" --log "/var/log/$app/$app.log" +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Distbin Service" +sleep 10 + #================================================= # SETUP SSOWAT #================================================= -ynh_print_info --message="Configuring SSOwat ..." +ynh_print_info --message="Configuring SSOwat..." # Make app public if necessary if [ $is_public -eq 1 ] @@ -202,14 +217,7 @@ fi #================================================= ynh_print_info --message="Reloading nginx web server..." -systemctl reload nginx - -#================================================= -# START SERVICE -#================================================= - -ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Started Distbin Service" -sleep 10 +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index a797fe9..e1a3a52 100644 --- a/scripts/remove +++ b/scripts/remove @@ -29,14 +29,14 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) # Remove a service from the admin panel, added by `yunohost service add` if yunohost service status $app >/dev/null 2>&1 then - ynh_print_info --message="Removing $app service" + ynh_print_info --message="Removing $app service..." yunohost service remove $app fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_print_info --message="Stopping and removing the systemd service" +ynh_print_info --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config @@ -44,7 +44,7 @@ ynh_remove_systemd_config #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_print_info --message="Removing dependencies" +ynh_print_info --message="Removing dependencies..." # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -53,7 +53,7 @@ ynh_remove_nodejs #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_print_info --message="Removing app main directory" +ynh_print_info --message="Removing app main directory..." # Remove the app directory securely ynh_secure_remove --file="$final_path" @@ -61,7 +61,7 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_print_info --message="Removing nginx web server configuration" +ynh_print_info --message="Removing nginx web server configuration..." # Remove the dedicated nginx config ynh_remove_nginx_config @@ -69,7 +69,7 @@ ynh_remove_nginx_config #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_print_info --message="Removing logrotate configuration" +ynh_print_info --message="Removing logrotate configuration..." # Remove the app-specific logrotate config ynh_remove_logrotate @@ -77,11 +77,10 @@ ynh_remove_logrotate #================================================= # CLOSE A PORT #================================================= -ynh_print_info --message="Closing a port..." if yunohost firewall list | grep -q "\- $port$" then - ynh_print_info --message="Closing port $port" + ynh_print_info --message="Closing port $port..." ynh_exec_warn_less yunohost firewall disallow TCP $port fi @@ -99,7 +98,7 @@ ynh_secure_remove --file="/var/log/$app/" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_print_info --message="Removing the dedicated system user" +ynh_print_info --message="Removing the dedicated system user..." # Delete a system user ynh_system_user_delete --username=$app diff --git a/scripts/restore b/scripts/restore index e745f06..55505bd 100644 --- a/scripts/restore +++ b/scripts/restore @@ -68,6 +68,7 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # RESTORE USER RIGHTS #================================================= +ynh_print_info --message="Securing files and directories..." # Restore permissions on app files chown -R "$app":"$app" "$final_path" @@ -77,6 +78,7 @@ chown -R "$app":"$app" "$final_path" #================================================= # CREATE LOG FOLDER #================================================= +ynh_print_info --message="Creating log folder..." mkdir -p "/var/log/$app" chown -R "$app":"$app" "/var/log/$app" @@ -88,7 +90,7 @@ ynh_print_info --message="Reinstalling dependencies..." # Define and install dependencies ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs 10 +ynh_install_nodejs --nodejs_version="10" #================================================= # RESTORE SYSTEMD @@ -102,9 +104,18 @@ systemctl daemon-reload #================================================= # ADVERTISE SERVICE IN ADMIN PANEL #================================================= +ynh_print_info --message="Advertising service in admin panel..." yunohost service add $app --log "/var/log/$app/$app.log" +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Starting a systemd service..." + +ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Distbin Service" +sleep 10 + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= @@ -118,21 +129,7 @@ ynh_restore_file --origin_path="/etc/logrotate.d/$app" #================================================= ynh_print_info --message="Reloading nginx web server..." -systemctl reload nginx - -#================================================= -# CREATE LOG FOLDER -#================================================= - -mkdir -p "/var/log/$app" -chown -R "$app":"$app" "/var/log/$app" - -#================================================= -# START SERVICE -#================================================= - -ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Started Distbin Service" -sleep 10 +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 5c9d7fa..3e3b9c8 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -22,6 +22,12 @@ is_public=$(ynh_app_setting_get --app=$app --key=is_public) final_path=$(ynh_app_setting_get --app=$app --key=final_path) port=$(ynh_app_setting_get --app=$app --key=port) +#================================================= +# CHECK VERSION +#================================================= + +upgrade_type=$(ynh_check_app_version_changed) + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -37,7 +43,7 @@ elif [ "$is_public" = "No" ]; then fi # If final_path doesn't exist, create it -if [ -z $final_path ]; then +if [ -z "$final_path" ]; then final_path=/var/www/$app ynh_app_setting_set --app=$app --key=final_path --value=$final_path fi @@ -57,21 +63,28 @@ ynh_clean_setup () { # Exit if an error occurs during the execution of the script ynh_abort_if_errors -#================================================= -# STOP SERVICE -#================================================= - -ynh_systemd_action --action=stop --service_name=$app - #================================================= # STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Stopping a systemd service..." + +ynh_systemd_action --service_name=$app --action=stop + #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= ynh_print_info --message="Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src# -ynh_setup_source --dest_dir="$final_path" +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 @@ -87,8 +100,7 @@ ynh_add_nginx_config ynh_print_info --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies -ynh_remove_nodejs -ynh_install_nodejs 10 +ynh_install_nodejs --nodejs_version="10" #================================================= # CREATE DEDICATED USER @@ -100,9 +112,18 @@ ynh_system_user_create --username=$app --home_dir=$final_path #================================================= # SPECIFIC UPGRADE +#================================================= +# CREATE LOG FOLDER +#================================================= +ynh_print_info --message="Creating log folder..." + +mkdir -p "/var/log/$app" +chown -R "$app":"$app" "/var/log/$app" + #================================================= # CREATE STORAGE FOLDER #================================================= +ynh_print_info --message="Creating storage folder..." DIRECTORY="$final_path/db" #Move old db @@ -113,6 +134,7 @@ fi #================================================= # MAKE INSTALL #================================================= +ynh_print_info --message="Making install..." chown -R "$app":"$app" "$final_path" pushd $final_path @@ -129,6 +151,7 @@ popd #================================================= # MODIFY A CONFIG FILE #================================================= +ynh_print_info --message="Modifying config file..." cp "../conf/.env" "$final_path/.env" @@ -144,6 +167,11 @@ ynh_replace_string --match_string="__PORT__" --replace_string="$port" --target_f ynh_replace_string --match_string="__DOMAIN_URI__" --replace_string="$domain_uri" --target_file="$final_path/.env" ynh_replace_string --match_string="__FINALPATH__" --replace_string="$final_path" --target_file="$final_path/.env" +#================================================= +# STORE THE CONFIG FILE CHECKSUM +#================================================= +ynh_print_info --message="Storing the config file checksum..." + ynh_backup_if_checksum_is_different --file="$final_path/.env" # Recalculate and store the checksum of the file for the next upgrade. ynh_store_file_checksum --file="$final_path/.env" @@ -169,17 +197,11 @@ ynh_add_systemd_config #================================================= # SECURE FILES AND DIRECTORIES #================================================= +ynh_print_info --message="Securing files and directories..." # Set permissions on app files chown -R $app:$app $final_path -#================================================= -# CREATE LOG FOLDER -#================================================= - -mkdir -p "/var/log/$app" -chown -R "$app":"$app" "/var/log/$app" - #================================================= # SETUP SSOWAT #================================================= @@ -192,19 +214,20 @@ then ynh_app_setting_set --app=$app --key=unprotected_uris --value="/" fi +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_print_info --message="Starting a systemd service..." + +ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Started Distbin Service" +sleep 10 + #================================================= # RELOAD NGINX #================================================= ynh_print_info --message="Reloading nginx web server..." -systemctl reload nginx - -#================================================= -# START SERVICE -#================================================= - -ynh_systemd_action --action=start --service_name=$app --log_path=systemd --line_match="Started Distbin Service" -sleep 10 +ynh_systemd_action --service_name=nginx --action=reload #================================================= # END OF SCRIPT