-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild
executable file
·257 lines (215 loc) · 8.34 KB
/
build
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
#!/usr/bin/env bash
# Check Android env
if test -z "$GEARLOCK_VER"; then
BD="$(dirname "$(readlink -f "$0")")"
export GTMP="$BD/cache"
mkdir -p "$GTMP"
WORKDIR="$BD/workdir"
GEARLOCK_NAME="gearlock"
GRLOAD="$BD/gearload"
mkdir -p "$GRLOAD"
PATH="$BD/bin:$PATH"
! chmod -R 777 "$BD/bin" && echo -e "Failed to get execution permissions on 'bin/garca'" && exit 1
fi
# Define Vars
_self="${0##*/}"
CompRatio="-mx=${3:-10}"
CompMethod="-m0=${2:-zstd}"
GETT="$WORKDIR"/'!zygote.sh'
PS3="$(echo -e "\nEnter a number >> ")"
# Locate garca
GARC_PATH="$(command -v garca)" || GARC_PATH="${_self}/bin/garca"
# Check if zygote exist
test ! -e "$GETT" && echo -e "No package was set-up, run ./configure first." && exit 1
# Colors
RC='\033[0m' RED='\033[0;31m' BRED='\033[1;31m' GRAY='\033[1;30m' BLUE='\033[0;34m' BBLUE='\033[1;34m' CYAN='\033[0;34m' BCYAN='\033[1;34m' WHITE='\033[1;37m' GREEN='\033[0;32m' BGREEN='\033[1;32m' YELLOW='\033[1;33m' PURPLE='\033[0;35m' BPURPLE='\033[1;35m' ORANGE='\033[0;33m'
# Define functions
function geco() {
echo -e "$@"
}
function get_value() {
sed -n "s/^$1=//p" "$GETT" | sed -e "s|\"||g" -e "s| #.*||" 2>/dev/null
}
function update_value() {
sed -i "s|\b$1=\".*\"|$1=\"$2\"|g" "$GETT"
}
function set_type(){
test -f "$WORKDIR/$GEARLOCK_NAME/extension.sh" && TTYPE="Extension"
update_value TYPE "${TTYPE:="Package"}"
}
function show_zygote_header(){
cat << EOF
______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______
/_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/
._. ___
| | / / *Name: $NAME
|_| \ \ *Version: $VERSION
|-| < < *Author: $AUTHOR
| | / / *Type: $TYPE
|_| \_\_ *ShortDesc: $SHORTDESC
______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______ ______
/_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/
EOF
}
function gen_attars(){
local zD="$WORKDIR"/'.!zygote'
local fM="$zD/mode" sP="$zD/.sParent"
local sT="$zD/.sTarget" sL="$zD/link"
mkdir -p "${zD:="$WORKDIR"/'.!zygote'}"
if [ -n "$(find "$WORKDIR" -type l -exec realpath {} + | sed "s|"$WORKDIR"/||" | awk '{print "\""$0"\""}')" ]; then
find "$WORKDIR" -type l -exec realpath {} + | sed "s|"$WORKDIR"/||g" | awk '{print "\""$0"\""}' | sed 's|\"/|\"|g' > "${sP}"
find "$WORKDIR" -type l -printf '"%p"\n' | sed "s|"$WORKDIR"/||g" | sed 's|\"/|\"|g' > "${sT}"
paste -d " " "$sP" "$sT" > "$sL" && rm -f "$sP" "$sT"
else
rm -f "$sL"
fi
find "$WORKDIR" -printf '%#m "%p"\n' | sed -e "s|"$WORKDIR"/||" -e "s|.*"$WORKDIR".*||" | awk 'NF' > "${fM}"
}
# Build process functions
function build_gxp(){
render_header
gen_attars
"$GARC_PATH" a '-x!readme*' ${CompMethod} ${CompRatio} $@ "$GRLOAD/${NAME}_${VERSION}_${AUTHOR}.gxp" "$WORKDIR"/* "$WORKDIR"/'.!zygote'; print_success; }
function render_header(){
clear
NAME="$(get_value NAME)"
VERSION="$(get_value VERSION)"
AUTHOR="$(get_value AUTHOR)"
TYPE="$(get_value TYPE)"
SHORTDESC="$(get_value SHORTDESC)"
test "$(get_value DEF_HEADER)" == "yes" && show_zygote_header
}
function print_success(){
if [ $? != 0 ]; then
geco "\nBuild failed ..."
else
geco "\n$TTYPE successfully build as "${NAME}"_"${VERSION}"_"${AUTHOR}".gxp and can be found at gearload dir"
test -n "$GEARLOCK_VER" && geco "You can test it through ${YELLOW}GXPM${RC} right now"
chmod -Rf 777 "$GRLOAD" 2>/dev/null
fi
:
}
function show_help(){
geco "
GearLock Development Kit
\$ Command Line Options: ./${_self} <option> <optional-compMethod> <optional-compRatio>
--nowizard Does not use wizard mode
--help, -h Print this help message
\$ Available compMethods: bzip2 bcj2 bcj ppc ia64 arm armt sparc swap2 swap4 copy deflate64 deflate delta lzma2 flzma2 lzma zstd(default) lz4
\$ Default compRatio level: 10 (Max 23)
\$ Note: It is advised not to change the compMethod
"
}
function wizard_run(){
geco "\n++ Try \`./${_self} --help\` to use the command line"
geco "\n~ Have you manually configured your ${TTYPE} properties in ${YELLOW}!zygote.sh${RC}?"
geco "~ Or do you want to go through the auto wizard?\n"
select opt in "I configured it manually" "Go through auto wizard" "Exit"
do
case "$opt" in
"I configured it manually")
geco "\nOkay"
sleep 1
clear
;;
"Go through auto wizard")
clear
# Name
read -eri "$(get_value NAME)" -p "$(geco "Enter your $TTYPE ${GREEN}Name${RC} > ")" "TNAME"
update_value NAME "$TNAME" && geco
# Codename
read -eri "$(get_value CODENAME)" -p "$(geco "Enter your $TTYPE ${GREEN}CodeName${RC} (${YELLOW}should be unique, lowercase and no special-chars${RC}) > ")" "TCODENAME"
update_value CODENAME "${TCODENAME,,}" && geco
# Version
read -eri "$(get_value VERSION)" -p "$(geco "Enter your ${GREEN}$TTYPE${RC} version > ")" "TVERSION"
update_value VERSION "$TVERSION" && geco
# Author
read -eri "$(get_value AUTHOR)" -p "$(geco "Enter your ${GREEN}Name${RC} as the owner/dev/author > ")" "TAUTHOR"
update_value AUTHOR "$TAUTHOR" && geco
# Description
read -eri "$(get_value SHORTDESC)" -p "$(geco "Enter a very short ${GREEN}Description${RC} for your $TTYPE > ")" "TSHORTDESC"
update_value SHORTDESC "$TSHORTDESC" && geco
# Reboot Request
while true; do
geco "\n~ You must require reboot if your ${TTYPE} modifies any major system files which can get it unstable duing runtime, otherwise it should be fine..."
read -rp "$(geco "Enable ${RED}Reboot-Request${RC}? [${GREEN}Y${RC}/n]") (Current Value: $(get_value REQREBOOT)) " c
case $c in
[Yy]* )
geco
select opt in "Only in android-booted mode" "Only in recovery mode" "Both android-booted + recovery mode"
do
case "$opt" in
"Only in android-booted mode")
update_value REQREBOOT "yes, no"
;;
"Only in recovery mode")
update_value REQREBOOT "no, yes"
;;
"Both android-booted + recovery mode")
update_value REQREBOOT "yes, yes"
;;
esac
break
done
break
;;
[Nn]* ) update_value REQREBOOT "no, no" && break ;;
* ) geco "\nEnter either ${GREEN}y${RC}es or no" ;;
esac
done
# Generate Uninstaller
while true; do
geco "\n~ ${GREEN}GearLock${RC} can generate an uninstallation script itself for your ${TTYPE}"
geco "~ You can even put your custom unins code in ${RED}uninstall.sh${RC} and also use auto uninstallation script by gearlock at the same time..."
geco "~ ${GREEN}GearLock${RC} will merge custom uninstallation script as needed...\n"
read -rp "$(geco "\nEnable ${RED}Auto-Uninstallation-Script Generation${RC}? [${GREEN}Y${RC}/n]") (Current Value: $(get_value GEN_UNINS)) " c
case $c in
[Yy]* ) update_value GEN_UNINS yes && break ;;
[Nn]* ) update_value GEN_UNINS no && break ;;
* ) geco "\nEnter either ${GREEN}y${RC}es or no" ;;
esac
done
# Interactive mode
while true; do
geco "\n~ Interactivity is valid if your install/uninstall operation requires inputs from the user ${BGREEN}expect Yes or No${RC}"
geco "~ You need to define this in your metadata so that GXPM can know if performing an auto/silent install/uninstall of your $TTYPE is possible"
read -rp "$(geco "\nSo, does your $TTYPE require additional interactivity? [${GREEN}Y${RC}/n]") (Current Value: $(get_value INTERACTIVE)) " c
case $c in
[Yy]* )
geco
select opt in "Only in install" "Only in uninstall" "Both install + uninstall"
do
case "$opt" in
"Only in install")
update_value INTERACTIVE "yes, no"
;;
"Only in uninstall")
update_value INTERACTIVE "no, yes"
;;
"Both install + uninstall")
update_value INTERACTIVE "yes, yes"
;;
esac
break
done
break
;;
[Nn]* ) update_value INTERACTIVE "no, no" && break ;;
* ) geco "\nEnter either ${GREEN}y${RC}es or no" ;;
esac
done
;;
"Exit")
exit 0
;;
esac
break
done
build_gxp
}
if [ -z "$1" ]; then set_type; wizard_run; else
case "$1" in
--nowizard) set_type; build_gxp ;;
--help|-h) show_help ;;
*) geco "${_self}: unknown option: $*" && show_help ;;
esac; fi