-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsideload
executable file
·270 lines (165 loc) · 6.36 KB
/
sideload
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
#!/bin/bash
source sideloader-config
#intro
osCheck
#versionCheck
packageCheck
while test $# -gt 0; do
case "$1" in
--nogui)
NOGUIFLAG=--nogui
NOGUI=1
shift
;;
*)
break
;;
esac
done
if [ $# -eq 0 ]; then
echo "No arguments supplied"
exit
else
APKNAME=$1
fi
clearLog
[[ ! -f $APKNAME ]] && error "$APKNAME is not a valid path to an apk" || ok "APK selected: $APKNAME"
#start
if [ $OSTYPE == "mac" ]; then
if ! command -v aapt &> /dev/null; then
warning "PLEASE INSTALL aapt from androidaapt.com, WE WILL JUST DOWNLOAD LOCALLY FOR NOW, NO WORRIES !"
info "DOWNLOADING https://raw.githubusercontent.com/whitewhidow/quest-sideloader-linux/main/mac_aapt_lib/aapt"
curl -s https://raw.githubusercontent.com/whitewhidow/quest-sideloader-linux/main/mac_aapt_lib/aapt -o aapt
chmod +x ./aapt
AAPT="./aapt"
warning "PLEASE INSTALL aapt from androidaapt.com to avoid this download in the future !!"
fi
fi
#device test
deviceCheck
#aapt test and packagename setup
if ([[ "$PWD" == *"/tmp/"* ]] || [[ "$PWD" == *"ftp:host"* ]]); then
MOUNTCOPY=1
info "MOUNT DETECTED, WILL COPY APK TO TEMP DIR, TO SUCCESSFULLY RUN AAPT AGAINST IT."
pv "$APKNAME" > "/tmp/$APKNAME"
PACKAGENAME=$($AAPT dump badging "/tmp/$APKNAME" | grep package:\ name | awk '/package/{gsub("name=|'"'"'",""); print $2}') || echo "DUMP FAILED"
PACKAGEVERSION=$($AAPT dump badging "/tmp/$APKNAME" | grep versionCode= | sed -E "s/.*Code='(.*)' version.*/\1/")
#rm "/tmp/$APKNAME"
else
PACKAGENAME=$($AAPT dump badging "$APKNAME" | grep package:\ name | awk '/package/{gsub("name=|'"'"'",""); print $2}')
PACKAGEVERSION=$($AAPT dump badging "$APKNAME" | grep versionCode= | sed -E "s/.*Code='(.*)' version.*/\1/")
fi
if [[ "$PACKAGENAME" == "" ]]; then
error "Package info could not be detected via aapt"
dialogLog
exit 0
fi
ok "Package info detected: $PACKAGENAME, VERSION: $PACKAGEVERSION"
#end aapt test and packagename setup
# $ADB shell dumpsys package my.package | grep versionName
#obb test
OBBCOUNT=$(find ./ -name "*.pak" -o -name "*.obb" | wc -l)
OBBLOCS=$(find ./ -name "*.pak" -o -name "*.obb" | sed 's/.\/\//.\//')
if [[ $OBBCOUNT -gt 0 ]] ; then
for file in $OBBLOCS; do
[[ ! -e $file ]] && continue
ok "OBB FOUND: $file"
done
fi
#end obb test
[ -z $CI ] && OLDVERSION=$($ADB shell dumpsys package $PACKAGENAME)
regex="versionCode=([0-9]*)"
if [[ $OLDVERSION =~ $regex ]]; then
OLDVERSION=${BASH_REMATCH[1]}
if [ "$OLDVERSION" -lt "$PACKAGEVERSION" ]; then
DIRECTION='up'
fi
if [ "$OLDVERSION" -gt "$PACKAGEVERSION" ]; then
DIRECTION='down'
fi
if [ "$OLDVERSION" == "$PACKAGEVERSION" ]; then
DIRECTION='same'
fi
else
DIRECTION='none'
fi
#versionName=1.3.6.3 | cut -c 13-
#ask verification
#printf "\n"
#echo -e "${BLUE}"
if [ "$DIRECTION" == 'up' ]; then
LINE="YOU ARE ABOUT TO UPGRADE: [$PACKAGENAME] \n\nFROM VERSION [$OLDVERSION] TO VERSION [$PACKAGEVERSION] \n\nAND COPY $OBBCOUNT OBB/PAK FILES ONTO [$DEVICE] !"
fi
if [ "$DIRECTION" == 'down' ]; then
LINE="YOU ARE ABOUT TO DOWNGRADE: [$PACKAGENAME]\n\nFROM VERSION [$OLDVERSION] TO VERSION [$PACKAGEVERSION] \n\nAND COPY $OBBCOUNT OBB/PAK FILES ONTO [$DEVICE] !"
fi
if [ "$DIRECTION" == 'same' ]; then
LINE="YOU ARE ABOUT TO REINSTALL VERSION [$OLDVERSION] OF [$PACKAGENAME] \n\nAND COPY $OBBCOUNT OBB/PAK FILES ONTO [$DEVICE] !"
fi
if [ "$DIRECTION" == 'none' ]; then
LINE="YOU ARE ABOUT TO INSTALL: [$PACKAGENAME] VERSION [$PACKAGEVERSION] \n\nAND COPY $OBBCOUNT OBB /PAKFILES ONTO [$DEVICE] !"
fi
#echo -e "${GREEN}$LINE\n\n"
dialog --title "Continue?" --yesno "$LINE \nVERIFY THE ABOVE INFO, AND CONFIRM THAT YOU WANT TO PROCEED" 0 0
if [ "$?" == 0 ]; then
echo -ne ''
else
info "Action was canceled by user"
dialogLog
exit 0
fi
#read -p "VERIFY THE ABOVE INFO, AND CLICK ANY KEY TO CONINUE, or CTRL+C to Cancel"
echo ''
printf "\n"
printf "\n"
info "(Re)Installing $PACKAGENAME, (please wait)"
dialog --title "Remove save and cache data?" --yesno "Should we also clear any possible cache and savedata for this package?" 0 0
if [ "$?" == 0 ]; then
[ -z $CI ] && [ -z $LOCAL ] && $ADB uninstall "$PACKAGENAME" > /dev/null
else
[ -z $CI ] && [ -z $LOCAL ] && $ADB uninstall -k "$PACKAGENAME" > /dev/null
fi
[ -z $CI ] && [ -z $LOCAL ] && $ADB install -g -d "$APKNAME" > /dev/null
ok "(Re)Installed $PACKAGENAME"
#uninstall and install
#copy and move obb
for file in $OBBLOCS; do
[[ ! -e $file ]] && continue # continue, if file does not exist
HASOBBS=true
file=$(echo "$file" | sed 's/.\/\//.\//')
OBBFILE=$(echo "$file" | cut -c 3-)
OBBNAME=$(echo $OBBFILE | awk -F'/' '{print $2}')
OBBNAME=${OBBNAME#/}
OBBFILE=${OBBFILE#/}
OBBFILENAME=$(echo "$OBBFILE" | sed 's:.*/::' | sed 's/.\/\//.\//')
info "Removing old OBB file: $OBBFILE (in case previously installed)"
[ -z $CI ] && [ -z $LOCAL ] && $ADB shell rm -r $STORAGE/obb/$PACKAGENAME 2> /dev/null
[ -z $CI ] && [ -z $LOCAL ] && $ADB shell rm -r $STORAGE/Android/obb/$PACKAGENAME 2> /dev/null
ok "Removed old OBB file: $OBBFILE"
info "Pushing new OBB file: $OBBFILE to $STORAGE/Download/obb/$PACKAGENAME"
#echo "PACKAGENAME:$PACKAGENAME"
#echo "OBBFILE:$OBBFILE"
#echo "OBBFILENAME:$OBBFILENAME"
if ([[ "$PWD" == *"/tmp/"* ]] || [[ "$PWD" == *"ftp:host"* ]]); then
info "MOUNT DETECTED, WILL COPY OBB TO TEMP DIR, TO SUCCESSFULLY COPY TO HMD."
pv "$OBBFILE" > "/tmp/$OBBFILENAME"
$ADB push "/tmp/$OBBFILENAME" $STORAGE/Download/obb/$PACKAGENAME/$OBBFILENAME
rm "/tmp/$OBBFILENAME"
else
[ -z $CI ] && [ -z $LOCAL ] && $ADB push "$OBBFILE" $STORAGE/Download/obb/$PACKAGENAME/$OBBFILENAME
fi
ok "Pushed new OBB file: $OBBFILE"
done
if [[ $HASOBBS == true ]] ; then
info "Moving OBB files to correct directory: $STORAGE/Android/obb/$PACKAGENAME, please be patient, this step has no progress indicator"
#echo "$ADB shell mv $STORAGE/Download/obb/$PACKAGENAME/ $STORAGE/Android/obb/$PACKAGENAME/"
[ -z $CI ] && $ADB shell mv $STORAGE/Download/obb/$PACKAGENAME/ $STORAGE/Android/obb/$PACKAGENAME/
info "Moved OBB files to correct directory"
fi
#end copy and move obb
ok ""
ok "APK Installed and $OBBCOUNT OBB files copied."
ok "Prompting settings."
ok ""
ok "DONE, sideload process finished"
dialogLog