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 -e 's/system\//SYSTEM\//g' -e 's/system_ext\//SYSTEM_EXT\//g' -e 's/product\//PRODUCT\//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/COPYRIGHT ${MAKEFILEDIR} || echo \ \ \ \ Error copying COPYRIGHT
100  cp $COMPANY/LICENSE ${MAKEFILEDIR} || echo \ \ \ \ Error copying LICENSE
101  echo \ \ Setting up $COMPANY-specific makefiles
102  cp -R $COMPANY/staging/* $MAKEFILEDIR || echo \ \ \ \ Error copying makefiles
103  echo \ \ Setting up shared makefiles
104  unzip -j -o $ZIP OTA/android-info.txt -d root > /dev/null || echo \ \ \ \ Error extracting OTA/android-info.txt
105  cp -R root/* ${FILEDIR_ROOT} || echo \ \ \ \ Error copying makefiles
106
107  if [[ ${ROOTDEVICE} == sailfish ]]
108  then
109    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/marlin
110    mkdir -p ${FILEDIR_ROOT_SHARE}
111
112    # sailfish shares BoardConfigVendor.mk with its bro' marlin
113    mv ${FILEDIR_ROOT}/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
114    # Move device-vendor-sailfish.mk under marlin directory so that it can be
115    # inherited by device/google/marlin/aosp_sailfish.mk
116    mv ${FILEDIR_ROOT}/device-vendor-sailfish.mk ${FILEDIR_ROOT_SHARE}
117  elif [[ ${ROOTDEVICE} == walleye ]]
118  then
119    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/muskie/proprietary
120    mkdir -p ${FILEDIR_ROOT_SHARE}
121
122    # walleye shares BoardConfigVendor.mk with its sis' muskie
123    mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
124    # Move device-vendor-walleye.mk under muskie directory so that it can be
125    # inherited by device/google/muskie/aosp_walleye.mk
126    mv ${FILEDIR_ROOT}/proprietary/device-vendor-walleye.mk ${FILEDIR_ROOT_SHARE}
127  elif [[ ${ROOTDEVICE} == blueline ]]
128  then
129    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/crosshatch/proprietary
130    mkdir -p ${FILEDIR_ROOT_SHARE}
131
132    # blueline shares BoardConfigVendor.mk with its neph' crosshatch
133    mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
134    # Move device-vendor-blueline.mk under crosshatch directory so that it can
135    # be inherited by device/google/crosshatch/aosp_blueline.mk
136    mv ${FILEDIR_ROOT}/proprietary/device-vendor.mk ${FILEDIR_ROOT_SHARE}
137  elif [[ ${ROOTDEVICE} == sargo ]]
138  then
139    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/bonito/proprietary
140    mkdir -p ${FILEDIR_ROOT_SHARE}
141
142    # sargo shares BoardConfigVendor.mk with its bro-in-law' bonito
143    mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
144    # Move device-vendor-sargo.mk under bonito directory so that it can
145    # be inherited by device/google/bonito/aosp_sargo.mk
146    mv ${FILEDIR_ROOT}/proprietary/device-vendor.mk ${FILEDIR_ROOT_SHARE}
147  elif [[ ${ROOTDEVICE} == flame ]]
148  then
149    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/coral/proprietary
150    mkdir -p ${FILEDIR_ROOT_SHARE}
151
152    # flame shares BoardConfigVendor.mk with its sis-in-law' coral
153    mv ${FILEDIR_ROOT}/proprietary/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
154    # Move device-vendor-flame.mk under coral directory so that it can
155    # be inherited by device/google/coral/aosp_flame.mk
156    mv ${FILEDIR_ROOT}/proprietary/device-vendor.mk ${FILEDIR_ROOT_SHARE}
157  fi
158
159  if [[ -e "${MAKEFILEDIR}/Android.mk" ]]
160  then
161    mv ${MAKEFILEDIR}/Android.mk ${FILEDIR}/
162  fi
163
164  if [[ -e "${MAKEFILEDIR}/Android.bp.txt" ]]; then
165    mv "${MAKEFILEDIR}/Android.bp.txt" "${FILEDIR}/Android.bp"
166  fi
167
168  echo \ \ Generating self-extracting script
169  SCRIPT=extract-$COMPANY-$DEVICE.sh
170  cat PROLOGUE > tmp/$SCRIPT || echo \ \ \ \ Error generating script
171  cat $COMPANY/COPYRIGHT >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
172  cat PART1 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
173  cat $COMPANY/LICENSE >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
174  cat PART2 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
175  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
176  cat PART3 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
177  (cd tmp ; tar zc --owner=root --group=root vendor/ >> $SCRIPT || echo \ \ \ \ Error generating embedded tgz)
178  chmod a+x tmp/$SCRIPT || echo \ \ \ \ Error generating script
179  ARCHIVE=$COMPANY-$DEVICE-$BUILD-$(sha256sum < tmp/$SCRIPT | cut -b -8 | tr -d \\n).tgz
180  rm -f $ARCHIVE
181  echo \ \ Generating final archive
182  (cd tmp ; tar --owner=root --group=root -z -c -f ../$ARCHIVE $SCRIPT || echo \ \ \ \ Error archiving script)
183  rm -rf tmp
184done
185