1#!/bin/sh
2
3# Copyright 2012 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17if [ $# != 6 ]
18then
19  echo Usage: $0 BUILD_ID BUILD ROOTDEVICE DEVICE MANUFACTURER PRODUCT
20  echo Example: $0 1075408 KOT49Y mako mako lge occam
21fi
22
23ZIP_TYPE=target_files  # ota | target_files
24
25ZIP=$6-$ZIP_TYPE-$1.zip
26BUILD=$2
27
28ROOTDEVICE=$3
29DEVICE=$4
30MANUFACTURER=$5
31
32cd ../$MANUFACTURER/$ROOTDEVICE/self-extractors || echo Error change dir
33
34EXTRACT_LIST_FILENAME=extract-lists.txt
35
36for COMPANY in `grep "[a-z|A-Z])" $EXTRACT_LIST_FILENAME | cut -f1 -d')'`
37do
38  echo Processing files from $COMPANY
39  rm -rf tmp
40  FILEDIR=tmp/vendor/$COMPANY/$DEVICE/proprietary
41  MAKEFILEDIR=tmp/vendor/$COMPANY/$DEVICE/
42  FILEDIR_ROOT=tmp/vendor/$MANUFACTURER/$ROOTDEVICE
43
44  case ${ROOTDEVICE} in
45    hikey960)
46      FILEDIR=tmp/vendor/linaro/$DEVICE/$COMPANY/proprietary
47      MAKEFILEDIR=tmp/vendor/linaro/$DEVICE/$COMPANY ;;
48    *)
49      FILEDIR_ROOT=tmp/vendor/${MANUFACTURER}_devices/$ROOTDEVICE ;;
50  esac
51
52  mkdir -p ${FILEDIR}
53  mkdir -p ${FILEDIR_ROOT}
54
55  TO_EXTRACT=`sed -n -e '/'"  $COMPANY"'/,/;;/ p' $EXTRACT_LIST_FILENAME | tail -n+3 | head -n-2 | sed -e 's/\\\//g'`
56
57  echo \ \ Extracting files from OTA package
58  for ONE_FILE in $TO_EXTRACT
59  do
60    if test ${ZIP_TYPE} = target_files
61    then
62      ONE_FILE=`echo $ONE_FILE | sed 's/system\//SYSTEM\//g'`
63    fi
64
65    if [[ $ONE_FILE == */lib64/* ]]
66    then
67      FILEDIR_NEW=$FILEDIR/lib64
68    elif [[ $ONE_FILE == */arm64/* ]]
69    then
70      FILEDIR_NEW=$FILEDIR/arm64
71    elif [[ $ONE_FILE == */arm/nb/* ]]
72    then
73      FILEDIR_NEW=$FILEDIR/armnb
74    else
75      FILEDIR_NEW=$FILEDIR
76    fi
77
78    echo \ \ \ \ Extracting $ONE_FILE
79    unzip -j -o $ZIP $ONE_FILE -d $FILEDIR_NEW> /dev/null || echo \ \ \ \ Error extracting $ONE_FILE
80    if test ${ONE_FILE,,} = system/vendor/bin/gpsd -o ${ONE_FILE,,} = system/vendor/bin/pvrsrvinit -o ${ONE_FILE,,} = system/bin/fRom
81    then
82      chmod a+x $FILEDIR_NEW/$(basename $ONE_FILE) || echo \ \ \ \ Error chmoding $ONE_FILE
83    fi
84
85    ONE_FILE_BASE=$(basename $ONE_FILE)
86
87    # Quick check to make sure apk or jar files are not stripped
88    if [[ ${ONE_FILE_BASE} == *.apk ]] || [[ ${ONE_FILE_BASE} == *.jar ]]
89    then
90      zipinfo ${FILEDIR_NEW}/${ONE_FILE_BASE} | grep -q classes.dex > /dev/null
91      if [[ $? != "0" ]]
92      then
93        echo "Error ${ONE_FILE} is stripped"
94      fi
95    fi
96
97  done
98  echo \ \ Copying $COMPANY-specific LICENSE
99  cp $COMPANY/LICENSE ${MAKEFILEDIR} || echo \ \ \ \ Error copying LICENSE
100  echo \ \ Setting up $COMPANY-specific makefiles
101  cp -R $COMPANY/staging/* $MAKEFILEDIR || echo \ \ \ \ Error copying makefiles
102  echo \ \ Setting up shared makefiles
103  unzip -j -o $ZIP OTA/android-info.txt -d root > /dev/null || echo \ \ \ \ Error extracting OTA/android-info.txt
104  cp -R root/* ${FILEDIR_ROOT} || echo \ \ \ \ Error copying makefiles
105
106  if [[ ${ROOTDEVICE} == sailfish ]]
107  then
108    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/marlin
109    mkdir -p ${FILEDIR_ROOT_SHARE}
110
111    # sailfish shares BoardConfigVendor.mk with its bro' marlin
112    mv ${FILEDIR_ROOT}/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
113    # Move device-vendor-sailfish.mk under marlin directory so that it can be
114    # inherited by device/google/marlin/aosp_sailfish.mk
115    mv ${FILEDIR_ROOT}/device-vendor-sailfish.mk ${FILEDIR_ROOT_SHARE}
116  elif [[ ${ROOTDEVICE} == walleye ]]
117  then
118    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/muskie/proprietary
119    mkdir -p ${FILEDIR_ROOT_SHARE}
120
121    # walleye shares BoardConfigVendor.mk with its sis' muskie
122    mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
123    # Move device-vendor-walleye.mk under muskie directory so that it can be
124    # inherited by device/google/muskie/aosp_walleye.mk
125    mv ${FILEDIR_ROOT}/proprietary/device-vendor-walleye.mk ${FILEDIR_ROOT_SHARE}
126  elif [[ ${ROOTDEVICE} == blueline ]]
127  then
128    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/crosshatch/proprietary
129    mkdir -p ${FILEDIR_ROOT_SHARE}
130
131    # blueline shares BoardConfigVendor.mk with its neph' crosshatch
132    mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
133    # Move device-vendor-blueline.mk under crosshatch directory so that it can
134    # be inherited by device/google/crosshatch/aosp_blueline.mk
135    mv ${FILEDIR_ROOT}/proprietary/device-vendor.mk ${FILEDIR_ROOT_SHARE}
136  elif [[ ${ROOTDEVICE} == sargo ]]
137  then
138    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/bonito/proprietary
139    mkdir -p ${FILEDIR_ROOT_SHARE}
140
141    # sargo shares BoardConfigVendor.mk with its bro-in-law' bonito
142    mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
143    # Move device-vendor-sargo.mk under bonito directory so that it can
144    # be inherited by device/google/bonito/aosp_sargo.mk
145    mv ${FILEDIR_ROOT}/proprietary/device-vendor.mk ${FILEDIR_ROOT_SHARE}
146  elif [[ ${ROOTDEVICE} == flame ]]
147  then
148    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/coral/proprietary
149    mkdir -p ${FILEDIR_ROOT_SHARE}
150
151    # flame shares BoardConfigVendor.mk with its sis-in-law' coral
152    mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
153    # Move device-vendor-flame.mk under coral directory so that it can
154    # be inherited by device/google/coral/aosp_flame.mk
155    mv ${FILEDIR_ROOT}/proprietary/device-vendor.mk ${FILEDIR_ROOT_SHARE}
156  fi
157
158  if [[ -e "${MAKEFILEDIR}/Android.mk" ]]
159  then
160    mv ${MAKEFILEDIR}/Android.mk ${FILEDIR}/
161  fi
162
163  echo \ \ Generating self-extracting script
164  SCRIPT=extract-$COMPANY-$DEVICE.sh
165  cat PROLOGUE > tmp/$SCRIPT || echo \ \ \ \ Error generating script
166  cat $COMPANY/COPYRIGHT >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
167  cat PART1 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
168  cat $COMPANY/LICENSE >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
169  cat PART2 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
170  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
171  cat PART3 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
172  (cd tmp ; tar zc --owner=root --group=root vendor/ >> $SCRIPT || echo \ \ \ \ Error generating embedded tgz)
173  chmod a+x tmp/$SCRIPT || echo \ \ \ \ Error generating script
174  ARCHIVE=$COMPANY-$DEVICE-$BUILD-$(sha256sum < tmp/$SCRIPT | cut -b -8 | tr -d \\n).tgz
175  rm -f $ARCHIVE
176  echo \ \ Generating final archive
177  (cd tmp ; tar --owner=root --group=root -z -c -f ../$ARCHIVE $SCRIPT || echo \ \ \ \ Error archiving script)
178  rm -rf tmp
179done
180