mirror of
https://github.com/YunoHost-Apps/squid3_ynh.git
synced 2024-09-03 20:26:11 +02:00
128 lines
4.8 KiB
Bash
Executable file
128 lines
4.8 KiB
Bash
Executable file
#!/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)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
|
|
### This helper will compare the version of the currently installed app and the version of the upstream package.
|
|
### $upgrade_type can have 2 different values
|
|
### - UPGRADE_APP if the upstream app version has changed
|
|
### - UPGRADE_PACKAGE if only the YunoHost package has changed
|
|
### ynh_check_app_version_changed will stop the upgrade if the app is up to date.
|
|
### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do.
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# DOWNLOAD, CHECK AND UNPACK SOURCE
|
|
#=================================================
|
|
|
|
if [ "$upgrade_type" == "UPGRADE_APP" ]
|
|
then
|
|
ynh_script_progression --message="Upgrading source files..." --time --weight=1
|
|
|
|
# Download, check integrity, uncompress and patch the source from app.src
|
|
ynh_setup_source --dest_dir="$final_path"
|
|
fi
|
|
|
|
#=================================================
|
|
# SPECIFIC RESTORATION
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading dependencies..." --time --weight=1
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
|
|
# 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 !)
|
|
|
|
# Open the port
|
|
ynh_exec_warn_less 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
|
|
### 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="$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"
|
|
|
|
#=================================================
|
|
# 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
|
|
|
|
yunohost service add squid3 --log "/var/log/$squid/access.log"
|
|
|
|
#=================================================
|
|
# RESTART SQUID'S SERVICE and SSOWATCONF
|
|
#=================================================
|
|
|
|
service $squid restart
|
|
yunohost app ssowatconf
|