-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.sh
52 lines (52 loc) · 1.93 KB
/
build.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
#!/bin/bash
## build
## - builds a copy of script with resolved . lines
## version 0.0.5 - ignore error exit function
##################################################
build() {
local -r regex_source_line='^\s*[.]\s\+'
local -r regex_error_exit_func_line='^_exit\s".{FUNCNAME}"\s".{LINENO}"$'
local outfile
outfile="${build}/$( basename ${0} .sh )"
cecho green "building standalone ..."
################################################
## 1. cleanup build (creates empty build dir)
## 1. populate build (minimum: source script)
## 1.1 migrate script
################################################
## 1. cleanup build (creates empty build dir)
################################################
cecho green "cleanup up build ..."
cecho yellow $( test ! -d "${build}" || rm -rvf ${_} )
cecho yellow $( mkdir -v "${build}" )
cecho green "build clean"
################################################
## 1. populate build (minimum: source script)
################################################
## 1.1 migrate script
## - resolves '.' lines
## - keeps 'source' lines
################################################
{ # resolve source lines
bash -vp ${0} true 2>&1 |
grep -v \
-e "${regex_source_line}" \
-e "${regex_error_exit_func_line}"
} | tee ${outfile}.sh
################################################
## obfuscate output to prevent easy tampering
################################################
test ! "${do_obfuscate}" || {
test ! $( which bash-obfuscate 2>/dev/null ) || {
bash-obfuscate ${outfile}.sh > ${outfile}.sh-temp
mv -v ${outfile}.sh{-temp,}
}
}
################################################
cecho green "standalone built"
}
##################################################
## generated by create-stub2.sh v0.1.2
## on Sat, 04 May 2019 11:57:45 +0900
## see <https://github.com/temptemp3/sh2>
##################################################