Skip to content

Commit

Permalink
2702: Refactor vvv_update_guest_hosts to do more cleanup and help wit…
Browse files Browse the repository at this point in the history
…h Docker compatibility
  • Loading branch information
tomjn committed Jun 15, 2024
1 parent efefb25 commit dea0bb9
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions provision/provision-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -654,30 +654,24 @@ export -f vvv_get_sites
# @description Updates the guest environments hosts file.
# @noargs
function vvv_update_guest_hosts() {
if test -f "/tmp/site-hosts"; then
sudo rm /tmp/site-hosts
fi
local SITES
SITES=$(vvv_get_sites)
cp -f /etc/hosts /tmp/hosts
for SITE in $SITES; do
SITE_ESCAPED="${SITE//./\\.}"
VVV_SITE_NAME=${SITE}
local value
value=$(shyaml -q get-values "sites.${SITE_ESCAPED}.hosts" <${VVV_CONFIG})
for v in $value; do
if [[ -z "$(grep -q "^127.0.0.1 ${v:-"${VVV_SITE_NAME}.test"}$" /etc/hosts)" ]]; then
echo "127.0.0.1 ${v:-"${VVV_SITE_NAME}.test"} # vvv-auto" >> "/etc/hosts"
echo "::1 ${v:-"${VVV_SITE_NAME}.test"} # vvv-auto" >> "/etc/hosts"
sed -i "/127.0.0.1 ${v:-"${VVV_SITE_NAME}.test"}/d" /tmp/hosts
if [[ -z "$(grep -q "^127.0.0.1 ${v:-"${VVV_SITE_NAME}.test"}$" /tmp/hosts)" ]]; then
echo "127.0.0.1 ${v:-"${VVV_SITE_NAME}.test"} # vvv-auto" >> "/tmp/hosts"
echo "::1 ${v:-"${VVV_SITE_NAME}.test"} # vvv-auto" >> "/tmp/hosts"
fi
done
done

echo "$(</tmp/site-hosts)" | sudo tee -a /etc/hosts > /dev/null

# cleanup
if test -f "/tmp/site-hosts"; then
sudo rm /tmp/site-hosts
fi
cp -f /tmp/hosts /etc/hosts
rm /tmp/hosts
}
export -f vvv_update_guest_hosts

Expand Down

0 comments on commit dea0bb9

Please sign in to comment.