Skip to content

Commit

Permalink
Merge pull request #1080 from LoreleiAurora/fix-hosts
Browse files Browse the repository at this point in the history
Add hosts defined in config file to machine host file
  • Loading branch information
jeremyfelt authored Jan 17, 2017
2 parents 54e8b7f + 1fffdc6 commit 78f8a33
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions provision/provision-site.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

SITE=$1
SITE_ESCAPED=`echo ${SITE} | sed 's/\./\\\\./g'`
REPO=$2
BRANCH=$3
VM_DIR=$4
Expand All @@ -9,18 +10,19 @@ NGINX_UPSTREAM=$6
VVV_PATH_TO_SITE=${VM_DIR}
VVV_SITE_NAME=${SITE}

VVV_CONFIG=/vagrant/vvv-config.yml
if [[ -f /vagrant/vvv-custom.yml ]]; then
VVV_CONFIG=/vagrant/vvv-custom.yml
fi

noroot() {
sudo -EH -u "vagrant" "$@";
}

# Takes 2 values, a key to fetch a value for, and an optional default value
# e.g. echo `get_config_value 'key' 'defaultvalue'`
get_config_value() {
local config=/vagrant/vvv-config.yml
if [[ -f /vagrant/vvv-custom.yml ]]; then
config=/vagrant/vvv-custom.yml
fi
local value=`cat ${config} | shyaml get-value sites.${SITE}.custom.${1} 2> /dev/null`
local value=`cat ${VVV_CONFIG} | shyaml get-value sites.${SITE_ESCAPED}.custom.${1} 2> /dev/null`
echo ${value:-$2}
}

Expand Down Expand Up @@ -90,6 +92,12 @@ if [[ -d ${VM_DIR} ]]; then
fi
done < "$hostfile"
done
fi

for line in `cat ${VVV_CONFIG} | shyaml get-values sites.${SITE_ESCAPED}.hosts 2> /dev/null`; do
if [[ -z "$(grep -q "^127.0.0.1 $line$" /etc/hosts)" ]]; then
echo "127.0.0.1 $line # vvv-auto" >> "/etc/hosts"
echo " * Added $line from ${VVV_CONFIG}"
fi
done
fi
service nginx restart

0 comments on commit 78f8a33

Please sign in to comment.