-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patht4d
More file actions
executable file
·292 lines (281 loc) · 12 KB
/
t4d
File metadata and controls
executable file
·292 lines (281 loc) · 12 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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/usr/bin/env zsh
autoload -U colors &> /dev/null
colors &> /dev/null
export T4D_ROOT_PATH="${T4D_ROOT_PATH:-$HOME/.tools4dev}"
if [[ "$(readlink $0)" != "" ]]; then
export Tools4Dev_PATH="$(dirname "$(readlink -f $0)")"
elif [[ -e "$0/../src" ]]; then
export Tools4Dev_PATH="$(dirname "$0")"
else
export Tools4Dev_PATH="$T4D_ROOT_PATH/src"
fi
function t4d-init() {
source $T4D_ROOT_PATH/init
}
function t4d-native(){
if [[ -e "$HOME/.zshenv" ]]; then
echo "BackUp $HOME/.zshenv -> $HOME/.zshenv.old"
cat "$HOME/.zshenv" > $HOME/.zshenv.old
cat "$HOME/.zshenv" | grep -v "^ZDOTDIR" > $HOME/.zshenv.tmp
mv $HOME/.zshenv.tmp $HOME/.zshenv
if [[ ! -e "$HOME/.tools4dev/.zsh_history" ]] && [[ "$$HOME/.zsh_history" ]] ; then
cp $HOME/.zsh_history $HOME/.tools4dev/
fi
fi
echo "ZDOTDIR=$HOME/.tools4dev" >> $HOME/.zshenv
}
function t4d-setup() {
mkdir -p $T4D_ROOT_PATH
if [[ ! -e "$T4D_ROOT_PATH/src" ]] || [[ "$1" == "-force" ]]; then
echo "Initial T4D Setup $Tools4Dev_PATH [$0]"
if [[ "$Tools4Dev_PATH" != "$T4D_ROOT_PATH/src" ]] && [[ -e "/opt/homebrew/opt/tools4dev" ]]; then
ln -sfnv "/opt/homebrew/opt/tools4dev/src" "$T4D_ROOT_PATH/src"
elif [[ "$Tools4Dev_PATH" != "$T4D_ROOT_PATH/src" ]] && [[ -e "/usr/local/opt/tools4dev" ]]; then
ln -sfnv "/usr/local/opt/tools4dev/src" "$T4D_ROOT_PATH/src"
elif [[ "$Tools4Dev_PATH" != "$T4D_ROOT_PATH/src" ]]; then
ln -sfnv "$Tools4Dev_PATH" "$T4D_ROOT_PATH/src"
elif [[ -e "$T4D_ROOT_PATH/src-devel" ]]; then
ln -sfnv "$T4D_ROOT_PATH/src-devel" "$T4D_ROOT_PATH/src"
fi
fi
if [[ ! -e "$(readlink -f $T4D_ROOT_PATH/.zshrc)" ]]; then
if [[ -e "$T4D_ROOT_PATH/.zshrc" ]] && [[ "$(readlink -f $T4D_ROOT_PATH/.zshrc)" != "$T4D_ROOT_PATH/.zshrc" ]]; then
rm $T4D_ROOT_PATH/.zshrc
fi
ZSH_PATH="$(command -v env) zsh"
if [[ -e $HOME/.zshrc ]] && [[ "$(cat $HOME/.zshrc | grep 'tools4dev')" == "" ]]; then
T4D_USE_ZSHRC="true"
fi
if [[ -e "$T4D_ROOT_PATH/src/Templates/t4drc.env" ]] || [[ "$1" == "-force" ]]; then
cd $T4D_ROOT_PATH
echo "Creating $T4D_ROOT_PATH/.zshrc"
cat "$T4D_ROOT_PATH/src/Templates/t4drc.env" | sed "s|<T4D_USE_ZSHRC>|${T4D_USE_ZSHRC:-false}|g" \
| sed "s|<ZSH_PATH>|${ZSH_PATH:-$(which zsh)}|g" \
| sed "s|<T4D_PROMPT>|${T4D_PROMPT:-true}|g" > ".zshrc"
fi
fi
if [[ ! -e "$T4D_ROOT_PATH/.zshrc" ]] || [[ "$1" == "-force" ]]; then
echo "Tools4Dev setup Link"
(
cd $T4D_ROOT_PATH
mkdir -p completions bin lib team
ln -sfn "src/project.env" "${T4D_ROOT_PATH}/project.env"
ln -sfn "../src/t4d" "${T4D_ROOT_PATH}/bin/t4d"
ln -sfn "src/Templates/init.env" "${T4D_ROOT_PATH}/init"
ln -sfn "../src/Templates/Team-New" "${T4D_ROOT_PATH}/team/Default"
if [[ ! -e "${T4D_ROOT_PATH}/manifest.xml" ]]; then
ln -sfn "src/Templates/Team-New/t4d-manifest.xml" "${T4D_ROOT_PATH}/manifest.xml"
fi
)
fi
t4d-native
}
if [[ -e "$Tools4Dev_PATH/manifest.xml" ]]; then
export WS_TEAM="$(cat $Tools4Dev_PATH/manifest.xml | grep '<team' | grep -Eo 'name=.*' | cut -d '"' -f2)"
fi
export T4D_SILENT_COMMAND=true
case $1 in
start*)
_ForceSrcUpdate="$2"
mkdir -p $T4D_ROOT_PATH
if [[ -e "$T4D_ROOT_PATH/src" ]] && [[ "$_ForceSrcUpdate" != "-f" ]]; then
if [[ "$1" == "start-with-debug" ]]; then
echo "Using $(readlink -f $T4D_ROOT_PATH/src) [$0]"
fi
fi
t4d-setup
if [[ "$1" == "start-with-debug" ]]; then
echo "Welcome to Tools4Dev [$(cat $Tools4Dev_PATH/VERSION)]"
fi
export ZDOTDIR=$T4D_ROOT_PATH; zsh
;;
*version)
cat $Tools4Dev_PATH/VERSION
;;
*help)
echo "TO DO helper"
;;
setup)
t4d-setup -force
;;
team*)
if [[ "$1" == "team-with-debug" ]]; then
echo "$0"
echo "-> T4D_ROOT_PATH=$T4D_ROOT_PATH"
fi
t4d-setup
t4d-init &> /dev/null
if [[ "$2" == "-add" ]]; then
_TeamOriginalPath="$PWD"
if [[ -e "$_TeamOriginalPath/t4d-manifest.xml" ]]; then
export WS_TEAM="$(cat $_TeamOriginalPath/t4d-manifest.xml | grep '<team' | grep -Eo 'name=.*' | cut -d '"' -f2)"
if [[ ! -e "$T4D_ROOT_PATH/team/$WS_TEAM" ]]; then
ln -sfn $_TeamOriginalPath $T4D_ROOT_PATH/team/$WS_TEAM
ln -sfn $_TeamOriginalPath/t4d-manifest.xml $T4D_ROOT_PATH/manifest.xml
_t4dCheckSucceeded "Team $WS_TEAM added to Tools4Dev"
_t4dDebugLog $pinfo "you can now use wkd to reload your environment"
else
_t4dCheckInfo "Team $WS_TEAM already exist"
ln -sfn $_TeamOriginalPath/t4d-manifest.xml $T4D_ROOT_PATH/manifest.xml
fi
else
_t4dDebugLog $perror "Folder >$_TeamOriginalPath< does not contain t4d-manifest.xml"
fi
else
local _TeamOriginalPath="$(readlink $T4D_ROOT_PATH/team/$2)"
if [[ "$_TeamOriginalPath" == "" ]]; then
_TeamOriginalPath="$T4D_ROOT_PATH/team/$2"
fi
if [[ -e "$_TeamOriginalPath/t4d-manifest.xml" ]] && [[ "$WS_TEAM" != "$2" ]]; then
ln -sfn $_TeamOriginalPath/t4d-manifest.xml $T4D_ROOT_PATH/manifest.xml
_t4dDebugLog $plog "Tools4Dev is now linked to $2"
_t4dDebugLog $plog "Team folder is now $_TeamOriginalPath"
_t4dDebugLog $pinfo "you can now use wkd to reload your environment"
elif [[ "$WS_TEAM" == "$2" ]]; then
if [[ "$1" == "team-with-debug" ]]; then
_t4dCheckSucceeded "Team $2 already setup in Tools4Dev"
fi
fi
fi
;;
link)
echo "Using $Tools4Dev_PATH [$0]"
local _Src="$Tools4Dev_PATH"
if [[ "$_Src" != "$T4D_ROOT_PATH/src" ]]; then
ln -sfnv "$_Src" "$T4D_ROOT_PATH/src"
elif [[ "$Tools4Dev_PATH" != "$T4D_ROOT_PATH/src" ]]; then
ln -sfnv "$Tools4Dev_PATH" "$T4D_ROOT_PATH/src"
elif [[ -e "$T4D_ROOT_PATH/src-devel" ]]; then
ln -sfnv "$T4D_ROOT_PATH/src-devel" "$T4D_ROOT_PATH/src"
fi
;;
native)
t4d-native
;;
update)
set -e
shift
t4d-init &> /dev/null || t4d-init
# t4dLoadProjectConf &> /dev/null
t4dUpdate ${@}
;;
clone)
set -e
shift
cd $Tools4Dev_PATH
t4d-init &> /dev/null || t4d-init
# t4dLoadProjectConf &> /dev/null
t4dUpdate
wks clone ${@}
;;
exec)
set -e
if [[ -e $PWD/project.env ]]; then
source $PWD/project.env &> /dev/null
else
source $Tools4Dev_PATH/tools4Dev.env &> /dev/null
fi
t4dLoadProjectConf &> /dev/null || t4dLoadProjectConf
$@
;;
docker)
set -e
shift
cd $Tools4Dev_PATH
t4d-init
mkdir -p $Tools4Dev_PATH/.t4d
_branch="$(_t4dSrcGitInfoBranch)"
_lastTag="$(_t4dSrcGitInfoLastTag)"
_lastTagName="$(echo $_lastTag | cut -d ' ' -f2)"
_lastTagCommit="$(echo $_lastTag | cut -d ' ' -f1)"
_Commit="$(_t4dSrcGitInfoLogFromBranch "$(echo $_lastTag | cut -d ' ' -f1)" HEAD | wc -l | tr -d ' ')"
if [[ "$(echo $_lastTagName | grep -Eo '\-dev[0-9].*')" != "" ]]; then
_CountTag="$(echo $_lastTagName | grep -Eo '\-dev[0-9].*' | sed 's|\-dev||g')"
_CommitSuffix="$(_t4dMath $_Commit + $_CountTag)"
else
_CommitSuffix="$_Commit"
fi
_Version="$(cat $Tools4Dev_PATH/VERSION)"
if [[ -e "$Tools4Dev_PATH/.t4d/.containerID" ]]; then
T4D_CONTAINER_ID="$(cat $Tools4Dev_PATH/.t4d/.containerID)"
fi
_gitRevision="$(_t4dSrcGitInfoRevision)"
case $_gitRevision in
develop)
_VersionSuffix="-dev$_CommitSuffix"
;;
support/*|release/*)
_CommitSuffix="$(_t4dSrcGitInfoLogFromBranch "develop" HEAD | wc -l | tr -d ' ')"
_VersionSuffix="-rc${_CommitSuffix}"
;;
$_Version)
_VersionSuffix=""
;;
esac
case $1 in
build)
rm tools4dev.tar 2> /dev/null || true
echo "docker build -t tools4dev:$_Version${_VersionSuffix} ."
docker build --no-cache --progress=plain --build-arg T4D_BRANCH="$_gitRevision" --build-arg T4D_FINAL_VERSION_SUFFIX="$_VersionSuffix" -t tools4dev:$_Version${_VersionSuffix} .
echo "docker run -dt tools4dev:$_Version${_VersionSuffix}"
docker run -dt tools4dev:$_Version${_VersionSuffix} > $Tools4Dev_PATH/.t4d/.containerID
echo "export to $Tools4Dev_PATH/.t4d/docker/build"
mkdir -p $Tools4Dev_PATH/.t4d/docker/build/tools4dev
docker cp $(cat $Tools4Dev_PATH/.t4d/.containerID):/root/.tools4dev/tools4dev.tar $Tools4Dev_PATH/.t4d/docker/build/tools4dev_${_Version}${_VersionSuffix}.tar
cd $Tools4Dev_PATH/.t4d/docker/build
mkdir -p "${_Version}${_VersionSuffix}"
sha256sum "tools4dev_${_Version}${_VersionSuffix}.tar" > "tools4dev_${_Version}${_VersionSuffix}.tar.sha"
tar -xf "tools4dev_${_Version}${_VersionSuffix}.tar" -C "${_Version}${_VersionSuffix}"
echo "To test new t4d setup you can now launch"
echo "t4d start $Tools4Dev_PATH/.t4d/docker/build/${_Version}${_VersionSuffix}"
echo "OR"
echo "git tag ${_Version}${_VersionSuffix} && git push --tags"
echo "gh release create \"${_Version}${_VersionSuffix}\" -p -t \"Development Build\" \"$Tools4Dev_PATH/.t4d/docker/build/tools4dev_${_Version}${_VersionSuffix}.tar\""
if [[ -e "$Tools4Dev_PATH/.t4d/docker/build/tools4dev_${_Version}${_VersionSuffix}.tar.sha" ]]; then
echo "sha -> $(cat "$Tools4Dev_PATH/.t4d/docker/build/tools4dev_${_Version}${_VersionSuffix}.tar.sha")"
fi
_DockerContainer="$(docker ps | grep "tools4dev:$_Version${_VersionSuffix}" | cut -d ' ' -f1)"
docker stop $_DockerContainer
docker rm $_DockerContainer
;;
run)
docker run -dt tools4dev:$_Version${_VersionSuffix} > $Tools4Dev_PATH/.t4d/.containerID
;;
exec)
if [[ -e "$Tools4Dev_PATH/.t4d/.containerID" ]]; then
docker exec -it $T4D_CONTAINER_ID zsh
fi
;;
stop)
if [[ -e "$Tools4Dev_PATH/.t4d/.containerID" ]]; then
docker stop $T4D_CONTAINER_ID
rm $Tools4Dev_PATH/.t4d/.containerID
fi
;;
esac
;;
-path|path)
set -e
cd $2
shift
shift
if [[ -e $PWD/project.env ]]; then
source $PWD/project.env &> /dev/null || source $PWD/project.env
else
source $Tools4Dev_PATH/tools4Dev.env &> /dev/null || source $Tools4Dev_PATH/tools4Dev.env
fi
t4dLoadProjectConf &> /dev/null || t4dLoadProjectConf
$@
;;
*)
set -e
if [[ -e $PWD/project.env ]]; then
source $PWD/project.env &> /dev/null || source $PWD/project.env
else
source $Tools4Dev_PATH/tools4Dev.env &> /dev/null || source $Tools4Dev_PATH/tools4Dev.env
fi
t4dLoadProjectConf &> /dev/null || t4dLoadProjectConf
# set -x
$*
;;
esac