From 36962f384f6deabbed8c05ab1ba2e5f6abd1abf1 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Sun, 13 Mar 2022 16:50:54 +0100 Subject: [PATCH] Apply last example_ynh --- check_process | 10 ++--- conf/squid.conf | 2 +- doc/.gitkeep | 0 doc/DESCRIPTION.md | 3 ++ doc/DISCLAIMER.md | 20 +++++++++ doc/screenshots/.gitkeep | 0 manifest.json | 8 +++- scripts/_common.sh | 8 ++++ scripts/backup | 9 +++- scripts/install | 34 ++++++--------- scripts/remove | 10 ++--- scripts/restore | 52 ++++++++++++++--------- scripts/upgrade | 90 +++++++++++++++++----------------------- 13 files changed, 139 insertions(+), 107 deletions(-) create mode 100644 doc/.gitkeep create mode 100644 doc/DESCRIPTION.md create mode 100644 doc/DISCLAIMER.md create mode 100644 doc/screenshots/.gitkeep diff --git a/check_process b/check_process index 8f035db..2d18291 100644 --- a/check_process +++ b/check_process @@ -1,8 +1,3 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - ;; Test complet ; Manifest port="8095" (PORT) @@ -14,7 +9,12 @@ setup_private=0 setup_public=0 upgrade=1 + # 1.0~ynh2 + upgrade=1 from_commit=e1920eb3c212ae8d09a6e2fd8188b2f93aed0707 backup_restore=1 multi_instance=0 port_already_use=0 change_url=0 +;;; Options +Email= +Notification=none diff --git a/conf/squid.conf b/conf/squid.conf index 9398477..f25381d 100644 --- a/conf/squid.conf +++ b/conf/squid.conf @@ -42,7 +42,7 @@ http_access deny all ##cache DNS en local dns_nameservers 127.0.0.1 ##Port d'écoute du Proxy -http_port __PORT__ +http_port __SQUID_PORT__ forwarded_for off ### mode transparant, la vrai IP est cachée cache_dir aufs /var/spool/__SQUID__ 10000 16 256 hierarchy_stoplist cgi-bin ? diff --git a/doc/.gitkeep b/doc/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/doc/DESCRIPTION.md b/doc/DESCRIPTION.md new file mode 100644 index 0000000..c58434f --- /dev/null +++ b/doc/DESCRIPTION.md @@ -0,0 +1,3 @@ +## Squid: Proxy with Optimising Web Delivery + +Squid is a caching proxy for the Web supporting HTTP, HTTPS, FTP, and more. It reduces bandwidth and improves response times by caching and reusing frequently-requested web pages. Squid has extensive access controls and makes a great server accelerator. diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md new file mode 100644 index 0000000..7d1669a --- /dev/null +++ b/doc/DISCLAIMER.md @@ -0,0 +1,20 @@ +## Instruction + +1. The app can not be **multi-instance**(can't be installed many times on same server). +2. **LDAP** is there(Registered users can use there login username and password to browser internet through the proxy) +3. **Port number** used by the proxy will be sent to the **admin mail** of the Yunohost server. +4. The username and password is **asked twice** first time you start the browser(I have no idea why this happens). + +## Configure Squid3 for Firefox + +1. Go to **Preferences -> General -> network proxy** +1. Select **Manual proxy configuration** +1. In **HTTP Proxy** enter your **domain name or server IP** and in **Port** enter the port sent to your **admin email**. +1. Check **Use this proxy server for all protocols**. +1. Under **No Proxy for** enter this **localhost, 127.0.0.1**. +1. **Save and restart** the Firefox. + +If you try Squid 3 in any other way please write the instruction in the issue so that I can add it to the readme + +## Special Thanks +Thanks to **Fred** to write the instruction to configure Squid for YunoHost. French: https://memo-linux.com/installer-squid3-sur-un-serveur-yunohost/ diff --git a/doc/screenshots/.gitkeep b/doc/screenshots/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/manifest.json b/manifest.json index d27d0eb..048ddd3 100644 --- a/manifest.json +++ b/manifest.json @@ -6,15 +6,19 @@ "en": "Caching proxy for the Web supporting HTTP, HTTPS, FTP and more.", "fr": "Proxy cache pour le web, compatible HTTP, HTTPS, FTP et plus encore." }, - "version": "1.0~ynh2", + "version": "1.0~ynh3", "url": "http://www.squid-cache.org/", + "upstream": { + "license": "GPL-2.0-only", + "website": "http://www.squid-cache.org" + }, "license": "GPL-2.0-only", "maintainer": { "name": "Anmol Sharma", "email": "anmol@datamol.org" }, "requirements": { - "yunohost": ">= 3.8.1" + "yunohost": ">= 4.3.0" }, "multi_instance": false, "services": [], diff --git a/scripts/_common.sh b/scripts/_common.sh index 57f1bda..169efef 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -7,6 +7,14 @@ # dependencies used by the app pkg_dependencies="squid3 mailutils" +#================================================= +# PERSONAL HELPERS +#================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + #================================================= # FUTURE OFFICIAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index f1247fe..048c0bc 100755 --- a/scripts/backup +++ b/scripts/backup @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -13,6 +14,9 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + true +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -22,10 +26,11 @@ ynh_abort_if_errors ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -squid=$(ynh_app_setting_get $app squid_folder) + +squid=$(ynh_app_setting_get --app=$app --key=squid_folder) #================================================= -# BACKUP OF THE CONFIG OF SQUID3 +# BACKUP VARIOUS FILES #================================================= ynh_backup --src_path="/etc/$squid/squid.conf" diff --git a/scripts/install b/scripts/install index 3f69c80..d898bc8 100755 --- a/scripts/install +++ b/scripts/install @@ -21,7 +21,6 @@ ynh_abort_if_errors #================================================= squid_port=$YNH_APP_ARG_SQUID_PORT -new_port="" app=$YNH_APP_INSTANCE_NAME @@ -35,10 +34,10 @@ ynh_script_progression --message="Configuring firewall..." # Find an available port squid_port=$(ynh_find_port --port=$squid_port) ynh_app_setting_set --app=$app --key=squid_port --value=$squid_port -ynh_app_setting_set --app=$app --key=new_port --value=$new_port # Open the port - ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $squid_port +ynh_script_progression --message="Configuring firewall..." +ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $squid_port #================================================= # INSTALL DEPENDENCIES @@ -48,42 +47,37 @@ ynh_script_progression --message="Installing dependencies..." ynh_install_app_dependencies $pkg_dependencies #================================================= -# MODIFY A CONFIG FILE +# SPECIFIC SETUP #================================================= +# ADD A CONFIGURATION +#================================================= +ynh_script_progression --message="Adding a configuration file..." # See if squid3 folder exits if [ -d "/etc/squid3" ]; then - squid="squid3" + squid="squid3" # If squid3 folder is not found look for squid folder elif [ -d "/etc/squid" ]; then - squid="squid" + squid="squid" # If both folders are not found then call ynh_die else - ynh_die "No squid folder found in /etc. Looks like squid 3 package is not installed. Try installing it manually." + ynh_die --message="No squid folder found in /etc. Looks like squid3 package is not installed. Try installing it manually." fi -ynh_replace_string --match_string="__PORT__" --replace_string="$squid_port" --target_file="../conf/squid.conf" -ynh_replace_string --match_string="__SQUID__" --replace_string="$squid" --target_file="../conf/squid.conf" -cp -f "../conf/squid.conf" "/etc/$squid/." -# Save squid folder in app settings - ynh_app_setting_set --app=$app --key=squid_folder --value=$squid -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -# Calculate and store the config file checksum into the app settings -ynh_store_file_checksum --file="/etc/$squid/squid.conf" +ynh_add_config --template="../conf/squid.conf" --destination="/etc/$squid/squid.conf" +#================================================= +# GENERIC FINALIZATION #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add $app --description "Squid3 a web proxy service" --log "/var/log/$squid/access.log" +yunohost service add $app --description "Squid3 a web proxy service" --log="/var/log/$squid/access.log" --needs_exposed_ports $squid_port #================================================= # START SYSTEMD SERVICE @@ -93,8 +87,6 @@ ynh_script_progression --message="Starting a systemd service..." # Start a systemd service ynh_systemd_action --service_name=$squid --action="restart" --log_path="/var/log/$squid/cache.log" -yunohost app ssowatconf - #================================================= # SEND A README FOR THE ADMIN #================================================= diff --git a/scripts/remove b/scripts/remove index c8335b3..a38a978 100755 --- a/scripts/remove +++ b/scripts/remove @@ -16,8 +16,8 @@ ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -squid_port=$(ynh_app_setting_get $app squid_port) -squid=$(ynh_app_setting_get $app squid_folder) +squid_port=$(ynh_app_setting_get --app=$app --key=squid_port) +squid=$(ynh_app_setting_get --app=$app --key=squid_folder) #================================================= # STANDARD REMOVE @@ -25,10 +25,10 @@ squid=$(ynh_app_setting_get $app squid_folder) # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -# Remove the service from the list of services known by Yunohost (added from `yunohost service add`) +# Remove the service from the list of services known by YunoHost (added from `yunohost service add`) if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Remove $squid service" + ynh_script_progression --message="Removing $app service integration..." yunohost service remove $app fi @@ -58,7 +58,7 @@ fi ynh_secure_remove --file="/etc/$squid/" # Remove the log files -ynh_secure_remove --file="/var/log/$squid/access.log" +ynh_secure_remove --file="/var/log/$squid" #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 0f05cd2..12ab984 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,6 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -13,23 +14,29 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -squid_port=$(ynh_app_setting_get $app squid_port) +squid_port=$(ynh_app_setting_get --app=$app --key=squid_port) #================================================= # SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= +ynh_script_progression --message="Reinstalling dependencies..." +# Define and install dependencies ynh_install_app_dependencies $pkg_dependencies #================================================= @@ -44,36 +51,41 @@ ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $squid_port ynh_app_setting_set --app=$app --key=squid_port --value=$squid_port #================================================= -# MODIFY A CONFIG FILE +# ADD A CONFIGURATION #================================================= +ynh_script_progression --message="Adding a configuration file..." -# See is squid3 folder is there +# See if squid3 folder exits if [ -d "/etc/squid3" ]; then - squid="squid3" - # If squid3 folder is not found look for squid folder + squid="squid3" + +# If squid3 folder is not found look for squid folder elif [ -d "/etc/squid" ]; then - squid="squid" + squid="squid" + # If both folders are not found then call ynh_die else - ynh_die "No squid folder found in /etc. Looks like squid 3 package is not installed. Try installing it manually." + ynh_die --message="No squid folder found in /etc. Looks like squid3 package is not installed. Try installing it manually." fi - -# Save squid folder ynh_app_setting_set --app=$app --key=squid_folder --value=$squid -#================================================= -# RESTORE INOTIFY'S CONFIG -#================================================= -ynh_secure_remove "/etc/$squid/squid.conf" -ynh_restore_file "/etc/$squid/squid.conf" -service $squid restart -yunohost app ssowatconf -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= +ynh_add_config --template="../conf/squid.conf" --destination="/etc/$squid/squid.conf" -yunohost service add squid3 --log "/var/log/$squid/cache.log" +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." + +yunohost service add $app --description "Squid3 a web proxy service" --log="/var/log/$squid/access.log" --needs_exposed_ports $squid_port + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." + +# Start a systemd service +ynh_systemd_action --service_name=$squid --action="restart" --log_path="/var/log/$squid/cache.log" #================================================= # SEND A README FOR THE ADMIN diff --git a/scripts/upgrade b/scripts/upgrade index 7f45d5d..780a711 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,10 +12,19 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= +ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -squid_port=$(ynh_app_setting_get $app squid_port) -new_port=$(ynh_app_setting_get $app new_port) + +squid_port=$(ynh_app_setting_get --app=$app --key=squid_port) +squid=$(ynh_app_setting_get --app=$app --key=squid_folder) + +#================================================= +# CHECK VERSION +#================================================= +ynh_script_progression --message="Checking version..." + +upgrade_type=$(ynh_check_app_version_changed) #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP @@ -25,14 +34,27 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - # restore it if the upgrade fails + ynh_clean_check_starting + # Restore it if the upgrade fails ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= -# SPECIFIC RESTORATION +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." + +ynh_systemd_action --service_name=$squid --action="stop" --log_path="/var/log/$squid/cache.log" + +#================================================= +# ENSURE DOWNWARD COMPATIBILITY +#================================================= +ynh_script_progression --message="Ensuring downward compatibility..." + #================================================= # UPGRADE DEPENDENCIES #================================================= @@ -41,74 +63,40 @@ ynh_script_progression --message="Upgrading dependencies..." ynh_install_app_dependencies $pkg_dependencies #================================================= -# CLOSE A PORT +# UPDATE A CONFIG FILE #================================================= -# If #new_port is not defined test the $port and keep it open -if [ -z $new_port ]; then - ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $squid_port - ynh_app_setting_set --app=$app --key=port --value=$squid_port - # If $new_port is define close the $port and open the $new_port -else - #Close $port - if yunohost firewall list | grep -q "\- $squid_port$" - then - ynh_script_progression --message="Closing port $squid_port..." - ynh_exec_warn_less yunohost firewall disallow TCP $squid_port - fi +ynh_script_progression --message="Updating a configuration file..." - # 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=squid_port --value=$squid_port - #Remove the value of $new_port - ynh_app_setting_set --app=$app --key=new_port --value="" -fi - -#================================================= -# MODIFY A CONFIG FILE -#================================================= - -### `ynh_replace_string` is used to replace a string in a file. -### (It's compatible with sed regular expressions syntax) - -# See is squid3 folder is there +# See if squid3 folder exits if [ -d "/etc/squid3" ]; then - squid="squid3" + squid="squid3" # If squid3 folder is not found look for squid folder elif [ -d "/etc/squid" ]; then - squid="squid" + squid="squid" # If both folders are not found then call ynh_die else - ynh_die "No squid folder found in /etc. Looks like squid 3 package is not installed. Try installing it manually by apt-get install squid3" + ynh_die --message="No squid folder found in /etc. Looks like squid3 package is not installed. Try installing it manually." fi -### 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="/etc/$squid/squid.conf" - -ynh_replace_string --match_string="__PORT__" --replace_string="$squid_port" --target_file="../conf/squid.conf" -ynh_replace_string --match_string="__SQUID__" --replace_string="$squid" --target_file="../conf/squid.conf" -cp -f "../conf/squid.conf" "/etc/$squid/." -# Save squid folder ynh_app_setting_set --app=$app --key=squid_folder --value=$squid -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="/etc/$squid/squid.conf" +ynh_add_config --template="../conf/squid.conf" --destination="/etc/$squid/squid.conf" #================================================= -# ADVERTISE SERVICE IN ADMIN PANEL +# INTEGRATE SERVICE IN YUNOHOST #================================================= +ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add squid3 --log "/var/log/$squid/cache.log" +yunohost service add $app --description "Squid3 a web proxy service" --log="/var/log/$squid/access.log" --needs_exposed_ports $squid_port #================================================= -# RESTART SQUID'S SERVICE and SSOWATCONF +# START SYSTEMD SERVICE #================================================= +ynh_script_progression --message="Starting a systemd service..." -service $squid restart -yunohost app ssowatconf +ynh_systemd_action --service_name=$squid --action="restart" --log_path="/var/log/$squid/cache.log" #================================================= # SEND A README FOR THE ADMIN