Skip to content

Commit

Permalink
Add replaceIp function and use it to update IP address in restart.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroTochigi committed Feb 10, 2024
1 parent 944a7c7 commit 46c2668
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/aws/dependencies/replaceIp.sh
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 3 additions & 2 deletions src/aws/restart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

0 comments on commit 46c2668

Please sign in to comment.