From b41b919d4c1ae0a9a3bcdc6c405129c4728cc80d Mon Sep 17 00:00:00 2001 From: Joey Hafner Date: Sun, 7 Jan 2024 02:26:18 -0800 Subject: [PATCH] Update for better script method --- wizard/scripts/update_hairpin_nat.sh | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/wizard/scripts/update_hairpin_nat.sh b/wizard/scripts/update_hairpin_nat.sh index 562e748..5acf9a0 100644 --- a/wizard/scripts/update_hairpin_nat.sh +++ b/wizard/scripts/update_hairpin_nat.sh @@ -1,26 +1,23 @@ #!/bin/vbash source /opt/vyatta/etc/functions/script-template -# create copies of config for modification and backup -cp /config/config.boot /config/config.new -cp /config/config.boot /config/backups/config.bk-$(date +%Y-%m-%d) +# get current public IP +NEW_IP=$(show interfaces pppoe pppoe1 | grep "inet\s" | cut -d ' ' -f 6) +# get old public IP +OLD_IP=$(show nat destination rules | grep 1100 | head -1 | tr -s ' ' | cut -d' ' -f 3) + + +show configuration commands | grep $OLD_IP | sed --expression="s/$OLD_IP/$NEW_IP/" > ipupdate.tmp -# switch mode to config configure -# get current public IP -NEW_IP=$(run show interfaces pppoe pppoe1 | grep "inet\s" | cut -d ' ' -f 6) -# get old public IP -OLD_IP=$(run show nat destination rules | grep 1100 | head -1 | tr -s ' ' | cut -d' ' -f 3) +source ipupdate.tmp -# edit the config.new file -sed -i "s/$OLD_IP/$NEW_IP/" /config/config.new - -# apply the new config -load /config/config.new { # try commit, save, exit commit && save && exit } || { # catch, exit discard and create a very basic error file exit discard echo "Script failed. Write some real error handling." } + +rm ipupdate.tmp