mirror of
https://github.com/edu4rdshl/linuxscripts.git
synced 2026-07-17 23:24:52 +00:00
Added randomvpn service and script
This commit is contained in:
parent
f2a3e2faf2
commit
f35da46f10
5 changed files with 70 additions and 2 deletions
24
randomvpn
Executable file
24
randomvpn
Executable file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# Script to select a random VPN client from /etc/openvpn/client/ (the default openvpn directory)
|
||||||
|
|
||||||
|
workdir="/etc/openvpn/client/"
|
||||||
|
|
||||||
|
if [ $UID -ne 0 ]; then
|
||||||
|
echo "You need root privileges."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" == "stop" ]; then
|
||||||
|
systemctl stop openvpn-client@*
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v openvpn > /dev/null && command -v systemctl > /dev/null; then
|
||||||
|
cd "$workdir"
|
||||||
|
vpn=$(shuf -ezn 1 * | xargs -0 -n1 | cut -f1 -d '.')
|
||||||
|
$(sudo systemctl start openvpn-client@$vpn)
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
echo "OpenVPN or systemd not installed, exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
24
system-bin/randomvpn
Executable file
24
system-bin/randomvpn
Executable file
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/usr/bin/env sh
|
||||||
|
# Script to select a random VPN client from /etc/openvpn/client/ (the default openvpn directory)
|
||||||
|
|
||||||
|
workdir="/etc/openvpn/client/"
|
||||||
|
|
||||||
|
if [ $UID -ne 0 ]; then
|
||||||
|
echo "You need root privileges."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" == "stop" ]; then
|
||||||
|
systemctl stop openvpn-client@*
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v openvpn > /dev/null && command -v systemctl > /dev/null; then
|
||||||
|
cd "$workdir"
|
||||||
|
vpn=$(shuf -ezn 1 * | xargs -0 -n1 | cut -f1 -d '.')
|
||||||
|
$(sudo systemctl start openvpn-client@$vpn)
|
||||||
|
exit
|
||||||
|
else
|
||||||
|
echo "OpenVPN or systemd not installed, exiting."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
20
system-units/randomvpn.service
Normal file
20
system-units/randomvpn.service
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Random VPN client
|
||||||
|
After=syslog.target network-online.target
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=oneshot
|
||||||
|
WorkingDirectory=/etc/openvpn/client/
|
||||||
|
ProtectHome=true
|
||||||
|
ProtectSystem=strict
|
||||||
|
ExecStart=/usr/bin/randomvpn
|
||||||
|
RemainAfterExit=yes
|
||||||
|
CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE LimitNPROC=10
|
||||||
|
DeviceAllow=/dev/null rw
|
||||||
|
DeviceAllow=/dev/net/tun rw
|
||||||
|
ExecStop=/usr/bin/randomvpn stop
|
||||||
|
KillMode=process
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Comprobación automatica de servicios de red cada 5 minutos
|
Description=Comprobación automatica de servicios de red cada 5 minutos
|
||||||
[Timer]
|
[Timer]
|
||||||
OnBootSec=2min
|
OnBootSec=1min
|
||||||
OnUnitActiveSec=10min
|
OnUnitActiveSec=5min
|
||||||
Unit=rnetworking.service
|
Unit=rnetworking.service
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
Loading…
Add table
Add a link
Reference in a new issue