#!/bin/bash
if [ "$(id -u)" -ne "0" ];
then
#echo "This script must be run as root" 2>&1
echo -e "\n\033[;31mThis script must be run as root!\033[;37m\n"
exit 1
fi
VPN_HOME=<sciezka_do_katalogu>
VPN_CONF_FILE=<plik_konf_vpn>
VPN_KEY_PASS_FILE=<haslo_do_klucza>
#openvpn start
cd $VPN_HOME
openvpn --config $VPN_CONF_FILE --askpass $VPN_KEY_PASS_FILE
#add route to redmine and git
route add -net <ip> netmask <maska> dev tun0
Może się mylę, ale czy openvpn nie tworzy przypadkiem urządzenia tun0 ?
Jeżeli odpalasz z palca urządzenie zdąży się utworzyć, ze skryptu nie. Daj może jakiś "sleep" między komendami i wtedy zobacz
Tworzy jak najbardziej. A nie jest tak, że te komendy powinny się wykonać w odpowiedniej sekwencji? Tzn. najpierw 'openvpn' potem 'route' czy może 'openvpn' jedzie w jakimś osobnym wątku? 'sleep' jest jakimś rozwiązaniem, ale nie wiadomo nigdy ile dokładnie potrwa wywołanie 'openvpn'..
--route network/IP [netmask] [gateway] [metric]
Add route to routing table after connection is established. Multiple routes can be specified. Routes will be automatically torn down in reverse order prior to TUN/TAP device close.
This option is intended as a convenience proxy for the route(8) shell command, while at the same time providing portable semantics across OpenVPN's platform space.
netmask default -- 255.255.255.255
gateway default -- taken from --route-gateway or the second parameter to --ifconfig when --dev tun is specified.
The default can be specified by leaving an option blank or setting it to "default".
The network and gateway parameters can also be specified as a DNS or /etc/hosts file resolvable name, or as one of three special keywords:
vpn_gateway -- The remote VPN endpoint address (derived either from --route-gateway or the second parameter to --ifconfig when --dev tun is specified).
net_gateway -- The pre-existing IP default gateway, read from the routing table (not supported on all OSes).
remote_host -- The --remote address if OpenVPN is being run in client mode, and is undefined in server mode.