Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2702: Guest hosts file fixes #2708

Merged
merged 6 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ permalink: /docs/en-US/changelog/
### Bug Fixes

* The host file inside the VM was only adding sites with `127.0.0.1` addresses, now it adds the IPVv6 `::1` too ( #2689 )
* Fixes for hosts file cleanup ( #2708 )
* Removed old MacOS PR workflows, no runners available ( #2698 )
* Replace an outdated Nginx signing key ( #2710 )

Expand Down
15 changes: 11 additions & 4 deletions provision/core/vvv/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ function vvv_ntp_restart() {
vvv_add_hook services_restart vvv_ntp_restart

function cleanup_vvv(){
if test -f "/tmp/hosts"; then
sudo rm /tmp/hosts
fi

# Cleanup the hosts file
vvv_info " * Cleaning the virtual machine's /etc/hosts file..."
sed -n '/# vvv-auto$/!p' /etc/hosts > /tmp/hosts
Expand All @@ -121,13 +125,16 @@ function cleanup_vvv(){
echo "127.0.0.1 tideways.vvv.test # vvv-auto" >> "/etc/hosts"
echo "127.0.0.1 xhgui.vvv.test # vvv-auto" >> "/etc/hosts"
fi
echo "$(</tmp/hosts)" | sudo tee -a /etc/hosts > /dev/null
sudo cp -rf /tmp/hosts /etc/hosts

# cleanup
if test -f "/tmp/hosts"; then
sudo rm /tmp/hosts
fi
}
export -f cleanup_vvv

if [ "${VVV_DOCKER}" != 1 ]; then
vvv_add_hook finalize cleanup_vvv 15
fi
vvv_add_hook finalize cleanup_vvv 15

function apt_hash_missmatch_fix() {
if [ ! -f "/etc/apt/apt.conf.d/99hashmismatch" ]; then
Expand Down
21 changes: 12 additions & 9 deletions provision/provision-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -654,27 +654,30 @@ 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

# Add each site.
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
echo "127.0.0.1 ${v:-"${VVV_SITE_NAME}.test"}" >> /tmp/site-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
# Remove duplicate lines then replace hosts file.
awk -i inplace '!seen[$0]++' /tmp/hosts

# 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
Loading