wg-quick: save all hooks on save

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2017-10-31 19:47:39 +01:00
parent 6e313371cc
commit 753dc179b6

View file

@ -177,7 +177,7 @@ set_config() {
} }
save_config() { save_config() {
local old_umask new_config current_config address local old_umask new_config current_config address cmd
[[ $(ip -all -brief address show dev "$INTERFACE") =~ ^$INTERFACE\ +\ [A-Z]+\ +(.+)$ ]] || true [[ $(ip -all -brief address show dev "$INTERFACE") =~ ^$INTERFACE\ +\ [A-Z]+\ +(.+)$ ]] || true
new_config=$'[Interface]\n' new_config=$'[Interface]\n'
for address in ${BASH_REMATCH[1]}; do for address in ${BASH_REMATCH[1]}; do
@ -188,10 +188,18 @@ save_config() {
done < <(resolvconf -l "tun.$INTERFACE" 2>/dev/null) done < <(resolvconf -l "tun.$INTERFACE" 2>/dev/null)
[[ -n $MTU && $(ip link show dev "$INTERFACE") =~ mtu\ ([0-9]+) ]] && new_config+="MTU = ${BASH_REMATCH[1]}"$'\n' [[ -n $MTU && $(ip link show dev "$INTERFACE") =~ mtu\ ([0-9]+) ]] && new_config+="MTU = ${BASH_REMATCH[1]}"$'\n'
[[ $SAVE_CONFIG -eq 0 ]] || new_config+=$'SaveConfig = true\n' [[ $SAVE_CONFIG -eq 0 ]] || new_config+=$'SaveConfig = true\n'
[[ -z $PRE_UP ]] || new_config+="PreUp = $PRE_UP"$'\n' for cmd in "${PRE_UP[@]}"; do
[[ -z $POST_UP ]] || new_config+="PostUp = $POST_UP"$'\n' new_config+="PreUp = $cmd"$'\n'
[[ -z $PRE_DOWN ]] || new_config+="PreDown = $PRE_DOWN"$'\n' done
[[ -z $POST_DOWN ]] || new_config+="PostDown = $POST_DOWN"$'\n' for cmd in "${POST_UP[@]}"; do
new_config+="PostUp = $cmd"$'\n'
done
for cmd in "${PRE_DOWN[@]}"; do
new_config+="PreDown = $cmd"$'\n'
done
for cmd in "${POST_DOWN[@]}"; do
new_config+="PostDown = $cmd"$'\n'
done
old_umask="$(umask)" old_umask="$(umask)"
umask 077 umask 077
current_config="$(cmd wg showconf "$INTERFACE")" current_config="$(cmd wg showconf "$INTERFACE")"