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)
### 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
sudo mkdir -p "PRIVOXY_CONFIG_DIR"
logg 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-12 21:01:29 -07:00
logg 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
sudo add-usergroup " $USER " privoxy
fi
2024-05-12 21:01:29 -07:00
logg 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
logg info " Symlinking $PRIVOXY_CONFIG to ${ HOMEBREW_PREFIX :- /opt/homebrew } /etc/privoxy/config "
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-12 21:01:29 -07:00
logg 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-12 21:01:29 -07:00
logg info 'Running sudo systemctl enable / restart privoxy'
2024-05-04 21:05:33 -07:00
sudo systemctl enable privoxy
sudo systemctl restart privoxy
else
logg info 'The system is a WSL environment so the Privoxy systemd service will not be enabled / restarted'
fi
fi
else
2024-05-12 21:01:29 -07:00
logg 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-12 21:01:29 -07:00
logg info 'privoxy is not installed or not available in the PATH'
2024-05-04 21:05:33 -07:00
fi