mirror of
https://github.com/YunoHost-Apps/squid3_ynh.git
synced 2024-09-03 20:26:11 +02:00
201 lines
8.5 KiB
Bash
Executable file
201 lines
8.5 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# MANAGE SCRIPT FAILURE
|
|
#=================================================
|
|
|
|
ynh_clean_setup () {
|
|
### Remove this function if there's nothing to clean before calling the remove script.
|
|
true
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# RETRIEVE ARGUMENTS FROM THE MANIFEST
|
|
#=================================================
|
|
|
|
squid_port=$YNH_APP_ARG_SQUID_PORT
|
|
|
|
### If it's a multi-instance app, meaning it can be installed several times independently
|
|
### The id of the app as stated in the manifest is available as $YNH_APP_ID
|
|
### The instance number is available as $YNH_APP_INSTANCE_NUMBER (equals "1", "2", ...)
|
|
### The app instance name is available as $YNH_APP_INSTANCE_NAME
|
|
### - the first time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample
|
|
### - the second time the app is installed, YNH_APP_INSTANCE_NAME = ynhexample__2
|
|
### - ynhexample__{N} for the subsequent installations, with N=3,4, ...
|
|
### The app instance name is probably what interests you most, since this is
|
|
### guaranteed to be unique. This is a good unique identifier to define installation path,
|
|
### db names, ...
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
#=================================================
|
|
# STANDARD MODIFICATIONS
|
|
#=================================================
|
|
# FIND AND OPEN A PORT
|
|
#=================================================
|
|
ynh_script_progression --message="Configuring firewall..."
|
|
|
|
### Use these lines if you have to open a port for the application
|
|
### `ynh_find_port` will find the first available port starting from the given port.
|
|
### If you're not using these lines:
|
|
### - Remove the section "CLOSE A PORT" in the remove script
|
|
|
|
# Find an available port
|
|
port=$(ynh_find_port --port=$squid_port)
|
|
ynh_app_setting_set --app=$app --key=port --value=$port
|
|
|
|
# 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
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Installing dependencies..."
|
|
|
|
### `ynh_install_app_dependencies` allows you to add any "apt" dependencies to the package.
|
|
### Those deb packages will be installed as dependencies of this package.
|
|
### If you're not using this helper:
|
|
### - Remove the section "REMOVE DEPENDENCIES" in the remove script
|
|
### - Remove the variable "pkg_dependencies" in _common.sh
|
|
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
|
|
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
#=================================================
|
|
# 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 if squid3 folder exits
|
|
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
|
|
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 in app settings
|
|
|
|
ynh_app_setting_set --app=$app --key=squid_folder --value=$squid
|
|
|
|
|
|
#=================================================
|
|
# STORE THE CONFIG FILE CHECKSUM
|
|
#=================================================
|
|
|
|
### `ynh_store_file_checksum` is used to store the checksum of a file.
|
|
### That way, during the upgrade script, by using `ynh_backup_if_checksum_is_different`,
|
|
### 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 --file="/etc/$squid/squid.conf"
|
|
|
|
|
|
#=================================================
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
#=================================================
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
### `yunohost service add` integrates a service in YunoHost. It then gets
|
|
### displayed in the admin interface and through the others `yunohost service` commands.
|
|
### (N.B. : this line only makes sense if the app adds a service to the system!)
|
|
### If you're not using these lines:
|
|
### - You can remove these files in conf/.
|
|
### - Remove the section "REMOVE SERVICE INTEGRATION IN YUNOHOST" in the remove script
|
|
### - As well as the section "INTEGRATE SERVICE IN YUNOHOST" in the restore script
|
|
### - And the section "INTEGRATE SERVICE IN YUNOHOST" in the upgrade script
|
|
|
|
yunohost service add $app --description "Squid3 a web proxy service" --log "/var/log/$squid/access.log"
|
|
|
|
### Additional options starting with 3.8:
|
|
###
|
|
### --needs_exposed_ports "$port" a list of ports that needs to be publicly exposed
|
|
### which will then be checked by YunoHost's diagnosis system
|
|
### (N.B. DO NOT USE THIS is the port is only internal !!!)
|
|
###
|
|
### --test_status "some command" a custom command to check the status of the service
|
|
### (only relevant if 'systemctl status' doesn't do a good job)
|
|
###
|
|
### --test_conf "some command" some command similar to "nginx -t" that validates the conf of the service
|
|
###
|
|
### Re-calling 'yunohost service add' during the upgrade script is the right way
|
|
### to proceed if you later realize that you need to enable some flags that
|
|
### weren't enabled on old installs (be careful it'll override the existing
|
|
### service though so you should re-provide all relevant flags when doing so)
|
|
###
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
### `ynh_systemd_action` is used to start a systemd service for an app.
|
|
### Only needed if you have configure a systemd service
|
|
### If you're not using these lines:
|
|
### - Remove the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the backup script
|
|
### - As well as the section "START SYSTEMD SERVICE" in the restore script
|
|
### - As well as the section"STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the upgrade script
|
|
### - And the section "STOP SYSTEMD SERVICE" and "START SYSTEMD SERVICE" in the change_url script
|
|
|
|
# Start a systemd service
|
|
ynh_systemd_action --service_name=$squid --action="restart" --log_path="/var/log/$squid/access.log"
|
|
|
|
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
|
|
|
|
|
|port: $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
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Installation of $app completed"
|