Last active
October 29, 2019 20:16
-
-
Save ianlintner-wf/a2b917158aaf100d9fb3 to your computer and use it in GitHub Desktop.
A basic shell script to use a configuration file to update local development hosts ip running on docker-machine (virtual box) and Mac OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
#Usage docker-machine-update-hosts.sh hosts.conf default | |
#arg1 is a configuration file with hosts | |
#arg2 is the docker-machine name e.g. default | |
DOCKER_IP=$(docker-machine ip $2) | |
echo "$2 ip: $DOCKER_IP" | |
#Remove existing lines from hosts | |
while IFS='' read -r line || [[ -n "$line" ]]; do | |
echo "Removing existing domain $line" | |
sudo sed -i '' '/'$line'/d' /etc/hosts | |
done < "$1" | |
#Add new hosts to the bottom of the file | |
while IFS='' read -r line || [[ -n "$line" ]]; do | |
echo "Adding entry $DOCKER_IP $line" | |
sudo echo "$DOCKER_IP $line" >>/etc/hosts | |
done < "$1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
example.dev | |
other-site.local | |
my-site.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you could do:
if you wanted to default the second parameter to the "active" docker-machine name.