mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 17:51:57 +00:00
25 lines
642 B
Bash
Executable File
25 lines
642 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euf -o pipefail
|
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")/.."
|
|
|
|
hosts=/etc/hosts
|
|
domain="${SOURCEGRAPH_HTTPS_DOMAIN:-"sourcegraph.test"}"
|
|
entry="$(printf "\n127.0.0.1\t%s" "${domain}")"
|
|
|
|
if grep -q -w -F -- "${domain}" "${hosts}"; then
|
|
echo "--- ${domain} already exists in ${hosts}"
|
|
elif [ -w "${hosts}" ]; then
|
|
# Don't need sudo
|
|
echo "--- adding ${domain} to ${hosts}"
|
|
echo "${entry}" >>"${hosts}"
|
|
else
|
|
echo "--- adding ${domain} to ${hosts} (you may need to enter your password)"
|
|
sudo ENTRY="${entry}" HOSTS="${hosts}" bash -c 'echo "${ENTRY}" >> "${HOSTS}"'
|
|
fi
|
|
|
|
echo "--- printing ${hosts}"
|
|
|
|
cat "${hosts}"
|