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 17 if [ $# != 6 ] 18 then 19 echo Usage: $0 BUILD_ID BUILD ROOTDEVICE DEVICE MANUFACTURER PRODUCT 20 echo Example: $0 1075408 KOT49Y mako mako lge occam 21 fi 22 23 ZIP_TYPE=target_files # ota | target_files 24 25 ZIP=$6-$ZIP_TYPE-$1.zip 26 BUILD=$2 27 28 ROOTDEVICE=$3 29 DEVICE=$4 30 MANUFACTURER=$5 31 32 cd ../$MANUFACTURER/$ROOTDEVICE/self-extractors || echo Error change dir 33 34 EXTRACT_LIST_FILENAME=extract-lists.txt 35 36 for COMPANY in `grep "[a-z|A-Z])" $EXTRACT_LIST_FILENAME | cut -f1 -d')'` 37 do 38 echo Processing files from $COMPANY 39 rm -rf tmp 40 FILEDIR=tmp/vendor/$COMPANY/$DEVICE/proprietary 41 mkdir -p $FILEDIR 42 mkdir -p tmp/vendor/$MANUFACTURER/$ROOTDEVICE 43 44 TO_EXTRACT=`sed -n -e '/'" $COMPANY"'/,/;;/ p' $EXTRACT_LIST_FILENAME | tail -n+3 | head -n-2 | sed -e 's/\\\//g'` 45 46 # Check if TO_EXTRACT list has any APK files 47 if [[ ${TO_EXTRACT} == *.apk* ]] 48 then 49 APK_MAKEFILE=${FILEDIR}/Android.mk 50 echo "LOCAL_PATH := \$(call my-dir)" > ${APK_MAKEFILE} 51 echo "" >> ${APK_MAKEFILE} 52 fi 53 54 echo \ \ Extracting files from OTA package 55 for ONE_FILE in $TO_EXTRACT 56 do 57 if test ${ZIP_TYPE} = target_files 58 then 59 ONE_FILE=`echo $ONE_FILE | sed 's/system\//SYSTEM\//g'` 60 fi 61 62 if [[ $ONE_FILE == */lib64/* ]] 63 then 64 FILEDIR_NEW=$FILEDIR/lib64 65 else 66 FILEDIR_NEW=$FILEDIR 67 fi 68 69 # apk makefile 70 if [[ ${ONE_FILE} == *.apk ]] 71 then 72 TMP_ONE_FILE_NAME=$(basename ${ONE_FILE} | sed 's/.apk//g') 73 74 echo "include \$(CLEAR_VARS)" >> ${APK_MAKEFILE} 75 76 echo "LOCAL_MODULE_SUFFIX := \$(COMMON_ANDROID_PACKAGE_SUFFIX)" >> ${APK_MAKEFILE} 77 echo "LOCAL_MODULE := ${TMP_ONE_FILE_NAME}" >> ${APK_MAKEFILE} 78 echo "LOCAL_MODULE_TAGS := optional" >> ${APK_MAKEFILE} 79 echo "LOCAL_BUILT_MODULE_STEM := package.apk" >> ${APK_MAKEFILE} 80 echo "LOCAL_MODULE_OWNER := ${COMPANY}" >> ${APK_MAKEFILE} 81 echo "LOCAL_MODULE_CLASS := APPS" >> ${APK_MAKEFILE} 82 echo "LOCAL_SRC_FILES := \$(LOCAL_MODULE).apk" >> ${APK_MAKEFILE} 83 echo "LOCAL_CERTIFICATE := PRESIGNED" >> ${APK_MAKEFILE} 84 85 if [[ ${TMP_ONE_FILE_NAME} == "LeanbackLauncher" ]] 86 then 87 echo "LOCAL_OVERRIDES_PACKAGES := Launcher2" >> ${APK_MAKEFILE} 88 fi 89 90 echo "include \$(BUILD_PREBUILT)" >> ${APK_MAKEFILE} 91 echo "" >> ${APK_MAKEFILE} 92 fi 93 94 echo \ \ \ \ Extracting $ONE_FILE 95 unzip -j -o $ZIP $ONE_FILE -d $FILEDIR_NEW> /dev/null || echo \ \ \ \ Error extracting $ONE_FILE 96 if test ${ONE_FILE,,} = system/vendor/bin/gpsd -o ${ONE_FILE,,} = system/vendor/bin/pvrsrvinit -o ${ONE_FILE,,} = system/bin/fRom 97 then 98 chmod a+x $FILEDIR_NEW/$(basename $ONE_FILE) || echo \ \ \ \ Error chmoding $ONE_FILE 99 fi 100 101 ONE_FILE_BASE=$(basename $ONE_FILE) 102 if [[ $ONE_FILE_BASE == *atmel-a432-*-shamu-p1.tdat ]] 103 then 104 ATMEL_FILE=$(ls $FILEDIR_NEW/$ONE_FILE_BASE | cut -f6 -d'/') 105 sed -i "s/$ONE_FILE_BASE/$ATMEL_FILE/" moto/staging/device-partial.mk 106 elif [[ $ONE_FILE_BASE == *atmel-a432-*-shamu.tdat ]] 107 then 108 ATMEL_FILE=$(ls $FILEDIR_NEW/$ONE_FILE_BASE | cut -f6 -d'/') 109 sed -i "s/$ONE_FILE_BASE/$ATMEL_FILE/" moto/staging/device-partial.mk 110 fi 111 112 done 113 echo \ \ Setting up $COMPANY-specific makefiles 114 cp -R $COMPANY/staging/* tmp/vendor/$COMPANY/$DEVICE || echo \ \ \ \ Error copying makefiles 115 echo \ \ Setting up shared makefiles 116 cp -R root/* tmp/vendor/$MANUFACTURER/$ROOTDEVICE || echo \ \ \ \ Error copying makefiles 117 echo \ \ Generating self-extracting script 118 SCRIPT=extract-$COMPANY-$DEVICE.sh 119 cat PROLOGUE > tmp/$SCRIPT || echo \ \ \ \ Error generating script 120 cat $COMPANY/COPYRIGHT >> tmp/$SCRIPT || echo \ \ \ \ Error generating script 121 cat PART1 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script 122 cat $COMPANY/LICENSE >> tmp/$SCRIPT || echo \ \ \ \ Error generating script 123 cat PART2 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script 124 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 125 cat PART3 >> tmp/$SCRIPT || echo \ \ \ \ Error generating script 126 (cd tmp ; tar zc --owner=root --group=root vendor/ >> $SCRIPT || echo \ \ \ \ Error generating embedded tgz) 127 chmod a+x tmp/$SCRIPT || echo \ \ \ \ Error generating script 128 ARCHIVE=$COMPANY-$DEVICE-$BUILD-$(md5sum < tmp/$SCRIPT | cut -b -8 | tr -d \\n).tgz 129 rm -f $ARCHIVE 130 echo \ \ Generating final archive 131 (cd tmp ; tar --owner=root --group=root -z -c -f ../$ARCHIVE $SCRIPT || echo \ \ \ \ Error archiving script) 132 rm -rf tmp 133 done 134