-
Notifications
You must be signed in to change notification settings - Fork 118
/
shell-commands.sh
executable file
·218 lines (200 loc) · 7.2 KB
/
shell-commands.sh
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# NOTE
# Run this 'eval' command at the command line to define the helper
# function for the current terminal:
# eval "$(docker run --rm t3docs/render-documentation:v3.1.0 show-shell-commands)"
#
# As alternative, you can 'source' the code directly into the shell:
# source <(docker run --rm t3docs/render-documentation:v3.1.0 show-shell-commands)
# ATTENTION:
# No whitespace between '<('
#
# Or, use an intermediate file:
# docker run --rm t3docs/render-documentation:v3.1.0 show-shell-commands >shell-commands.sh
# source shell-commands.sh
# This function defines the helper function, usually named \'dockrun_t3rd\'
function dockrun_t3rd () {
# Environment variables the USER may find important (on the host!),
# no slash ('/') at the end,
# default is the current directory $(pwd):
#
# T3DOCS_PROJECT=/abspathto/MyProjectStartFolder (readonly)
# T3DOCS_RESULT=/abspathto/ResultFolder (readwrite)
# T3DOCS_TMP=/abspathto/TemporaryFolder (readwrite)
# T3DOCS_THEMES=/abspathto/MySphinxThemes (readonly)
#
# Environment variables only some DEVELOPERS may find important,
# no slash ('/') at the end,
#
# T3DOCS_MAKEDIR=/abspathto/MYALL/Makedir
# T3DOCS_MENU=/abspathto/MYALL/Menu
# T3DOCS_TOOLCHAINS=/abspathto/MYALL/Toolchains
# T3DOCS_USERHOME=/abspathto/MYALL/userhome
# T3DOCS_VENV=/abspathto/MYALL/venv
# T3DOCS_WHEELS=/abspathto/WheelsFolder
# T3DOCS_DEBUG=0 (0 or 1, talk to stdout)
# T3DOCS_DRY_RUN=0 (0 or 1, don't really execute)
# T3DOCS_GIT_RESTORE_MTIME=1 (0 or 1, usually 1=on)
local DEBUG=${T3DOCS_DEBUG:-0}
local GIT_RESTORE_MTIME=1
local DRY_RUN=${T3DOCS_DRY_RUN:-0}
local git_restore_mtime=$(which git-restore-mtime)
local exitcode=$?
if [[ $exitcode -ne 0 ]] || [[ "$GIT_RESTORE_MTIME" = "0" ]]; then git_restore_mtime=; fi
# start command building
local cmd="docker run --rm"
if [[ $# -eq 0 ]]; then
# create folders on host? (e.g. Documentation-GENERATED-temp)
local CREATING=1
cmd="$cmd --user=$(id -u):$(id -g)"
elif [[ "$@" = "/bin/bash" ]]; then
local CREATING=1
cmd="$cmd --entrypoint /bin/bash -it"
elif [[ "$@" = "/usr/bin/bash" ]]; then
local CREATING=1
cmd="$cmd --user=$(id -u):$(id -g)"
cmd="$cmd --entrypoint /bin/bash -it"
elif [[ "$1" = "serve4build" ]]; then
local CREATING=1
local PORT=${2:-9999}
cmd="$cmd --user=$(id -u):$(id -g) -it"
cmd="$cmd --publish=${PORT}:${PORT}/tcp"
elif [[ "$1" = "just1sphinxbuild" ]]; then
local CREATING=1
cmd="$cmd --user=$(id -u):$(id -g)"
elif [[ "$@" = "export-ALL" ]]; then
local CREATING=1
cmd="$cmd --entrypoint /bin/bash"
else
local CREATING=1
cmd="$cmd --user=$(id -u):$(id -g)"
fi
# PROJECT - read only!
# assume existing folder PROJECT/Documentation
# absolute path to existing folder PROJECT or current dir
local PROJECT=${T3DOCS_PROJECT:-$(pwd)}
cmd="$cmd -v $PROJECT:/PROJECT:ro"
if (($DEBUG)); then echo "PROJECT......: $PROJECT"; fi
# RESULT
# absolute path to existing folder RESULT of (RESULT/Documentation-GENERATED-temp)
local RESULT=${T3DOCS_RESULT:-$(pwd)}
# force special name to prevent create/delete disasters
RESULT=${RESULT}/Documentation-GENERATED-temp
cmd="$cmd -v $RESULT:/RESULT"
if (($CREATING)); then
if (($DEBUG)); then echo creating.....: mkdir -p "$RESULT" ; fi
mkdir -p "$RESULT" 2>/dev/null
fi
if (($DEBUG)); then echo "git_restore_mtime: $git_restore_mtime"; fi
if (($DEBUG)); then echo "RESULT.......: $RESULT"; fi
# TMP
# absolute path to existing folder TMP of (TMP/tmp-GENERATED-temp)
local TMP=${T3DOCS_TMP:-$(pwd)}
# force special name to prevent create/delete disasters
TMP=${TMP}/tmp-GENERATED-temp
if (($CREATING)) && [[ -n "${T3DOCS_TMP}" ]]; then
mkdir -p "$TMP" 2>/dev/null
fi
if [[ -d "${TMP}" ]]; then
cmd="$cmd -v $TMP:/tmp"
if (($CREATING)); then
/bin/bash -c "rm -rf $TMP/*"
fi
if (($DEBUG)); then echo "TMP..........: $TMP"; fi
fi
# USERHOME
# absolute path to existing folder 'userhome'
local USERHOME=${T3DOCS_USERHOME:-$(pwd)/tmp-GENERATED-userhome}
if [ -d "$USERHOME" ]; then
cmd="$cmd -v $USERHOME:/ALL/userhome"
if (($DEBUG)); then echo "USERHOME......: $USERHOME"; fi
fi
# MAKEDIR
# absolute path to existing folder MAKEDIR
local MAKEDIR=${T3DOCS_MAKEDIR:-$(pwd)/tmp-GENERATED-Makedir}
if [ -d "$MAKEDIR" ]; then
cmd="$cmd -v $MAKEDIR:/ALL/Makedir"
if (($DEBUG)); then echo "MAKEDIR......: $MAKEDIR"; fi
fi
# MENU
# absolute path to existing folder MENU
local MENU=${T3DOCS_MENU:-$(pwd)/tmp-GENERATED-Menu}
if [ -d "$MENU" ]; then
cmd="$cmd -v $MENU:/ALL/Menu"
if (($DEBUG)); then echo "MENU.........: $MENU"; fi
fi
# VENV (used to be 'Rundir')
# absolute path to existing folder VENV
local VENV=${T3DOCS_VENV:-$(pwd)/tmp-GENERATED-venv}
if [ -d "$VENV" ]; then
cmd="$cmd -v $VENV:/ALL/venv"
if (($DEBUG)); then echo "VENV.........: $VENV"; fi
fi
# THEMES
# absolute path to a folder containing Sphinx themes
local THEMES=${T3DOCS_THEMES:-$(pwd)/tmp-GENERATED-Themes}
if [ -d "$THEMES" ]; then
cmd="$cmd -v $THEMES:/THEMES"
if (($DEBUG)); then echo "THEMES.......: $THEMES"; fi
fi
# TOOLCHAINS
# absolute path to existing folder TOOLCHAINS
local TOOLCHAINS=${T3DOCS_TOOLCHAINS:-$(pwd)/tmp-GENERATED-Toolchains}
if [ -d "$TOOLCHAINS" ]; then
cmd="$cmd -v $TOOLCHAINS:/ALL/Toolchains"
if (($DEBUG)); then echo "TOOLCHAINS...: $TOOLCHAINS"; fi
fi
# WHEELS
# absolute path to a folder containing Python wheel packages
local WHEELS=${T3DOCS_WHEELS:-$(pwd)/tmp-GENERATED-Wheels}
if [ -d "$WHEELS" ]; then
cmd="$cmd -v $WHEELS:/WHEELS"
if (($DEBUG)); then echo "WHEELS.......: $WHEELS"; fi
fi
cmd="$cmd ghcr.io/t3docs/render-documentation:v3.1.0"
if (($DEBUG)); then echo "OUR_IMAGE....: t3docs/render-documentation:v3.1.0"; fi
# add remaining arguments
if [[ "$@" = "/bin/bash" ]]; then
true "do nothing here"
elif [[ "$@" = "/usr/bin/bash" ]]; then
true "do nothing here"
elif [[ "$1" = "serve4build" ]]; then
cmd="$cmd ${1} ${PORT}"
elif [[ "$1" = "just1sphinxbuild" ]]; then
cmd="$cmd $@"
echo "See 'Documentation-GENERATED-temp/sphinx-build' for build information"
elif [[ "$@" = "export-ALL" ]]; then
cmd="$cmd -c \"rsync -a --delete --chown=$(id -u):$(id -g) /ALL/ /RESULT/ALL-exported\""
echo The export will go to:
echo " $RESULT/ALL-exported"
else
cmd="$cmd $@"
# if script git-restore-mtime exists and '*make*' in args try the command
# See README: get 'git-restore-mtime' from https://github.com/MestreLion/git-tools
if [[ "$git_restore_mtime" != "" ]] && [[ $@ =~ .*make.* ]]; then
if (($DEBUG)); then
echo $git_restore_mtime
$git_restore_mtime
else
$git_restore_mtime 2>/dev/null
fi
fi
fi
if [[ -w "$RESULT" ]]; then true
echo "$cmd" | sed "s/-v /\\\\\\n -v /g" >"$RESULT/last-docker-run-command-GENERATED.sh.txt"
fi
if (($DEBUG || $DRY_RUN)); then
echo $cmd | sed "s/-v /\\\\\\n -v /g"
fi
if [[ "$DRY_RUN" = "0" ]]; then
eval "$cmd"
fi
}
if [[ ! -v DOCKRUN_FN_QUIET ]]; then true
DOCKRUN_FN_QUIET=0
fi
if [[ "$DOCKRUN_FN_QUIET" -ne 1 ]]; then true
echo "This function is now defined FOR THIS terminal window to run 'v3.1.0':"
echo " dockrun_v3.1.0"
echo ""
echo "(Define 'export DOCKRUN_FN_QUIET=1' to turn this message off)"
fi