-
-
Save vertexvaar/f36d57db5e5bca39a0dd0fb5bab56403 to your computer and use it in GitHub Desktop.
Create host entry in makefile if it does not exist for linux and mac
This file contains hidden or 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
HOST=local.project.com |
This file contains hidden or 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
add-hosts-entry: | |
SERVICES=$$(command -v getent > /dev/null && echo "getent ahostsv4" || echo "dscacheutil -q host -a name"); \ | |
if [ ! "$$($$SERVICES $(HOST) | grep 127.0.0.1 > /dev/null; echo $$?)" -eq 0 ]; then sudo bash -c 'echo "127.0.0.1 $(HOST)" >> /etc/hosts; echo "Entry was added"'; else echo 'Entry already exists'; fi; | |
include .env | |
SHELL := /bin/bash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment