2018-09-14 05:20:02 +02:00
#!/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
#=================================================
2018-10-04 17:22:43 +02:00
squid_port=$YNH_APP_ARG_SQUID_PORT
2020-10-17 13:00:27 +02:00
new_port=""
2018-10-04 17:22:43 +02:00
2020-10-17 11:19:50 +02:00
### 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, ...
2018-09-14 05:20:02 +02:00
app=$YNH_APP_INSTANCE_NAME
#=================================================
# STANDARD MODIFICATIONS
#=================================================
# FIND AND OPEN A PORT
#=================================================
2020-10-17 11:19:50 +02:00
ynh_script_progression --message="Configuring firewall..."
2018-09-14 05:20:02 +02:00
### 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
2020-10-17 11:19:50 +02:00
# Find an available port
2020-10-17 13:52:59 +02:00
squid_port=$(ynh_find_port --port=$squid_port)
ynh_app_setting_set --app=$app --key=squid_port --value=$squid_port
2020-10-17 13:00:27 +02:00
ynh_app_setting_set --app=$app --key=new_port --value=$new_port
2020-10-17 11:19:50 +02:00
# 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
2020-10-17 13:52:59 +02:00
ynh_exec_warn_less yunohost firewall allow --no-upnp TCP $squid_port
2018-09-14 05:20:02 +02:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2020-10-17 11:19:50 +02:00
ynh_script_progression --message="Installing dependencies..."
2018-09-14 05:20:02 +02:00
### `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
2020-10-17 11:19:50 +02:00
### - Remove the variable "pkg_dependencies" in _common.sh
2018-09-14 05:20:02 +02:00
### - As well as the section "REINSTALL DEPENDENCIES" in the restore script
### - And the section "UPGRADE DEPENDENCIES" in the upgrade script
2020-10-17 11:19:50 +02:00
ynh_install_app_dependencies $pkg_dependencies
2018-09-14 05:20:02 +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
2020-10-17 11:19:50 +02:00
# See if squid3 folder exits
if [ -d "/etc/squid3" ]; then
2018-09-28 12:38:03 +02:00
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"
2020-10-17 11:19:50 +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 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/."
2020-10-17 11:19:50 +02:00
# Save squid folder in app settings
ynh_app_setting_set --app=$app --key=squid_folder --value=$squid
2018-09-28 12:38:03 +02:00
2018-09-14 05:20:02 +02:00
#=================================================
# 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
2020-10-17 11:19:50 +02:00
ynh_store_file_checksum --file="/etc/$squid/squid.conf"
2018-09-14 05:20:02 +02:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
2020-10-17 11:19:50 +02:00
#=================================================
# 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!)
2018-09-14 05:20:02 +02:00
### If you're not using these lines:
### - You can remove these files in conf/.
2020-10-17 11:19:50 +02:00
### - 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
2018-09-14 05:20:02 +02:00
2020-10-17 11:19:50 +02:00
# Start a systemd service
2020-10-17 13:52:59 +02:00
ynh_systemd_action --service_name=$squid --action="restart" --log_path="/var/log/$squid/cache.log"
2018-09-14 05:20:02 +02:00
2018-09-14 07:02:29 +02:00
yunohost app ssowatconf
2018-09-14 05:20:02 +02:00
#=================================================
# SEND A README FOR THE ADMIN
#=================================================
2020-10-17 11:50:38 +02:00
echo "You can find a config file at /etc/$squid/squid.conf
2020-10-17 11:19:50 +02:00
Squid 3 will work with your registered users through LDAP. Just put the username and password when asked.
2018-09-14 05:20:02 +02:00
To configure on Firefox go to preferences->general->network proxy->manual proxy configuration.
Enter these value in the below feilds.
2020-10-17 11:19:50 +02:00
---------------------------------------------------------------------
| Http proxy: Your any registered domain name or ip eg domain.tld
2020-10-17 12:08:40 +02:00
|
2020-10-17 13:52:59 +02:00
|port: $squid_port
2020-10-17 12:08:40 +02:00
|
2020-10-17 11:19:50 +02:00
|Tick mark use this proxy server for all protocols
2020-10-17 12:08:40 +02:00
|
2020-10-17 11:19:50 +02:00
|No proxy for: localhost, 127.0.0.1
2020-10-17 12:08:40 +02:00
|
2020-10-17 11:19:50 +02:00
|Save and restart borwser.
---------------------------------------------------------------------
2020-10-17 11:50:38 +02:00
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
2018-09-14 05:20:02 +02:00
2020-10-17 11:50:38 +02:00
ynh_send_readme_to_admin --app_message="mail_to_send" --type="install"
2018-09-14 05:20:02 +02:00
2020-10-17 11:19:50 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2018-09-14 05:20:02 +02:00
2020-10-17 11:19:50 +02:00
ynh_script_progression --message="Installation of $app completed"