1 #!/bin/bash 2 3 function replace() 4 { 5 echo replacing $1 6 rm $V -rf "$UNZIPPED_BASE_DIR"/$1 7 cp $V -rf "$UNZIPPED_IMAGE_DIR"/$1 "$UNZIPPED_BASE_DIR"/$1 8 } 9 10 V="" 11 Q="-q" 12 if [ "$1" == "-v" ]; then 13 V="-v" 14 Q="" 15 shift 16 fi 17 18 NOZIP="" 19 if [ "$1" == "-nozip" ]; then 20 NOZIP="1" 21 shift 22 fi 23 24 BASE="$1" 25 IMAGES="$2" 26 OUTPUT="$3" 27 28 if [[ -z "$BASE" || -z "$IMAGES" || -z "$OUTPUT" ]] ; then 29 echo "usage: combine_sdks.sh [-v] [-nozip] BASE IMAGES OUTPUT" 30 echo 31 echo " BASE and IMAGES should be sdk zip files. The system image files," 32 echo " emulator and other runtime files will be copied from IMAGES and" 33 echo " everything else will be copied from BASE. All of this will be" 34 echo " bundled into OUTPUT and zipped up again (unless -nozip is specified)." 35 echo 36 exit 1 37 fi 38 39 TMP=$(mktemp -d) 40 41 TMP_ZIP=tmp.zip 42 43 # determine executable extension 44 case `uname -s` in 45 *_NT-*) # for Windows 46 EXE=.exe 47 ;; 48 *) 49 EXE= 50 ;; 51 esac 52 53 BASE_DIR="$TMP"/base 54 IMAGES_DIR="$TMP"/images 55 OUTPUT_TMP_ZIP="$BASE_DIR/$TMP_ZIP" 56 57 unzip $Q "$BASE" -d "$BASE_DIR" 58 unzip $Q "$IMAGES" -d "$IMAGES_DIR" 59 60 UNZIPPED_BASE_DIR=$(echo "$BASE_DIR"/*) 61 UNZIPPED_IMAGE_DIR=$(echo "$IMAGES_DIR"/*) 62 63 # 64 # The commands to copy over the files that we want 65 # 66 67 # replace tools/emulator # at this time we do not want the exe from SDK1.x 68 replace tools/lib/images 69 replace tools/lib/res 70 replace tools/lib/fonts 71 replace tools/lib/layoutlib.jar 72 replace docs 73 replace android.jar 74 75 for i in widgets categories broadcast_actions service_actions; do 76 replace tools/lib/$i.txt 77 done 78 79 if [ -d "$UNZIPPED_BASE_DIR"/usb_driver ]; then 80 replace usb_driver 81 fi 82 83 # 84 # end 85 # 86 87 if [ -z "$NOZIP" ]; then 88 pushd "$BASE_DIR" &> /dev/null 89 # rename the directory to the leaf minus the .zip of OUTPUT 90 LEAF=$(echo "$OUTPUT" | sed -e "s:.*\.zip/::" | sed -e "s:.zip$::") 91 mv * "$LEAF" 92 # zip it 93 zip $V -qr "$TMP_ZIP" "$LEAF" 94 popd &> /dev/null 95 96 cp $V "$OUTPUT_TMP_ZIP" "$OUTPUT" 97 echo "Combined SDK available at $OUTPUT" 98 else 99 OUT_DIR="${OUTPUT//.zip/}" 100 mv $V "$BASE_DIR"/* "$OUT_DIR" 101 echo "Unzipped combined SDK available at $OUT_DIR" 102 fi 103 104 rm $V -rf "$TMP" 105 106