install.fairie/home/dot_local/bin/post-installx/executable_post-privoxy.sh

67 lines
2.9 KiB
Bash
Raw Normal View History

2024-05-04 21:05:33 -07:00
#!/usr/bin/env bash
# @file Privoxy Configuration
# @brief This script applies the Privoxy configuration stored at `${XDG_CONFIG_HOME:-HOME/.config}/privoxy/config` to the system and then restarts Privoxy
# @description
# Privoxy is a web proxy that can be combined with Tor to provide an HTTPS / HTTP proxy that can funnel all traffic
# through Tor. This script:
#
# 1. Determines the system configuration file location
# 2. Applies the configuration stored at `${XDG_CONFIG_HOME:-HOME/.config}/privoxy/config`
# 3. Enables and restarts the Privoxy service with the new configuration
#
# ## Links
#
# * [Privoxy configuration](https://github.com/megabyte-labs/install.doctor/tree/master/home/dot_config/privoxy/config)
2024-05-27 20:45:14 -07:00
set -Eeuo pipefail
2024-05-27 20:50:11 -07:00
trap "gum log -sl error 'Script encountered an error!'" ERR
2024-05-27 04:15:03 -07:00
2024-05-04 21:05:33 -07:00
### Configure variables
if [ -d /Applications ] && [ -d /System ]; then
### macOS
2024-05-12 21:01:29 -07:00
PRIVOXY_CONFIG_DIR=/usr/local/etc/privoxy
2024-05-04 21:05:33 -07:00
else
### Linux
PRIVOXY_CONFIG_DIR=/etc/privoxy
fi
PRIVOXY_CONFIG="$PRIVOXY_CONFIG_DIR/config"
if command -v privoxy > /dev/null; then
2024-05-12 21:01:29 -07:00
if [ -f "${XDG_CONFIG_HOME:-HOME/.config}/privoxy/config" ]; then
2024-05-19 23:06:00 -07:00
sudo mkdir -p "$PRIVOXY_CONFIG_DIR"
2024-05-27 20:50:11 -07:00
gum log -sl info "Copying ${XDG_CONFIG_HOME:-HOME/.config}/privoxy/config to $PRIVOXY_CONFIG"
2024-05-04 21:05:33 -07:00
sudo cp -f "${XDG_CONFIG_HOME:-HOME/.config}/privoxy/config" "$PRIVOXY_CONFIG"
2024-05-27 20:50:11 -07:00
gum log -sl info "Running sudo chmod 600 $PRIVOXY_CONFIG"
2024-05-04 21:05:33 -07:00
sudo chmod 600 "$PRIVOXY_CONFIG"
if command -v add-usergroup > /dev/null; then
2024-05-20 00:15:50 -07:00
sudo add-usergroup privoxy privoxy
2024-05-04 21:05:33 -07:00
sudo add-usergroup "$USER" privoxy
fi
2024-05-27 20:50:11 -07:00
gum log -sl info 'Applying proper permissions to Privoxy configuration'
2024-05-04 21:05:33 -07:00
sudo chown privoxy:privoxy "$PRIVOXY_CONFIG" 2> /dev/null || sudo chown privoxy:$(id -g -n) "$PRIVOXY_CONFIG"
2024-05-12 21:01:29 -07:00
if [ -d "${HOMEBREW_PREFIX:-/opt/homebrew}/etc/privoxy" ] && [ ! -f "${HOMEBREW_PREFIX:-/opt/homebrew}/etc/privoxy/config" ]; then
2024-05-27 20:50:11 -07:00
gum log -sl info "Symlinking $PRIVOXY_CONFIG to ${HOMEBREW_PREFIX:-/opt/homebrew}/etc/privoxy/config"
2024-05-12 21:01:29 -07:00
ln -s "$PRIVOXY_CONFIG" "${HOMEBREW_PREFIX:-/opt/homebrew}/etc/privoxy/config"
fi
2024-05-04 21:05:33 -07:00
### Restart Privoxy after configuration is applied
if [ -d /Applications ] && [ -d /System ]; then
### macOS
2024-05-27 20:50:11 -07:00
gum log -sl info 'Running brew services restart privoxy'
2024-05-04 21:05:33 -07:00
brew services restart privoxy
else
2024-05-12 21:01:29 -07:00
### Linux
2024-05-04 21:05:33 -07:00
if [[ ! "$(test -d /proc && grep Microsoft /proc/version > /dev/null)" ]]; then
2024-05-27 20:50:11 -07:00
gum log -sl info 'Running sudo systemctl enable / restart privoxy'
2024-05-04 21:05:33 -07:00
sudo systemctl enable privoxy
sudo systemctl restart privoxy
else
2024-05-27 20:50:11 -07:00
gum log -sl info 'The system is a WSL environment so the Privoxy systemd service will not be enabled / restarted'
2024-05-04 21:05:33 -07:00
fi
fi
else
2024-05-27 20:50:11 -07:00
gum log -sl info "${XDG_CONFIG_HOME:-HOME/.config}/privoxy/config is missing so skipping set up of Privoxy"
2024-05-04 21:05:33 -07:00
fi
else
2024-05-27 20:50:11 -07:00
gum log -sl info 'privoxy is not installed or not available in the PATH'
2024-05-04 21:05:33 -07:00
fi