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  mkdir -p $FILEDIR
42  FILEDIR_ROOT=tmp/vendor/$MANUFACTURER/$ROOTDEVICE
43
44  case ${ROOTDEVICE} in
45    dragon|marlin|sailfish)
46      FILEDIR_ROOT=tmp/vendor/${MANUFACTURER}_devices/$ROOTDEVICE ;;
47    *) ;;
48  esac
49
50  mkdir -p ${FILEDIR_ROOT}
51
52  TO_EXTRACT=`sed -n -e '/'"  $COMPANY"'/,/;;/ p' $EXTRACT_LIST_FILENAME | tail -n+3 | head -n-2 | sed -e 's/\\\//g'`
53
54  # Check if TO_EXTRACT list has any APK files
55  if [[ ${TO_EXTRACT} == *.apk* ]]
56  then
57    APK_MAKEFILE=${FILEDIR}/Android.mk
58    echo "LOCAL_PATH := \$(call my-dir)" > ${APK_MAKEFILE}
59    echo "" >> ${APK_MAKEFILE}
60  fi
61
62  echo \ \ Extracting files from OTA package
63  for ONE_FILE in $TO_EXTRACT
64  do
65    if test ${ZIP_TYPE} = target_files
66    then
67      ONE_FILE=`echo $ONE_FILE | sed 's/system\//SYSTEM\//g'`
68    fi
69
70    if [[ $ONE_FILE == */lib64/* ]]
71    then
72      FILEDIR_NEW=$FILEDIR/lib64
73    elif [[ $ONE_FILE == */arm/nb/* ]]
74    then
75      FILEDIR_NEW=$FILEDIR/armnb
76    else
77      FILEDIR_NEW=$FILEDIR
78    fi
79
80    # apk makefile
81    if [[ ${ONE_FILE} == *.apk ]]
82    then
83      TMP_ONE_FILE_NAME=$(basename ${ONE_FILE} | sed 's/.apk//g')
84
85      echo "include \$(CLEAR_VARS)" >> ${APK_MAKEFILE}
86
87      echo "LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)" >> ${APK_MAKEFILE}
88      echo "LOCAL_MODULE := ${TMP_ONE_FILE_NAME}" >> ${APK_MAKEFILE}
89      echo "LOCAL_MODULE_TAGS := optional" >> ${APK_MAKEFILE}
90      echo "LOCAL_BUILT_MODULE_STEM := package.apk" >> ${APK_MAKEFILE}
91      echo "LOCAL_MODULE_OWNER := ${COMPANY}" >> ${APK_MAKEFILE}
92      echo "LOCAL_MODULE_CLASS := APPS" >> ${APK_MAKEFILE}
93      echo "LOCAL_SRC_FILES := \$(LOCAL_MODULE).apk" >> ${APK_MAKEFILE}
94      echo "LOCAL_CERTIFICATE := PRESIGNED" >> ${APK_MAKEFILE}
95
96      if [[ ${ONE_FILE} == *priv-app/* ]]
97      then
98        echo "LOCAL_PRIVILEGED_MODULE := true" >> ${APK_MAKEFILE}
99      fi
100
101      if [[ ${TMP_ONE_FILE_NAME} == "LeanbackLauncher" ]]
102      then
103        echo "LOCAL_OVERRIDES_PACKAGES := Launcher2" >> ${APK_MAKEFILE}
104      fi
105
106      echo "include \$(BUILD_PREBUILT)" >> ${APK_MAKEFILE}
107      echo "" >> ${APK_MAKEFILE}
108    fi
109
110    echo \ \ \ \ Extracting $ONE_FILE
111    unzip -j -o $ZIP $ONE_FILE -d $FILEDIR_NEW> /dev/null || echo \ \ \ \ Error extracting $ONE_FILE
112    if test ${ONE_FILE,,} = system/vendor/bin/gpsd -o ${ONE_FILE,,} = system/vendor/bin/pvrsrvinit -o ${ONE_FILE,,} = system/bin/fRom
113    then
114      chmod a+x $FILEDIR_NEW/$(basename $ONE_FILE) || echo \ \ \ \ Error chmoding $ONE_FILE
115    fi
116
117    ONE_FILE_BASE=$(basename $ONE_FILE)
118    if [[ $ONE_FILE_BASE == *atmel-a432-*-shamu-p1.tdat ]]
119    then
120      ATMEL_FILE=$(ls $FILEDIR_NEW/$ONE_FILE_BASE | cut -f6 -d'/')
121      sed -i "s/$ONE_FILE_BASE/$ATMEL_FILE/" moto/staging/device-partial.mk
122    elif [[ $ONE_FILE_BASE == *atmel-a432-*-shamu.tdat ]]
123    then
124      ATMEL_FILE=$(ls $FILEDIR_NEW/$ONE_FILE_BASE | cut -f6 -d'/')
125      sed -i "s/$ONE_FILE_BASE/$ATMEL_FILE/" moto/staging/device-partial.mk
126    fi
127
128  done
129  echo \ \ Setting up $COMPANY-specific makefiles
130  cp -R $COMPANY/staging/* tmp/vendor/$COMPANY/$DEVICE || echo \ \ \ \ Error copying makefiles
131  echo \ \ Setting up shared makefiles
132  unzip -j -o $ZIP OTA/android-info.txt -d root > /dev/null || echo \ \ \ \ Error extracting OTA/android-info.txt
133  cp -R root/* ${FILEDIR_ROOT} || echo \ \ \ \ Error copying makefiles
134
135  if [[ ${ROOTDEVICE} == sailfish ]]
136  then
137    FILEDIR_ROOT_SHARE=tmp/vendor/${MANUFACTURER}_devices/marlin
138    mkdir -p ${FILEDIR_ROOT_SHARE}
139
140    # sailfish shares BoardConfigVendor.mk with its bro' marlin
141    mv ${FILEDIR_ROOT}/BoardConfigVendor.mk ${FILEDIR_ROOT_SHARE}
142    # Move device-vendor-sailfish.mk under marlin directory so that it can be
143    # inherited by device/google/marlin/aosp_sailfish.mk
144    mv ${FILEDIR_ROOT}/device-vendor-sailfish.mk ${FILEDIR_ROOT_SHARE}
145  fi
146
147  echo \ \ Generating self-extracting script
148  SCRIPT=extract-$COMPANY-$DEVICE.sh
149  cat PROLOGUE > tmp/$SCRIPT || echo \ \ \ \ Error generating script
150  cat $COMPANY/COPYRIGHT >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
151  cat PART1 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
152  cat $COMPANY/LICENSE >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
153  cat PART2 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
154  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
155  cat PART3 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script
156  (cd tmp ; tar zc --owner=root --group=root vendor/ >> $SCRIPT || echo \ \ \ \ Error generating embedded tgz)
157  chmod a+x tmp/$SCRIPT || echo \ \ \ \ Error generating script
158  ARCHIVE=$COMPANY-$DEVICE-$BUILD-$(sha256sum < tmp/$SCRIPT | cut -b -8 | tr -d \\n).tgz
159  rm -f $ARCHIVE
160  echo \ \ Generating final archive
161  (cd tmp ; tar --owner=root --group=root -z -c -f ../$ARCHIVE $SCRIPT || echo \ \ \ \ Error archiving script)
162  rm -rf tmp
163done
164