dotfiles/.local/bin/personal/checktor

30 lines
708 B
Bash
Executable file

#!/bin/sh
check() {
[ ! -z $(pidof tor) ] && echo "On" || echo "Off"
}
checkNotif() {
[ ! -z $(pidof tor) ] && notify-send "Tor activated" || notify-send "Tor deactivated"
}
checkWeb() {
tor="$(curl --socks5-hostname localhost:9050 -s https://check.torproject.org | grep -c "Congratulation")"
[ $tor -eq 0 ] && notify-send "Tor deactivated" || notify-send "Tor activated"
}
toggle() {
[ ! -z "$(pidof tor)" ] && $(sudo systemctl stop tor) || $(sudo systemctl start tor)
}
restartTor() {
sudo systemctl restart tor && notify-send "Tor restarting" || notify-send "Tor failed to restart"
}
case "$1" in
-t ) $(toggle) ;;
-c ) checkWeb ;;
-r ) restartTor ;;
-n ) checkNotif ;;
* ) check ;;
esac