-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-dist.sh
executable file
·106 lines (100 loc) · 2.4 KB
/
build-dist.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
#!/usr/bin/env bash
#
# Builds release version of mixtape.
#
# Global vars & imports
DIR=$(dirname $0)
COMMON=${DIR}/bin/mixtape-common.sh
# Checks if a function is used by a script
func_in_use() {
local FUNC=$1 SCRIPT=$2 COUNT
case ${FUNC} in
versioninfo|usage)
FUNC=parseargs
;;
index_epoch|index_datetime|index_files)
grep -q index_ "${SCRIPT}"
return $?
;;
index_content_regex)
FUNC=index_content
;;
largefile_search_sha)
FUNC=largefile_store
;;
esac
if grep -q -P "${FUNC}( |\$)" "${SCRIPT}" ; then
return 0
fi
COUNT=$(grep -P "${FUNC}( |\$)" "${COMMON}" | wc -l)
if [[ ${COUNT} -gt 0 ]] ; then
return 0
fi
return 1
}
# Prints the used code from mixtape-common.sh
print_common_inlined() {
local SCRIPT=$1 ECHO=false LINE= COMMENT= FUNC=
while IFS= read -r LINE ; do
case ${LINE} in
*"() {")
FUNC=${LINE%%()*}
if func_in_use "${FUNC}" "${SCRIPT}" ; then
[[ -n ${COMMENT} ]] && echo "${COMMENT}" || true
echo "${LINE}"
ECHO=true
COMMENT=
else
ECHO=false
COMMENT=
fi
;;
"}")
${ECHO} && echo "${LINE}" || true
;;
"#"*)
COMMENT="${LINE}"
;;
"")
${ECHO} && echo || true
ECHO=true
COMMENT=
;;
*)
${ECHO} && [[ -n ${COMMENT} ]] && echo "${COMMENT}" || true
${ECHO} && echo "${LINE}" || true
COMMENT=
;;
esac
done < ${COMMON}
}
# Prints a script with mixtape-common.sh inlined
print_inlined_script() {
local SCRIPT=$1 ECHO=true LINE=
while IFS= read -r LINE ; do
case ${LINE} in
'# Import common'*)
ECHO=false
;;
'source "${LIBRARY}"'*)
ECHO=true
print_common_inlined "${SCRIPT}"
continue
;;
esac
${ECHO} && echo "${LINE}" || true
done < ${SCRIPT}
}
# Program start
main() {
local FILE
rm -rf dist
mkdir -p dist/bin
for FILE in bin/*.sh ; do
if [[ ${FILE} != */mixtape-common.sh ]] ; then
print_inlined_script ${FILE} > dist/${FILE%%.sh}
fi
done
chmod +x dist/bin/*
}
main