Last active
January 18, 2021 12:41
-
-
Save nottux/77b75f0090aa73b521c9481d9db6b99a to your computer and use it in GitHub Desktop.
namespaced vpn but easy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pipe=/tmp/outpipe_vpn | |
case "$1" in | |
firefox|web|fox) app="firefox --private-window";; | |
haku|neko|nero|hakuneko|hakunero) app="/usr/lib/hakuneko-desktop/hakuneko";; | |
shell|sh) app="echo openning shell";; | |
*) app="firefox --private-window";; | |
esac | |
case "$2" in | |
vpn) user=vpn;; | |
utku3) user=utku3;; | |
"") user=$USER;; | |
*) echo wrong user;exit;; | |
esac | |
if [ -e "$pipe.exist" ] | |
then sudo ip netns exec protected sudo -u $user sh -c "DISPLAY=:0 $app" | |
case "$1" in | |
shell|sh) sudo ip netns exec protected sudo -u $user -i;; | |
esac | |
else sudo echo 'nyaa-des ~' | |
touch "$pipe.exist" | |
mkfifo $pipe | |
sudo /home/utku3/Programlar/namespaced-openvpn-master/namespaced-openvpn --config '/home/utku3/vpn/FreeVPN.me-OpenVPN-Bundle-July-2020/FreeVPN.me - Server1-NL/Server1-TCP443.ovpn' >$pipe & grep -m1 "Initialization Sequence Completed" $pipe && (xhost local: ; sudo ip netns exec protected sudo -u $user sh -c "DISPLAY=:0 $app") | |
case "$1" in | |
shell|sh) sudo ip netns exec protected sudo -u $user -i;; | |
esac | |
rm $pipe | |
rm "$pipe.exist" | |
sudo su -c "kill $(jobs -p 1)" | |
sleep 1 | |
while jobs -p 1 | |
do sleep 2 | |
sudo su -c "kill $(jobs -p 1)" | |
done | |
fi |
there is something weird with the pipe file, it disapears &reappears but openvpn stays on.
Also while openvpn killed succesfully in the first run. openvpn won't close normal (probably due to pipe crashing)
I wonder if pipe is crashing because its in the if statement. It used to work fine
Edit: turns out while kill command does run, it doesn't sigterm openvpn
now at least I can ^C to close openvpn 😞
utku3@utku3:~/Programlar$ /home/utku3/Programlar/vpn2 sh
openning shell
utku3@utku3:~/Programlar$
:)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I feel like there is bug where it doesn't close the connection properly