Skip to content

Instantly share code, notes, and snippets.

@ntrp
Created November 20, 2013 18:16
Show Gist options
  • Save ntrp/7568208 to your computer and use it in GitHub Desktop.
Save ntrp/7568208 to your computer and use it in GitHub Desktop.
Automation script for network reconition and proxy automation.
#!/bin/sh
IF=$1
STATUS=$2
WIFI="wlp2s0"
LAN="enp3s0"
NETMASK_WIFI_HOME="192.168.1.1/24"
NETMASK_WIFI_ANDROID="192.168.43.255/24" # Android HotSpot has always same netmask
NETMASK_LAN_HOME="192.168.1.1/24"
NETMASK_LAN_RVE="10.6.196.1/22"
NETMASK_LAN_ENG="192.168.44.1/22"
notify() {
for pid in $(pgrep 'xfce'); do
eval $(grep -z ^USER /proc/$pid/environ)
eval export $(grep -z ^DISPLAY /proc/$pid/environ)
eval export $(grep -z ^DBUS_SESSION_BUS_ADDRESS /proc/$pid/environ)
done
su $USER -c "notify-send \"Proxy Automation\" \"$1\" -i package_network -t 5000"
}
reinit_proxy() {
case "$1" in
rve)
echo "Initializing RVE proxy mode.."
MSG="Proxy reinitialization completed:\n\n<b>RegioneVeneto</b> profile activated."
cp /etc/squid/squid_rve.conf /etc/squid/squid.conf
;;
eng)
echo "Initializing ENG proxy mode.."
MSG="Proxy reinitialization completed:\n\n<b>Engineering</b> profile activated."
cp /etc/squid/squid_eng.conf /etc/squid/squid.conf
;;
*)
echo "## Initializing proxy direct mode.."
MSG="Proxy reinitialization completed:\n\n<b>Direct</b> profile activated."
cp /etc/squid/squid_direct.conf /etc/squid/squid.conf
;;
esac
systemctl restart squid.service
notify "$MSG"
echo "## Proxy restart complete."
}
if [ "$IF" = "$WIFI" ] && [ "$STATUS" = "up" ]; then
if [ -n "`/sbin/ip addr show $IF to $NETMASK_WIFI_HOME`" ] || [ -n "`/sbin/ip addr show $IF to $NETMASK_WIFI_ANDROID`" ]; then
reinit_proxy direct
exit $?
fi
fi
if [ "$IF" = "$LAN" ] && [ "$STATUS" = "up" ]; then
if [ -n "`/sbin/ip addr show $IF to $NETMASK_LAN_HOME`" ]; then
reinit_proxy direct
exit $?
elif [ -n "`/sbin/ip addr show $IF to $NETMASK_LAN_RVE`" ]; then
reinit_proxy rve
exit $?
elif [ -n "`/sbin/ip addr show $IF to $NETMASK_LAN_ENG`" ]; then
reinit_proxy eng
exit $?
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment