-
Notifications
You must be signed in to change notification settings - Fork 5
/
package-rename.sh
executable file
·95 lines (77 loc) · 2.13 KB
/
package-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
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
#! /bin/bash
# author: Scott Greenwald (github.com/scottgwald)
# project: WearScript
# license: Apache 2.0
# first arg is name of apk
# second arg is new trigger phrase
#
# REQUIRES:
# jar
# aapt
# jarsigner
# keystore file: debug.keystore
#
# CHECK IF COMMAND LINE ARGUMENTS ARE PRESENT
#
if [[ $# > 2 ]]
then
echo "There are "$#" command line arguments present."
else
echo "There are "$#" command line arguments present, but I need 3."
echo "Try including the name of the WearScript apk, a new trigger phrase, and package naming string."
exit
fi
#
# UNPACK AND THEN REPACK
#
export SCRIPTPATH=$( cd $(dirname $0) ; pwd -P )
java -jar $SCRIPTPATH/libs/apktool-cli.jar d -f $1
#
# CHANGE TRIGGER PHRASE
#
# replace string "wear a script" with $2 second commandline argument
export name=$1
export truncatedName=${name:0:${#name}-4}
pathToXml=$truncatedName/res/values/strings.xml
export sedCmd="sed -i .back 's/wear a script/"$2"/g' "$pathToXml
eval $sedCmd
rm $pathToXml.back
#
# CHANGE PACKAGE NAME IN MANIFEST
#
export newPackageSegment=dappervision_$3
export sedCmd="sed -i .back 's/dappervision/"$newPackageSegment"/g' "$truncatedName"/AndroidManifest.xml"
echo $sedCmd
eval $sedCmd
#
# CHANGE PACKAGE NAME IN SMALI FILES
#
# replace instances of "dappervision" with new string
export replaceCmd="find . -iname '*.smali' | xargs sed -i .back 's/dappervision/"$newPackageSegment"/g'"
eval $replaceCmd
# remove sed's backup files
find $truncatedName -iname '*.back' | xargs rm
#
# MOVE FOLDER IN SMALI DIRECTORY TREE
#
mv $truncatedName/smali/com/dappervision $truncatedName/smali/com/$newPackageSegment
#
# repack
java -jar $SCRIPTPATH/libs/apktool-cli.jar 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
export newName=$truncatedName-renamed.apk
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $SCRIPTPATH/debug.keystore $pathToNewApk android
cp $pathToNewApk $newName
#
# INSTALL NEW APK
#
adb install -r $newName