1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/squid3_ynh.git synced 2024-09-03 20:26:11 +02:00
squid3_ynh/scripts/upgrade

155 lines
5.6 KiB
Text
Raw Normal View History

2018-09-15 09:48:48 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
app=$YNH_APP_INSTANCE_NAME
2020-10-17 13:52:59 +02:00
squid_port=$(ynh_app_setting_get $app squid_port)
new_port=$(ynh_app_setting_get $app new_port)
2018-09-15 09:48:48 +02:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
2018-09-15 09:48:48 +02:00
# Backup the current version of the app
ynh_backup_before_upgrade
ynh_clean_setup () {
# restore it if the upgrade fails
ynh_restore_upgradebackup
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
2020-10-17 11:19:50 +02:00
# SPECIFIC RESTORATION
2018-09-15 09:48:48 +02:00
#=================================================
2020-10-17 11:19:50 +02:00
# UPGRADE DEPENDENCIES
2018-09-15 09:48:48 +02:00
#=================================================
2020-10-17 13:52:59 +02:00
ynh_script_progression --message="Upgrading dependencies..."
2020-10-17 11:19:50 +02:00
ynh_install_app_dependencies $pkg_dependencies
#=================================================
# CLOSE A PORT
#=================================================
# If #new_port is not defined test the $port and keep it open
2020-10-17 14:28:42 +02:00
if [ -z $new_port ]; then
2020-10-17 13:52:59 +02:00
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $squid_port
ynh_app_setting_set --app=$app --key=port --value=$squid_port
2020-10-17 14:28:42 +02:00
# If $new_port is define close the $port and open the $new_port
else
#Close $port
2020-10-17 13:52:59 +02:00
if yunohost firewall list | grep -q "\- $squid_port$"
then
2020-10-17 13:52:59 +02:00
ynh_script_progression --message="Closing port $squid_port..."
ynh_exec_warn_less yunohost firewall disallow TCP $squid_port
fi
# Open $new_port
port=$(ynh_find_port --port=$squid_new_port)
#Add the value of $new_port to $port
2020-10-17 13:52:59 +02:00
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
2020-10-17 11:19:50 +02:00
2018-09-15 09:48:48 +02:00
#=================================================
# MODIFY A CONFIG FILE
#=================================================
### `ynh_replace_string` is used to replace a string in a file.
### (It's compatible with sed regular expressions syntax)
2018-09-28 12:38:03 +02:00
# See is squid3 folder is there
2020-10-17 11:19:50 +02:00
if [ -d "/etc/squid3" ]; then
2018-09-28 12:38:03 +02:00
squid="squid3"
2020-10-17 11:19:50 +02:00
2018-09-28 12:38:03 +02:00
# If squid3 folder is not found look for squid folder
elif [ -d "/etc/squid" ]; then
squid="squid"
2018-09-28 12:52:49 +02:00
2018-09-28 12:38:03 +02:00
# 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"
2020-10-17 11:19:50 +02:00
2018-09-28 12:38:03 +02:00
fi
2020-10-17 11:19:50 +02:00
### 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"
2018-09-28 12:38:03 +02:00
2020-10-17 13:52:59 +02:00
ynh_replace_string --match_string="__PORT__" --replace_string="$squid_port" --target_file="../conf/squid.conf"
2020-10-17 11:19:50 +02:00
ynh_replace_string --match_string="__SQUID__" --replace_string="$squid" --target_file="../conf/squid.conf"
2018-09-28 12:52:49 +02:00
cp -f "../conf/squid.conf" "/etc/$squid/."
2018-09-28 12:38:03 +02:00
# Save squid folder
2020-10-17 11:19:50 +02:00
ynh_app_setting_set --app=$app --key=squid_folder --value=$squid
2018-09-15 09:48:48 +02:00
# Recalculate and store the checksum of the file for the next upgrade.
2020-10-17 11:19:50 +02:00
ynh_store_file_checksum --file="/etc/$squid/squid.conf"
2018-09-15 09:48:48 +02:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
### `yunohost service add` is a CLI yunohost command to add a service in the admin panel.
### You'll find the service in the 'services' section of YunoHost admin panel.
### This CLI command would be useless if the app does not have any services (systemd or sysvinit)
### 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
2020-10-17 13:52:59 +02:00
yunohost service add squid3 --log "/var/log/$squid/cache.log"
2018-09-15 09:48:48 +02:00
#=================================================
# RESTART SQUID'S SERVICE and SSOWATCONF
#=================================================
2018-09-28 12:38:03 +02:00
service $squid restart
2018-09-15 09:48:48 +02:00
yunohost app ssowatconf
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
echo "You can find a config file at /etc/$squid/squid.conf
Squid 3 will work with your registered users through LDAP. Just put the username and password when asked.
To configure on Firefox go to preferences->general->network proxy->manual proxy configuration.
Enter these value in the below feilds.
---------------------------------------------------------------------
| Http proxy: Your any registered domain name or ip eg domain.tld
|
2020-10-17 13:52:59 +02:00
|port: $squid_port
|
|Tick mark use this proxy server for all protocols
|
|No proxy for: localhost, 127.0.0.1
|
|Save and restart borwser.
---------------------------------------------------------------------
If you are facing any issues or want to improve this app, please open a new issue in this project: https://github.com/YunoHost-Apps/squid3_ynh/issues" > mail_to_send
ynh_send_readme_to_admin --app_message="mail_to_send" --type="install"
#=================================================
# END OF SCRIPT
#=================================================
2020-11-02 19:27:34 +01:00
ynh_script_progression --message="Upgrade of $app completed"