#!/bin/sh -xe # clean set_var () { echo ==== Init ==== BASE_DIR=`pwd` echo $BASE_DIR PKG_DIR=$BASE_DIR/EMUL_PKG PKG_BIN_DIR=$PKG_DIR/data/tools/emulator SWAP_IMG_NAME="swap.img" SWAP_DIR=$PKG_BIN_DIR/storages/swap mkdir -p $PKG_BIN_DIR/storages/sdcard mkdir -p $SWAP_DIR } create_sdcard_image () { echo ==== Start creating sdcard image ==== cd $PKG_BIN_DIR/storages/sdcard for size in 4 8 16 32 do echo "make sdcard_${size}G image" ${ROOTDIR}/tools/emulator/bin/qemu-img create -f raw raw_${size}G.img ${size}G mkfs.ext4 -F raw_${size}G.img ${ROOTDIR}/tools/emulator/bin/qemu-img convert -O qcow2 raw_${size}G.img sdcard_ext4_${size}G.img rm raw_${size}G.img done echo ==== Finish creating sdcard image ==== } check_swap_image () { echo ==== Start checking swap image ==== if [ -f ${BASE_DIR}/${SWAP_IMG_NAME} ] then cp "${BASE_DIR}/${SWAP_IMG_NAME}" "${SWAP_DIR}/${SWAP_IMG_NAME}" else echo "CAUTION!! There's no ${SWAP_IMG_NAME} file." echo "Packaging is failed." exit 1; fi echo ==== Finish checking swap image ==== } set_var clean() { echo "$SRCDIR" rm -rf $PKG_DIR rm -rf $BASE_DIR/*.zip rm -rf $BASE_DIR/package/emulator-storages.package.$TARGET_OS } # build build() { if test ! -e "${ROOTDIR}/tools/emulator/bin/qemu-img" then echo "qemu-img tools does not exist.\n" exit 1 fi create_sdcard_image check_swap_image } # install install() { mkdir -p $SRCDIR/package/emulator-storages.package.$TARGET_OS mv $PKG_DIR/* $SRCDIR/package/emulator-storages.package.$TARGET_OS/ } [ "$1" = "clean" ] && clean [ "$1" = "build" ] && build [ "$1" = "install" ] && install echo "success"