-
Notifications
You must be signed in to change notification settings - Fork 29
/
turnkey-lexicon
executable file
·109 lines (81 loc) · 3.18 KB
/
turnkey-lexicon
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash -e
# fallback defaults - adjust as desired
VENV_FALLBACK=/usr/local/src/venv
export VENV_BASE="${VENV_BASE:-$VENV_FALLBACK}"
[[ -z "$DEBUG" ]] || set -x
no_venv() {
cat <<EOF
FATAL: $@
Lexicon venv not available. To set up/install, please run:
confconsole
Then select:
Advanced >> Let's Encrypt >> Get Certificate >> DNS-01
If you encounter problems, please report to TurnKey, either via our forums:
https://www.turnkeylinux.org/forum/support
Or open an issue on our tracker:
https://github.com/turnkeylinux/tracker/issues
EOF
exit 1
}
usage() {
cat <<EOF
Syntax $(basename "$0") [-h|--help] [-l|--lexicon-help] [<lexicon_args>] [<provider>]
Lexicon is a tool to manipulate DNS records on various DNS providers in a
standardized way.
TurnKey Confconsole leverages lexicon to support Let's Encrypt
DNS challenges, via Dehydrated. This script ensures that lexicon is run
within it's required virtual environment.
This wrapper script runs lexicon from a predetermined virtual environment,
with <lexicon_args> and/or <provider>.
This wrapper script is shipped as part of confconsole and expects lexicon to
already be installed via pip to a venv, located at $VENV_FALLBACK/lexicon.
If lexicon is not already installed into the venv, then this script will
fail.
To install/setup lexicon in venv as this wrapper expects, please run:
Confconsole >> Advanced >> Let's Encrypt >> Get Certificate >> DNS-01
Once lexicon is installed as expected, this wrapper can be run independantly
of Confconsole.
Args::
------
Note that if you pass more that one argument/option to $(basename "$0"), all
args are passed directly to lexicon.
-h|--help Display this help and exit - nothing passed to lexicon
-h|--help PROVIDER Display lexicon help for PROVIDER - all args passed to lexicon
-l|--lexicon-help Show lexicon -h|--help - -h|--help passed to lexicon
Env vars::
----------
VENV_BASE Base dir to find lexicon venv dir.
Default: $VENV_FALLBACK
DEBUG Set to enable verbose output - useful for debugging
EOF
exit 1
}
lexicon_bin() {
source "$VENV_BASE/lexicon/bin/activate"
"$VENV_BASE/lexicon/bin/lexicon" $(printf '%q ' "$@")
}
if [[ "$(id -u)" -ne 0 ]]; then
echo "FATAL: $(basename "$0") must be run as root, please re-run with sudo"
fi
if [[ ! -e "$VENV_BASE" ]]; then
no_venv "VENV_BASE ($VENV_BASE) does not exist"
elif [[ ! -d "$VENV_BASE" ]]; then
no_venv "VENV_BASE ($VENV_BASE) exists but is a file - please remove first"
elif [[ ! -d "$VENV_BASE/lexicon" ]]; then
no_venv "lexicon venv ($VENV_BASE/lexicon) does not exist (or is not a directory)"
elif [[ ! -f "$VENV_BASE/lexicon/bin/activate" ]] \
|| [[ ! -x "$VENV_BASE/lexicon/bin/lexicon" ]]; then
no_venv "lexicon venv executables missing"
fi
chown -R root:root "$VENV_BASE"
if [[ "$#" == 1 ]]; then
case $1 in
-h|--help) usage;;
-l|--lexicon-help) lexicon_bin --help;;
*) lexicon_bin "$1";;
esac
else
# note: double quotes around $@ prevents globbing and word splitting of
# individual elements, while still expanding to multiple separate args
lexicon_bin "$@"
fi