From 46c266854ece8ee6f6dc3dc35c55c9d1b3e2d205 Mon Sep 17 00:00:00 2001 From: hiroTochigi Date: Fri, 9 Feb 2024 21:07:10 -0600 Subject: [PATCH] Add replaceIp function and use it to update IP address in restart.sh --- src/aws/dependencies/replaceIp.sh | 19 +++++++++++++++++++ src/aws/restart.sh | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/aws/dependencies/replaceIp.sh diff --git a/src/aws/dependencies/replaceIp.sh b/src/aws/dependencies/replaceIp.sh new file mode 100644 index 00000000..2b195dbf --- /dev/null +++ b/src/aws/dependencies/replaceIp.sh @@ -0,0 +1,19 @@ +replaceIp() { + FILE="/etc/tunnel" + + if [ "$#" -ne 2 ]; then + echo "Usage: replace_ip OLD_IP NEW_IP" + return 1 + fi + + oldIp=$1 + newIp=$2 + + if [ -f "$FILE" ]; then + sudo sed -i "s/$newIp/$oldIp/g" "$FILE" + echo "IP address has been successfully replaced." + else + echo "Error: File $FILE does not exist." + return 1 + fi +} diff --git a/src/aws/restart.sh b/src/aws/restart.sh index 33a300ba..69071992 100644 --- a/src/aws/restart.sh +++ b/src/aws/restart.sh @@ -18,6 +18,8 @@ function restart(){ exit 1 fi + oldPublicIp=$(getValueByAttribute $balloonName publicIp) + aws ec2 start-instances --instance-ids $instanceId echo "get the new ip address. The procedure might take time for a while" @@ -28,6 +30,5 @@ function restart(){ echo "the new ip address is $publicIp" updateIPAddress $balloonName $publicIp - echo "open the new sshtunnel" - openSSHTunnel $publicIp $portConfigArray + replaceIp $oldPublicIp $publicIp } \ No newline at end of file