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