genconfig: Add push support

* Add ability to specify push commands with `-p` argument.
This commit is contained in:
Kyle Manna 2014-07-09 10:28:54 -07:00
parent 0c873ab4cf
commit 20be0f90a5

View File

@ -36,6 +36,7 @@ usage() {
echo " -u SERVER_PUBLIC_URL"
echo " [-s SERVER_SUBNET]"
echo " [-r ROUTE ...]"
echo " [-p PUSH ...]"
echo
echo "optional arguments:"
echo " -d Disable NAT routing and default route"
@ -47,6 +48,7 @@ set -ex
OVPN_ENV=$OPENVPN/ovpn_env.sh
OVPN_SERVER=192.168.255.0/24
OVPN_DEFROUTE=1
OVPN_PUSH=()
# Import defaults if present
[ -r "$OVPN_ENV" ] && source "$OVPN_ENV"
@ -55,7 +57,7 @@ ORIG_OVPN_ROUTES=$OVPN_ROUTES
OVPN_ROUTES=""
# Parse arguments
while getopts ":r:s:du:c" opt; do
while getopts ":r:s:du:cp:" opt; do
case $opt in
r)
if [ -n "$OVPN_ROUTES" ]; then
@ -76,6 +78,9 @@ while getopts ":r:s:du:c" opt; do
c)
OVPN_CLIENT_TO_CLIENT=1
;;
p)
OVPN_PUSH+=("$OPTARG")
;;
\?)
set +x
echo "Invalid option: -$OPTARG" >&2
@ -118,7 +123,7 @@ fi
export OVPN_SERVER OVPN_ROUTES OVPN_DEFROUTE
export OVPN_SERVER_URL OVPN_ENV OVPN_PROTO OVPN_CN OVPN_PORT
export OVPN_CLIENT_TO_CLIENT
export OVPN_CLIENT_TO_CLIENT OVPN_PUSH
# Preserve config
if [ -f "$OVPN_ENV" ]; then
@ -169,6 +174,11 @@ for i in ${OVPN_ROUTES[@]}; do
echo route $(getroute $i) >> "$conf"
done
# Append push commands
for i in "${OVPN_PUSH[@]}"; do
echo push \"$i\" >> "$conf"
done
# Clean-up duplicate configs (always return success)
diff -q "$bak_env" "$OVPN_ENV" 2> /dev/null && rm "$bak_env" || true
diff -q "$bak" "$conf" 2> /dev/null && rm "$bak" || true