Forked from ianlintner-wf/docker-machine-update-hosts.sh
Created
January 28, 2016 15:19
-
-
Save jcarley/3be3478b19f933291e6f 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