-
Notifications
You must be signed in to change notification settings - Fork 2
/
add-tld-to-local-resolver
executable file
·89 lines (73 loc) · 1.72 KB
/
add-tld-to-local-resolver
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/bash
set -eo pipefail
SELF="${0##*/}"
function _script_echo { printf "[$(date)] $SELF[$$] $2 #$1\n" "${@:3}" >&2; }
function debug { [[ -z "$DEBUG" ]] || _script_echo DEBUG "$@"; }
function e { [[ -n "$QUIET" ]] || _script_echo INFO "$@"; }
function info { e "$@"; }
function warn { [[ -n "$QUIET" ]] || _script_echo WARNING "$@"; }
function warning { warn "$@"; }
function error { _script_echo ERROR "$@" >&2; }
function death { error "$@"; exit 1; }
function debug_call { debug 'call: %s' "$*"; "$@"; }
function nullify { "$@" >/dev/null 2>&1; }
function errnullify { "$@" 2>/dev/null; }
function os-type() {
local -n ret="${1:?}"
local given_ostype="${2:-$OSTYPE}"
case "${given_ostype,,}" in
linux*) ret=linux ;;
darwin*) ret=osx ;;
esac
}
##
## Meat
##
shopt -s expand_aliases
alias dc=docker-compose
declare -a linux=()
declare -a osx=()
os-type os
declare -n stack="$os"
ns="${1:-127.0.0.69}"
tld="${2:-docker}"
function ensure-doxy {
dc build
dc kill && dc rm -fv || :
dc up -d
}
stack+=(ensure-doxy)
function osx-ensure-resolv {
e "Setting tld=%s to use nameserver=%s" "$tld" "$ns"
sudo mkdir -pv /etc/resolver
sudo tee "/etc/resolver/$tld" \
>/dev/null \
<<-EOF
# Generated by $0 $@
# on $(date)
nameserver $ns
EOF
}
osx+=(osx-ensure-resolv)
function linux-ensure-resolv {
local fn="doxy-$tld"
local dnsmasq_d="/etc/dnsmasq.d/$fn"
error "Set the tld to resolve on your own, bruh."
sudo tee "$dnsmasq_d" \
>/dev/null \
<<-EOF
# Generated by $0 $@
# on $(date)
server=/$tld/$ns
EOF
}
linux+=(linux-ensure-resolv)
function main {
local current
for current in "${stack[@]}"; do
e "OS[%s]: %s" "$os" "$current"
$current
done
e "Done."
}
main "$@"