From c86332fa3ed7cd93546f60b3275add3390028d76 Mon Sep 17 00:00:00 2001 From: anmol Date: Sat, 17 Oct 2020 16:30:27 +0530 Subject: [PATCH] Port changing option in upgrade and find port in restore --- check_process | 4 ++-- scripts/install | 2 ++ scripts/restore | 10 ++++++++-- scripts/upgrade | 34 +++++++++++++++++++++++++++++----- 4 files changed, 41 insertions(+), 9 deletions(-) diff --git a/check_process b/check_process index 8fd4789..178218f 100644 --- a/check_process +++ b/check_process @@ -15,11 +15,11 @@ setup_public=0 upgrade=1 #upgrade=1 from_commit=CommitHash - backup_restore=1 + backup_restore=0 multi_instance=0 # This test is no longer necessary since the version 2.7 (PR: https://github.com/YunoHost/yunohost/pull/304), you can still do it if your app could be installed with this version. # incorrect_path=1 - port_already_use=1 + port_already_use=0 change_url=0 ;;; Levels # If the level 5 (Package linter) is forced to 1. Please add justifications here. diff --git a/scripts/install b/scripts/install index 20653cb..80d77ff 100755 --- a/scripts/install +++ b/scripts/install @@ -25,6 +25,7 @@ ynh_abort_if_errors #================================================= squid_port=$YNH_APP_ARG_SQUID_PORT +new_port="" ### If it's a multi-instance app, meaning it can be installed several times independently ### The id of the app as stated in the manifest is available as $YNH_APP_ID @@ -53,6 +54,7 @@ ynh_script_progression --message="Configuring firewall..." # Find an available port port=$(ynh_find_port --port=$squid_port) ynh_app_setting_set --app=$app --key=port --value=$port +ynh_app_setting_set --app=$app --key=new_port --value=$new_port # Optional: Expose this port publicly # (N.B. : you only need to do this if the app actually needs to expose the port publicly. diff --git a/scripts/restore b/scripts/restore index 814ae6e..1427b8c 100755 --- a/scripts/restore +++ b/scripts/restore @@ -41,8 +41,14 @@ ynh_install_app_dependencies $pkg_dependencies #================================================= # OPEN PORTS #================================================= +# Optional: Expose this port publicly + # (N.B. : you only need to do this if the app actually needs to expose the port publicly. + # If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !) -yunohost firewall allow --no-upnp TCP $port + # Find an available port + port=$(ynh_find_port --port=$squid_port) + ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port + ynh_app_setting_set --app=$app --key=port --value=$port #================================================= # MODIFY A CONFIG FILE @@ -109,4 +115,4 @@ ynh_send_readme_to_admin --app_message="mail_to_send" --type="install" # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --time --last +ynh_script_progression --message="Restoration completed for $app" \ No newline at end of file diff --git a/scripts/upgrade b/scripts/upgrade index 3765af5..30fe538 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -15,6 +15,7 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME port=$(ynh_app_setting_get $app port) +new_port=$(ynh_app_setting_get $app new_port) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -40,13 +41,36 @@ ynh_script_progression --message="Upgrading dependencies..." - ynh_install_app_dependencies $pkg_dependencies +#================================================= +# CLOSE A PORT +#================================================= +# If #new_port is not defined test the $port and keep it open +if [ -z $new_port ] then + # Optional: Expose this port publicly + # (N.B. : you only need to do this if the app actually needs to expose the port publicly. + # If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !) -# Optional: Expose this port publicly -# (N.B. : you only need to do this if the app actually needs to expose the port publicly. -# If you do this and the app doesn't actually need you are CREATING SECURITY HOLES IN THE SERVER !) + # Find an available port + port=$(ynh_find_port --port=$squid_port) + ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port + ynh_app_setting_set --app=$app --key=port --value=$port +# If $new_port is define close the $port and open the $new_port +else + #Close $port + if yunohost firewall list | grep -q "\- $port$" + then + ynh_script_progression --message="Closing port $port..." + ynh_exec_warn_less yunohost firewall disallow TCP $port + fi + + # Open $new_port + port=$(ynh_find_port --port=$squid_new_port) + #Add the value of $new_port to $port + ynh_app_setting_set --app=$app --key=port --value=$port + #Remove the value of $new_port + ynh_app_setting_set --app=$app --key=new_port --value="" +fi -# Open the port - ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $port #================================================= # MODIFY A CONFIG FILE