From 7d561eaeb8983e41975829ae09d8dcd7a9d9b3d1 Mon Sep 17 00:00:00 2001 From: anmol26s Date: Fri, 28 Sep 2018 16:08:03 +0530 Subject: [PATCH 1/2] Check correct squid folder in /etc --- scripts/backup | 4 ++-- scripts/install | 31 +++++++++++++++++++++++++------ scripts/remove | 4 ++-- scripts/restore | 32 +++++++++++++++++++++++++++----- scripts/upgrade | 29 +++++++++++++++++++++++------ 5 files changed, 79 insertions(+), 21 deletions(-) diff --git a/scripts/backup b/scripts/backup index dbf9b98..bac0015 100755 --- a/scripts/backup +++ b/scripts/backup @@ -25,10 +25,10 @@ ynh_abort_if_errors #================================================= app=$YNH_APP_INSTANCE_NAME - +squid=$(ynh_app_setting_get $app squid_folder) #================================================= # BACKUP OF THE CONFIG OF SQUID3 #================================================= -ynh_backup "/etc/squid3/squid.conf" +ynh_backup "/etc/$squid/squid.conf" diff --git a/scripts/install b/scripts/install index a78d5c7..c8a8e14 100755 --- a/scripts/install +++ b/scripts/install @@ -62,8 +62,27 @@ ynh_install_app_dependencies squid3 mailutils ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) -ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" -cp -f "../conf/squid.conf" "/etc/squid3/." + +# See is squid3 folder is there +if [ -d "/etc/squid3" ]; then + squid="squid3" + ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" + cp -f "../conf/squid.conf" "/etc/squid3/." +# If squid3 folder is not found look for squid folder +elif [ -d "/etc/squid" ]; then + squid="squid" + ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" + cp -f "../conf/squid.conf" "/etc/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" + +fi + +# Save squid folder +ynh_app_setting_set $app squid_folder $squid + + #================================================= # STORE THE CONFIG FILE CHECKSUM #================================================= @@ -73,7 +92,7 @@ cp -f "../conf/squid.conf" "/etc/squid3/." ### you can make a backup of this file before modifying it again if the admin had modified it. # Calculate and store the config file checksum into the app settings -ynh_store_file_checksum "/etc/squid3/squid.conf" +ynh_store_file_checksum "/etc/$squid/squid.conf" #================================================= @@ -88,21 +107,21 @@ ynh_store_file_checksum "/etc/squid3/squid.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 squid3 --log "/var/log/squid3/access.log" +yunohost service add squid3 --log "/var/log/$squid/access.log" #================================================= # RESTART SQUID'S SERVICE and SSOWATCONF #================================================= -service squid3 restart +service $squid restart yunohost app ssowatconf #================================================= # SEND A README FOR THE ADMIN #================================================= -message="You can find a config file at /etc/squid3/squid.conf +message="You can find a config file at /etc/$squid/squid.conf Squid 3 will work with your registered users. Just put the username and password when asked. To configure on Firefox go to preferences->general->network proxy->manual proxy configuration. diff --git a/scripts/remove b/scripts/remove index b003512..ee79832 100755 --- a/scripts/remove +++ b/scripts/remove @@ -15,14 +15,14 @@ source /usr/share/yunohost/helpers app=$YNH_APP_INSTANCE_NAME port=$(ynh_app_setting_get $app port) - +squid=$(ynh_app_setting_get $app squid_folder) # Remove a service from the admin panel, added by `yunohost service add` if yunohost service status | grep -q $app then - echo "Remove $app service" + echo "Remove $squid service" yunohost service remove $app fi diff --git a/scripts/restore b/scripts/restore index 331b944..53e457f 100755 --- a/scripts/restore +++ b/scripts/restore @@ -44,25 +44,47 @@ ynh_install_app_dependencies squid3 mailutils yunohost firewall allow --no-upnp TCP $port +#================================================= +# 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 +if [ -d "/etc/squid3" ]; then + squid="squid3" + # If squid3 folder is not found look for squid folder +elif [ -d "/etc/squid" ]; then + 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" + +fi + +# Save squid folder +ynh_app_setting_set $app squid_folder $squid + #================================================= # RESTORE INOTIFY'S CONFIG #================================================= -ynh_secure_remove "/etc/squid3/squid.conf" -ynh_restore_file "/etc/squid3/squid.conf" -service squid3 restart +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 #================================================= -yunohost service add squid3 --log "/var/log/squid3/access.log" +yunohost service add squid3 --log "/var/log/$squid/access.log" #================================================= # SEND A README FOR THE ADMIN #================================================= -message="You can find a config file at /etc/squid3/squid.conf +message="You can find a config file at /etc/$squid/squid.conf Squid 3 will work with your registered users. Just put the username and password when asked. To configure on Firefox go to preferences->general->network proxy->manual proxy configuration. diff --git a/scripts/upgrade b/scripts/upgrade index 313c3c2..ef2e532 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -53,8 +53,25 @@ yunohost firewall allow --no-upnp TCP $port ### `ynh_replace_string` is used to replace a string in a file. ### (It's compatible with sed regular expressions syntax) -ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" -cp -f "../conf/squid.conf" "/etc/squid3/squid.conf" + +# See is squid3 folder is there +if [ -d "/etc/squid3" ]; then + squid="squid3" + ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" + cp -f "../conf/squid.conf" "/etc/squid3/." +# If squid3 folder is not found look for squid folder +elif [ -d "/etc/squid" ]; then + squid="squid" + ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" + cp -f "../conf/squid.conf" "/etc/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" + +fi + +# Save squid folder +ynh_app_setting_set $app squid_folder $squid #================================================= @@ -63,9 +80,9 @@ cp -f "../conf/squid.conf" "/etc/squid3/squid.conf" ### 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 "/etc/squid3/squid.conf" +ynh_backup_if_checksum_is_different "/etc/$squid/squid.conf" # Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum "/etc/squid3/squid.conf" +ynh_store_file_checksum "/etc/$squid/squid.conf" #================================================= # ADVERTISE SERVICE IN ADMIN PANEL @@ -79,12 +96,12 @@ ynh_store_file_checksum "/etc/squid3/squid.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 squid3 --log "/var/log/squid3/access.log" +yunohost service add squid3 --log "/var/log/$squid/access.log" #================================================= # RESTART SQUID'S SERVICE and SSOWATCONF #================================================= -service squid3 restart +service $squid restart yunohost app ssowatconf From 891a8f675a3bf395b6059541a754ad86911246f5 Mon Sep 17 00:00:00 2001 From: anmol26s Date: Fri, 28 Sep 2018 16:22:49 +0530 Subject: [PATCH 2/2] Check correct squid folder in /etc --- conf/squid.conf | 6 +++--- scripts/install | 10 +++++----- scripts/upgrade | 9 +++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/conf/squid.conf b/conf/squid.conf index ce2ea36..9398477 100644 --- a/conf/squid.conf +++ b/conf/squid.conf @@ -21,7 +21,7 @@ acl purge method PURGE acl CONNECT method CONNECT ###Directive pour n’autoriser que les comptes enregistrés dans le LDAP de Yunohost -auth_param basic program /usr/lib/squid3/basic_ldap_auth -b dc=yunohost,dc=org -h 127.0.0.1 -f "uid=%s" +auth_param basic program /usr/lib/__SQUID__/basic_ldap_auth -b dc=yunohost,dc=org -h 127.0.0.1 -f "uid=%s" auth_param basic children 50 auth_param basic realm Web-Proxy @@ -44,9 +44,9 @@ dns_nameservers 127.0.0.1 ##Port d'écoute du Proxy http_port __PORT__ forwarded_for off ### mode transparant, la vrai IP est cachée -cache_dir aufs /var/spool/squid3 10000 16 256 +cache_dir aufs /var/spool/__SQUID__ 10000 16 256 hierarchy_stoplist cgi-bin ? -access_log /var/log/squid3/access.log squid +access_log /var/log/__SQUID__/access.log squid refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern -i (/cgi-bin/|\?) 0 0% 0 diff --git a/scripts/install b/scripts/install index c8a8e14..5ec92d3 100755 --- a/scripts/install +++ b/scripts/install @@ -66,19 +66,19 @@ ynh_install_app_dependencies squid3 mailutils # See is squid3 folder is there if [ -d "/etc/squid3" ]; then squid="squid3" - ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" - cp -f "../conf/squid.conf" "/etc/squid3/." + # If squid3 folder is not found look for squid folder elif [ -d "/etc/squid" ]; then squid="squid" - ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" - cp -f "../conf/squid.conf" "/etc/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" fi - +ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" +ynh_replace_string "__SQUID__" "$squid" "../conf/squid.conf" +cp -f "../conf/squid.conf" "/etc/$squid/." # Save squid folder ynh_app_setting_set $app squid_folder $squid diff --git a/scripts/upgrade b/scripts/upgrade index ef2e532..a0f9e7a 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -57,19 +57,20 @@ yunohost firewall allow --no-upnp TCP $port # See is squid3 folder is there if [ -d "/etc/squid3" ]; then squid="squid3" - ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" - cp -f "../conf/squid.conf" "/etc/squid3/." + # If squid3 folder is not found look for squid folder elif [ -d "/etc/squid" ]; then squid="squid" - ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" - cp -f "../conf/squid.conf" "/etc/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" fi +ynh_replace_string "__PORT__" "$port" "../conf/squid.conf" +ynh_replace_string "__SQUID__" "$squid" "../conf/squid.conf" +cp -f "../conf/squid.conf" "/etc/$squid/." # Save squid folder ynh_app_setting_set $app squid_folder $squid