-
Notifications
You must be signed in to change notification settings - Fork 14
/
push-apk
133 lines (116 loc) · 3.32 KB
/
push-apk
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
#!/bin/bash
#set -x
REMOVE_ODEX_IF_EXISTS=false
FACTORY_RESET=false
FIND_EXISTS=false
API=$(adb shell getprop ro.build.version.sdk | tr -d '\r')
FIND=$(adb shell ls /system/ | tr -d '\015'|grep '^find$')
FULL_PATH=
ARCH=
REBOOT="reboot"
show_help()
{
echo "$0 [options] apk"
echo " options:"
echo " -d : if the odex should be removed from the system for the application (if exists)"
echo " -w : if data should be wiped in recovery when rebooting"
echo ""
}
wipedata()
{
echo "--wipe_data" > command
adb push command /data/local/tmp
adb shell su -c 'dd if=/data/local/tmp/command of=/cache/recovery/command'
adb shell su -c 'chmod 644 /cache/recovery/command'
adb reboot recovery
rm -rf command
}
get_apk_path()
{
if [ $FIND_EXISTS == true ]; then
FULL_PATH=$(find system -name $APK)
else
FULL_PATH=$(adb shell ls /system/app | grep -w $NAME | tr -d '\r')
if [ -z $FULL_PATH ]; then
FULL_PATH=$(adb shell ls /system/priv-app | grep -w $NAME | tr -d '\r')
if [ -z $FULL_PATH ]; then
FULL_PATH=$(adb shell ls /system/framework | grep -w $NAME | tr -d '\r')
if [ -z $FULL_PATH ]; then
echo "Unable to determine app's location"
echo "Please enter the full path to the directory containing the apk"
read path
FULL_PATH=$path
else
FULL_PATH=/system/framework
fi
else
if [ $API -ge 21 ]; then
FULL_PATH=/system/priv-app/$NAME
else
FULL_PATH=/system/priv-app
fi
fi
else
if [ $API -ge 21 ]; then
FULL_PATH=/system/app/$NAME
else
FULL_PATH=/system/app
fi
fi
fi
}
get_apk_arch()
{
if [ $API -ge 21 ]; then
if [ $FIND_EXISTS == true ]; then
ARCH=$(find $FULL_PATH -name arm)
else
ARCH=$(adb shell ls $FULL_PATH | grep -w arm | tr -d '\r')
if [ -z $ARCH ]; then
ARCH=$(adb shell ls $FULL_PATH | grep -w arm64 | tr -d '\r')
fi
fi
fi
}
if [ $# -eq 0 ]; then
show_help
exit 1
fi
OPTIND=1
while getopts ":dw" opt; do
case $opt in
d) REMOVE_ODEX_IF_EXISTS=true ;;
w) FACTORY_RESET=true ;;
esac
done
shift $((OPTIND-1))
APK=$1
NAME=${APK%%.*}
if [ ! -z $FIND ]; then
FIND_EXISTS=true
fi
get_apk_path
echo "---- Found apk's location at $FULL_PATH ----"
get_apk_arch
echo "---- Pushing apk to device ----"
adb push $APK /data/local/tmp
echo "---- Mounting system r/w ----"
adb shell su -c 'mount -o remount,rw /system'
echo "---- Moving app to $FULL_PATH/$APK ----"
adb shell su -c "dd if=/data/local/tmp/$APK of=$FULL_PATH/$APK"
if [ $REMOVE_ODEX_IF_EXISTS == true ]; then
echo "---- Removing odex ----"
if [ ! -z $ARCH ]; then
adb shell su -c "rm -rf $FULL_PATH/$ARCH"
else
adb shell su -c 'rm -rf $FULL_PATH/$NAME.odex'
fi
fi
echo "---- Setting permissions ----"
adb shell su -c "chmod 644 $FULL_PATH/$APK"
if [ $FACTORY_RESET == true ]; then
wipedata
REBOOT="reboot recovery"
fi
echo "---- Rebooting - ($REBOOT) ----"
adb $REBOOT