-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtrigger-rename.sh
executable file
·63 lines (52 loc) · 1.3 KB
/
trigger-rename.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
#! /bin/bash
# first arg is name of apk
# second arg is new trigger phrase
#
# REQUIRES:
# apktool
# aapt
# jarsigner
# keystore file: debug.keystore
#
# CHECK IF COMMAND LINE ARGUMENTS ARE PRESENT
#
if [[ $# > 1 ]]
then
echo "There are "$#" command line arguments present."
else
echo "There are "$#" command line arguments present, but I need 2."
echo "Try including the name of the WearScript apk and a new trigger phrase."
exit
fi
#
# UNPACK AND THEN REPACK
#
export name=$1
export truncatedName=${name:0:${#name}-4}
apktool d -f $name
# replace string "wear a script" with $2 second commandline argument
pathToXml=$truncatedName/res/values/strings.xml
tmp="tmp.xml"
export sedCmd="sed -i .back 's/wear a script/"$2"/g' "$pathToXml
eval $sedCmd
rm $pathToXml.back
# repack
apktool b $truncatedName
#
# VERIFY THE FILE WAS THERE AND IS NEW
#
export pathToNewApk=$truncatedName/dist/$name
echo "Details of new apk: "
echo `ls -l $pathToNewApk`
#
# SIGN THE RESULTING FILE
#
# debug.keystore is file, assumed to be in current directory
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore debug.keystore $pathToNewApk android
cp $pathToNewApk $name
#
# UNINSTALL DIFFERENTLY-SIGNED APK, INSTALL NEW ONE
#
adb uninstall com.dappervision.wearscript
adb install -r $name
echo `which aapt`