forked from TYPO3-Documentation/TYPO3CMS-Guide-HowToDocument
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
161 lines (143 loc) · 5.07 KB
/
run.sh
File metadata and controls
161 lines (143 loc) · 5.07 KB
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
# NOTE
# You can 'source' this file directly into the shell of your commandline with:
# source <(docker run --rm t3docs/render-documentation:v1.6.11-full show-shell-commands)
# ATTENTION:
# No whitespace between '<('
# the usual worker command like 'dockrun_t3rdf'
function dockrun_t3rdf () {
# Environment variables the USER may find important (on the host!),
# no slash ('/') at the end,
# default is the current directory $(pwd):
#
# T3DOCS_PROJECT=/absolute/path/to/project/start/folder
# T3DOCS_RESULT=/absolute/path/to/result/folder
# T3DOCS_TMP=/absolute/path/to/temporary/folder
# T3DOCS_DUMMY_WEBROOT=/absolute/path/to/output/dummy_webroot/
#
# Environment variables only some DEVELOPERS may find important,
# no slash ('/') at the end,
#
# T3DOCS_MAKEDIR=/absolute/path/to/makedir
# T3DOCS_MENU=/absolute/path/to/menu
# T3DOCS_RUNDIR=/absolute/path/to/rundir
# T3DOCS_TOOLCHAINS=/absolute/path/to/toolchains
# Example:
# local DEBUG=${T3DOCS_DEBUG:-0}
# local DEBUG=${T3DOCS_DEBUG:-1}
# set T3DOCS_DEBUG=0 or set T3DOCS_DEBUG=1
local DEBUG=${T3DOCS_DEBUG:-0}
local git_restore_mtime=$(which git-restore-mtime)
local exitcode=$?
if [[ $exitcode -ne 0 ]]; then git_restore_mtime=; fi
# start command building
local cmd="docker run --rm"
if [[ $# -eq 0 ]]; then
# note: CREATING=0 leads to root:root permissions (why? to be solved!)
local CREATING=1
cmd="$cmd --user=$(id -u):$(id -g)"
elif [[ "$@" = "/bin/bash" ]]; then
# note: CREATING=0 leads to root:root permissions (why? to be solved!)
local CREATING=1
cmd="$cmd --entrypoint /bin/bash -it"
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 "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
# DUMMY_WEBROOT
# absolute path to existing folder DUMMY_WEBROOT
local DUMMY_WEBROOT=${T3DOCS_DUMMY_WEBROOT:-$(pwd)/tmp-GENERATED-dummy_webroot}
if [ -d "$DUMMY_WEBROOT" ]; then
cmd="$cmd -v $DUMMY_WEBROOT:/ALL/dummy_webroot"
if (($DEBUG)); then echo "DUMMY_WEBROOT: $DUMMY_WEBROOT"; 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
# RUNDIR
# absolute path to existing folder RUNDIR
local RUNDIR=${T3DOCS_RUNDIR:-$(pwd)/tmp-GENERATED-Rundir}
if [ -d "$RUNDIR" ]; then
cmd="$cmd -v $RUNDIR:/ALL/Rundir"
if (($DEBUG)); then echo "RUNDIR.......: $RUNDIR"; 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
# Add current working directory in environment variable HOST_CWD
# (PWD should be defined in all POSIX compliant shells)
if [ ! -z "/ALL/Rundir" ];then
cmd="$cmd -e HOST_CWD=$PWD"
fi
cmd="$cmd t3docs/render-documentation:v1.6.11-full"
if (($DEBUG)); then echo "OUR_IMAGE....: t3docs/render-documentation:v1.6.11-full"; fi
# add remaining arguments
if [[ "$@" != "/bin/bash" ]]; then
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"
fi
if (($DEBUG)); then
echo $cmd | sed "s/-v /\\\\\\n -v /g"
fi
eval "$cmd"
}
echo "This function is now defined FOR THIS terminal window:"
echo " dockrun_t3rdf"