ci-demo-2/infrastructure/update-ip-addr.sh

16 lines
560 B
Bash
Executable File

#!/bin/bash
if [ $# -eq 0 ] ; then
newip=$(ifconfig | grep 0xfff | grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' | grep -v 255 | head -1 | sed 's/\./-/g')
searchStr="s/[0-9]\{1,3\}-[0-9]\{1,3\}-[0-9]\{1,3\}-[0-9]\{1,3\}"
elif [ $# -eq 2 ] ; then
newip=$2
searchStr=$1
else
echo "you must either provide 0 arguments or"
echo "exactly 2 arguments:"
echo "./update-ip-adrr.sh <old-ip-or-dns> <new-ip-or-dns>"
fi
echo $newip
sed -i -e "s/${searchStr}"/"$newip"/g .env
sed -i -e 's/[0-9]\{1,3\}-[0-9]\{1,3\}-[0-9]\{1,3\}-[0-9]\{1,3\}'/"$newip"/g README.adoc