-
Notifications
You must be signed in to change notification settings - Fork 12
/
envsetup.sh
executable file
·234 lines (193 loc) · 5.44 KB
/
envsetup.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
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
#!/bin/bash
#**************************************************#
#This shell used to export PORT_ROOT
#**************************************************#
TOPFILE=build/envsetup.sh
PROJECT_MAX_DEPTH=3
if [ -f $TOPFILE ] ; then
PORT_ROOT=$PWD
else
while [ \( ! \( -f $TOPFILE \) \) -a \( $PWD != "/" \) ]; do
cd .. > /dev/null
done
if [ -f $PWD/$TOPFILE ]; then
PORT_ROOT=$PWD
#echo "PORT: $PORT_ROOT"
else
echo "Failed! run me under you porting workspace"
return
fi
fi
if [ -n "$PORT_ROOT" ]; then
MATCH=$(echo $PATH | grep $PORT_ROOT)
if [ "$MATCH" = "" ];then
PATH=$PORT_ROOT/tools:$PATH
LD_LIBRARY_PATH=$PORT_ROOT/build/lib/:$LD_LIBRARY_PATH
export PATH LD_LIBRARY_PATH
fi
PORT_BUILD="$PORT_ROOT/build"
#echo "set port_build, PORT_BUILD:$PORT_BUILD"
export PORT_ROOT PORT_BUILD
fi
# Command "coron" complete
function __cmd_coron()
{
local cur="${COMP_WORDS[COMP_CWORD]}"
case $COMP_CWORD in
0)
;;
1)
local options="fire config newproject patchall autofix fullota upgrade clean cleanall help"
COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
;;
2)
;;
esac
}
complete -F __cmd_coron coron
function ifdir()
{
$PORT_BUILD/tools/ifdir.sh $1
}
function croot()
{
cd $PORT_ROOT
}
# setup the function to cd to the project under the smali dir
function setupCdFunction()
{
local projectName
local projectPath
local temp_sh=`mktemp -t temp.sh.XXXXXX`
local temp_info=`mktemp -t temp.info.XXXXX`
echo "#!/bin/bash \n" > $temp_sh
echo ">>> All valid projects: "
printf "name path fast_cd_command\n" >> $temp_info
for makefile in `find $PORT_ROOT/devices -maxdepth $PROJECT_MAX_DEPTH -iname "makefile"`
do
projectPath=`dirname $makefile`
projectName=`basename $projectPath`
echo -e "$projectName $projectPath c$projectName" >> $temp_info
echo "
function c$projectName()
{
cd \"$projectPath\"
}" >> $temp_sh
done
chmod a+x $temp_sh
source "$temp_sh"
cat $temp_info | column -t
rm -rf "$temp_sh"
rm -rf "$temp_info"
}
setupCdFunction
if [ -f $PORT_BUILD/custom/Makefile ]; then
cp $PORT_BUILD/custom/Makefile $PORT_ROOT
fi
SIMGTOIMG=$PORT_BUILD/tools/bin/simg2img
function unpack_systemimg()
{
local systemimg=$1
local outdir=$2
echo ">>> begin unpack $systemimg"
if [ "x$outdir" = "x" ]; then
outdir=$PWD
fi
if [ -f $systemimg ]; then
mkdir -p $outdir
if [ -x $SIMGTOIMG ]; then
tmpImg=`mktemp -t system.XXXX.img`
tmpMnt=`mktemp -dt system.XXXX.mnt`
$SIMGTOIMG $systemimg $tmpImg
sudo mount -t ext4 -o loop $tmpImg $tmpMnt
sudo cp -rf $tmpMnt/* $outdir
sudo umount $tmpMnt
rm -rf $tmpImg
rm -rf $tmpMnt
echo ">>> success unpack $systemimg to $outdir"
return 0
else
echo ">>> $SIMGTOIMG can not be execute!"
fi
else
echo ">>> $systemimg doesn't exist! "
fi
echo ">>> failed to unpack $systemimg"
return 1
}
function imgtoota()
{
local systemimg=$1
local outzip=$2
echo ">>> begin generate ota zip from $systemimg"
if [ "x$outzip" = "x" ]; then
outzip=$PWD
fi
if [ -d "$outzip" ]; then
outzip=$outzip/ota.zip
fi
outdir=`mktemp -dt ota.XXX`
unpack_systemimg $systemimg $outdir
if [ $? = "0" ]; then
echo ">>> begin zip $outdir to $outzip"
cd $outdir
sudo zip ota.zip * -q -r -y
cd -
mv $outdir/ota.zip $outzip
echo ">>> genera ota zip: $outzip"
return 0
else
echo ">>> unpack $systemimg failed! "
rm -rf $outdir
return 1
fi
}
SIGN_JAR="$PORT_BUILD/tools/signapk.jar"
KEY_DIR="$PORT_BUILD/security"
TESTKEY_PEM="$KEY_DIR/testkey.x509.pem"
TESTKEY_PK="$KEY_DIR/testkey.pk8"
function sign()
{
apkName=$1
if [ $# = "0" ];then
echo ">>> usage: sign XXX.apk"
echo " use testkey to sign XXX.apk"
return
fi
if [ ! -f $apkName ];then
echo ">>> $apkName doesn't exist!"
return
fi
echo ">>> use \"testkey\" to sign $apkName"
rm -rf $apkName.signed $apkName.signed.aligned
zip -d $apkName "META-INF/*" 2>&1 > /dev/null
java -jar $SIGN_JAR $TESTKEY_PEM $TESTKEY_PK $apkName $apkName.signed
echo ">>> signed out: $apkName.signed"
zipalign 4 $apkName.signed $apkName.signed.aligned
echo ">>> zipalign out: $apkName.signed.aligned"
}
function sign_key()
{
keyType=$1
apkName=$2
if [ $# = "0" ];then
echo ">>> usage: sign_key platform/media/share/testkey/releasekey XXX.apk"
echo " used to sign XXX.apk"
return
fi
if [ ! -f "$apkName" ];then
echo ">>> $apkName doesn't exist!"
return
fi
if [ ! -f "$KEY_DIR/$keyType.x509.pem" ] || [ ! -f "$KEY_DIR/$keyType.pk8" ];then
echo ">>> \"$keyType\" key doesn't exist!"
return
fi
echo ">>> use \"$keyType\" to sign $apkName"
rm -rf $apkName.signed $apkName.signed.aligned
zip -d $apkName "META-INF/*" 2>&1 > /dev/null
java -jar $SIGN_JAR "$KEY_DIR/$keyType.x509.pem" "$KEY_DIR/$keyType.pk8" $apkName $apkName.signed
echo ">>> signed out: $apkName.signed"
zipalign 4 $apkName.signed $apkName.signed.aligned
echo ">>> zipalign out: $apkName.signed.aligned"
}