-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxapk
executable file
·65 lines (45 loc) · 1.47 KB
/
xapk
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
#!/bin/bash
set -euo pipefail
# Install a `.xapk` into a device.
# Dependecies:
# mktemp
# 7z
# fd
# sort
# adb
# FIX: If there are several APK files with different architectures ( i.e:
# config.arm64_v8a.apk ), make sure to check your phone's CPU architecture
# before proceeding with installing the APK.
#
# TODO: A way to select on what device to installed.
#
# TODO: Verbose flag.
# -------------------------------- Functions -------------------------------- #
Err()
{
printf "Err: %s\n" "$2" 1>&2
# shellcheck disable=2086
(($1 > 0)) && exit $1
}
# ----------------------------- Input Processing ----------------------------- #
(($# == 0)) && Err 1 "Xapk file path needed."
XapkPath=$1
[[ -r $XapkPath ]] || Err 1 "File '$XapkPath' is not readable."
# ----------------------------------- Main ----------------------------------- #
# echo "Installing '$XapkPath'."
TempFolder=$(mktemp -d)
7z x "$XapkPath" -o"$TempFolder" 1>/dev/null
readarray -t Apks <<<"$(fd -tf -e apk . "$TempFolder" | sort)"
# echo "Installing ${Apks[@]}"
adb install-multiple "${Apks[@]}"
ObbPath="$TempFolder/Android/obb"
if [[ -d $ObbPath ]]; then
# The 'com.*.apk' should always be the first entry if well packaged.
ObbAppPath="$ObbPath/${Apks[0]##*/}"
ObbAppPath="${ObbAppPath%.apk}"
StoragePath="/storage/emulated/0/Android/obb/"
# echo "obb folder found. Pushing $ObbAppPath -> $StoragePath"
adb push "$ObbAppPath" "$StoragePath"
fi
# echo "Done!!!"
rm -rf "$TempFolder"