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
|
|
|
|
port=$(ynh_app_setting_get $app port)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_install_app_dependencies squid3 mailutils
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORE
|
|
|
|
#=================================================
|
|
|
|
# OPEN PORTS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
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)
|
2018-09-28 12:38:03 +02:00
|
|
|
|
|
|
|
# See is squid3 folder is there
|
|
|
|
if [ -d "/etc/squid3" ]; then
|
|
|
|
squid="squid3"
|
2018-09-28 12:52:49 +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"
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
2018-09-28 12:52:49 +02:00
|
|
|
ynh_replace_string "__PORT__" "$port" "../conf/squid.conf"
|
|
|
|
ynh_replace_string "__SQUID__" "$squid" "../conf/squid.conf"
|
|
|
|
cp -f "../conf/squid.conf" "/etc/$squid/."
|
2018-09-28 12:38:03 +02:00
|
|
|
# Save squid folder
|
|
|
|
ynh_app_setting_set $app squid_folder $squid
|
2018-09-15 09:48:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
### 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.
|
2018-09-28 12:38:03 +02:00
|
|
|
ynh_backup_if_checksum_is_different "/etc/$squid/squid.conf"
|
2018-09-15 09:48:48 +02:00
|
|
|
# Recalculate and store the checksum of the file for the next upgrade.
|
2018-09-28 12:38:03 +02:00
|
|
|
ynh_store_file_checksum "/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
|
|
|
|
|
2018-09-28 12:38:03 +02:00
|
|
|
yunohost service add squid3 --log "/var/log/$squid/access.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
|
|
|
|
|