Skip to content

Instantly share code, notes, and snippets.

@vertexvaar
Last active November 26, 2019 08:22
Show Gist options
  • Save vertexvaar/f36d57db5e5bca39a0dd0fb5bab56403 to your computer and use it in GitHub Desktop.
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
HOST=local.project.com
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