-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-packages.sh
executable file
·184 lines (158 loc) · 7.25 KB
/
generate-packages.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
#!/bin/sh
# Copyright 2012 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ $# != 6 ]
then
echo Usage: $0 BUILD_ID BUILD ROOTDEVICE DEVICE MANUFACTURER PRODUCT
echo Example: $0 1075408 KOT49Y mako mako lge occam
fi
ZIP_TYPE=target_files # ota | target_files
ZIP=$6-$ZIP_TYPE-$1.zip
BUILD=$2
ROOTDEVICE=$3
DEVICE=$4
MANUFACTURER=$5
cd ../$MANUFACTURER/$ROOTDEVICE/self-extractors || echo Error change dir
EXTRACT_LIST_FILENAME=extract-lists.txt
for COMPANY in `grep "[a-z|A-Z])" $EXTRACT_LIST_FILENAME | cut -f1 -d')'`
do
echo Processing files from $COMPANY
rm -rf tmp
FILEDIR=tmp/vendor/$COMPANY/$DEVICE/proprietary
MAKEFILEDIR=tmp/vendor/$COMPANY/$DEVICE/
FILEDIR_ROOT=tmp/vendor/$MANUFACTURER/$ROOTDEVICE
case ${ROOTDEVICE} in
hikey960)
FILEDIR=tmp/vendor/linaro/$DEVICE/$COMPANY/proprietary
MAKEFILEDIR=tmp/vendor/linaro/$DEVICE/$COMPANY ;;
*)
FILEDIR_ROOT=tmp/vendor/${MANUFACTURER}_devices/$ROOTDEVICE ;;
esac
mkdir -p ${FILEDIR}
mkdir -p ${FILEDIR_ROOT}
TO_EXTRACT=`sed -n -e '/'" $COMPANY"'/,/;;/ p' $EXTRACT_LIST_FILENAME | tail -n+3 | head -n-2 | sed -e 's/\\\//g'`
echo \ \ Extracting files from OTA package
for ONE_FILE in $TO_EXTRACT
do
if test ${ZIP_TYPE} = target_files
then
ONE_FILE=`echo $ONE_FILE | sed -e 's/system\//SYSTEM\//g' -e 's/system_ext\//SYSTEM_EXT\//g' -e 's/product\//PRODUCT\//g'`
fi
if [[ $ONE_FILE == */lib64/* ]]
then
FILEDIR_NEW=$FILEDIR/lib64
elif [[ $ONE_FILE == */arm64/* ]]
then
FILEDIR_NEW=$FILEDIR/arm64
elif [[ $ONE_FILE == */arm/nb/* ]]
then
FILEDIR_NEW=$FILEDIR/armnb
else
FILEDIR_NEW=$FILEDIR
fi
echo \ \ \ \ Extracting $ONE_FILE
unzip -j -o $ZIP $ONE_FILE -d $FILEDIR_NEW> /dev/null || echo \ \ \ \ Error extracting $ONE_FILE
if test ${ONE_FILE,,} = system/vendor/bin/gpsd -o ${ONE_FILE,,} = system/vendor/bin/pvrsrvinit -o ${ONE_FILE,,} = system/bin/fRom
then
chmod a+x $FILEDIR_NEW/$(basename $ONE_FILE) || echo \ \ \ \ Error chmoding $ONE_FILE
fi
ONE_FILE_BASE=$(basename $ONE_FILE)
# Quick check to make sure apk or jar files are not stripped
if [[ ${ONE_FILE_BASE} == *.apk ]] || [[ ${ONE_FILE_BASE} == *.jar ]]
then
zipinfo ${FILEDIR_NEW}/${ONE_FILE_BASE} | grep -q classes.dex > /dev/null
if [[ $? != "0" ]]
then
echo "Error ${ONE_FILE} is stripped"
fi
fi
done
echo \ \ Copying $COMPANY-specific LICENSE
cp $COMPANY/COPYRIGHT ${MAKEFILEDIR} || echo \ \ \ \ Error copying COPYRIGHT
cp $COMPANY/LICENSE ${MAKEFILEDIR} || echo \ \ \ \ Error copying LICENSE
echo \ \ Setting up $COMPANY-specific makefiles
cp -R $COMPANY/staging/* $MAKEFILEDIR || echo \ \ \ \ Error copying makefiles
echo \ \ Setting up shared makefiles
unzip -j -o $ZIP OTA/android-info.txt -d root > /dev/null || echo \ \ \ \ Error extracting OTA/android-info.txt
cp -R root/* ${FILEDIR_ROOT} || echo \ \ \ \ Error copying makefiles
if [[ ${ROOTDEVICE} == sailfish ]]
then
FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/marlin
mkdir -p ${FILEDIR_ROOT_SHARE}
# sailfish shares BoardConfigVendor.mk with its bro' marlin
mv ${FILEDIR_ROOT}/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
# Move device-vendor-sailfish.mk under marlin directory so that it can be
# inherited by device/google/marlin/aosp_sailfish.mk
mv ${FILEDIR_ROOT}/device-vendor-sailfish.mk ${FILEDIR_ROOT_SHARE}
elif [[ ${ROOTDEVICE} == walleye ]]
then
FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/muskie/proprietary
mkdir -p ${FILEDIR_ROOT_SHARE}
# walleye shares BoardConfigVendor.mk with its sis' muskie
mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
# Move device-vendor-walleye.mk under muskie directory so that it can be
# inherited by device/google/muskie/aosp_walleye.mk
mv ${FILEDIR_ROOT}/proprietary/device-vendor-walleye.mk ${FILEDIR_ROOT_SHARE}
elif [[ ${ROOTDEVICE} == blueline ]]
then
FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/crosshatch/proprietary
mkdir -p ${FILEDIR_ROOT_SHARE}
# blueline shares BoardConfigVendor.mk with its neph' crosshatch
mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
# Move device-vendor-blueline.mk under crosshatch directory so that it can
# be inherited by device/google/crosshatch/aosp_blueline.mk
mv ${FILEDIR_ROOT}/proprietary/device-vendor.mk ${FILEDIR_ROOT_SHARE}
elif [[ ${ROOTDEVICE} == sargo ]]
then
FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/bonito/proprietary
mkdir -p ${FILEDIR_ROOT_SHARE}
# sargo shares BoardConfigVendor.mk with its bro-in-law' bonito
mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
# Move device-vendor-sargo.mk under bonito directory so that it can
# be inherited by device/google/bonito/aosp_sargo.mk
mv ${FILEDIR_ROOT}/proprietary/device-vendor.mk ${FILEDIR_ROOT_SHARE}
elif [[ ${ROOTDEVICE} == flame ]]
then
FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/coral/proprietary
mkdir -p ${FILEDIR_ROOT_SHARE}
# flame shares BoardConfigVendor.mk with its sis-in-law' coral
mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
# Move device-vendor-flame.mk under coral directory so that it can
# be inherited by device/google/coral/aosp_flame.mk
mv ${FILEDIR_ROOT}/proprietary/device-vendor.mk ${FILEDIR_ROOT_SHARE}
fi
if [[ -e "${MAKEFILEDIR}/Android.mk" ]]
then
mv ${MAKEFILEDIR}/Android.mk ${FILEDIR}/
fi
if [[ -e "${MAKEFILEDIR}/Android.bp.txt" ]]; then
mv "${MAKEFILEDIR}/Android.bp.txt" "${FILEDIR}/Android.bp"
fi
echo \ \ Generating self-extracting script
SCRIPT=extract-$COMPANY-$DEVICE.sh
cat PROLOGUE > tmp/$SCRIPT || echo \ \ \ \ Error generating script
cat $COMPANY/COPYRIGHT >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
cat PART1 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
cat $COMPANY/LICENSE >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
cat PART2 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
echo tail -n +$(expr 2 + $(cat PROLOGUE $COMPANY/COPYRIGHT PART1 $COMPANY/LICENSE PART2 PART3 | wc -l)) \$0 \| tar zxv >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
cat PART3 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
(cd tmp ; tar zc --owner=root --group=root vendor/ >> $SCRIPT || echo \ \ \ \ Error generating embedded tgz)
chmod a+x tmp/$SCRIPT || echo \ \ \ \ Error generating script
ARCHIVE=$COMPANY-$DEVICE-$BUILD-$(sha256sum < tmp/$SCRIPT | cut -b -8 | tr -d \\n).tgz
rm -f $ARCHIVE
echo \ \ Generating final archive
(cd tmp ; tar --owner=root --group=root -z -c -f ../$ARCHIVE $SCRIPT || echo \ \ \ \ Error archiving script)
rm -rf tmp
done