#!/bin/bash . /etc/init.d/functions.sh || exit 1 die() { eerror "$*"; exit 1; } set -e BASE="/mnt/host/source" BUILD_DIR="${BASE}/src/build" cd "${BASE}/src/scripts/" : "${BOARD:="$(cat .default_board 2>/dev/null)"}" if [[ -z ${BOARD} ]] ; then die "missing BOARD" fi IMAGES="${BASE}/src/build/images/${BOARD}" BUILD="/build/${BOARD}" usage() { exec cat < Write image to w/out prompting. -p Pretend -- show commands that would be run. -v Verbose -- send command output to stdout. EOF } find_first_removable() { local d cd /sys/block for d in sd? ; do if [[ $(cat "${d}/removable" 2>/dev/null) == "1" ]]; then echo "/dev/${d}" return 0 fi done return 0 } ARG_CLEAN=false ARG_DEV="$(find_first_removable)" ARG_DEV_USER=false ARG_PRETEND=false ARG_NOPKG=false ARG_AUTOTEST=false ARG_FACTORY=false ARG_VERBOSE=false ARG_TEST=false while [[ $# -ne 0 ]] ; do case $1 in --clean) ARG_CLEAN=true;; -p) ARG_PRETEND=true;; -Y) ARG_DEV_USER=true;; -y) shift; ARG_DEV=$1; ARG_DEV_USER=true;; -v) ARG_VERBOSE=true;; -t) ARG_TEST=true;; --nousepkg) ARG_NOPKG=true;; --autotest) ARG_AUTOTEST=true;; --factory) ARG_FACTORY=true;; -h) usage;; *) echo "unknown opt: $*"; exit 1;; esac shift done piperet() { set -- ${PIPESTATUS[@]/0}; [[ $# -eq 0 ]]; } run() { set +e if ! ${ARG_PRETEND} ; then ebegin "$*" local log="${IMAGES}"/log.${1##*/} if ${ARG_VERBOSE} ; then "$@" |& tee "${log}" else "$@" >& "${log}" fi piperet eend $? || exit $? else echo "$*" fi set -e } tfe() { ($1 && echo $2 || echo $3); } mkdir -p "${IMAGES}" rm -f "${IMAGES}"/log.* einfo "Log root: ${IMAGES}/log." run update_chroot if ${ARG_CLEAN} || [[ ! -d ${BUILD} ]] ; then run sudo rm -rf "${BUILD}" run setup_board --board=${BOARD} --skip-chroot-upgrade if [[ $? -ne 0 ]] ; then run sudo rm -rf "${BUILD}" exit 1 fi fi run cros build-packages \ --board=${BOARD} \ --nowithdebug \ --nowithrevdeps \ --skip-chroot-upgrade \ $(tfe ${ARG_AUTOTEST} --{,no-}withautotest) \ $(tfe ${ARG_FACTORY} --{,no-}withfactory) \ $(tfe ${ARG_NOPKG} --{no-,}usepkg) \ $(tfe ${ARG_TEST} --{,no-}withtest) BUILD_IMG="cros build-image --board=${BOARD} --no-enable-rootfs-verification $(tfe ${ARG_TEST} test base)" run ${BUILD_IMG} IMG_TO_USB="cros flash --yes usb://${ARG_DEV} xbuddy://local/${BOARD}/latest/dev" if ${ARG_DEV_USER} ; then run ${IMG_TO_USB} sync & fi cd "${IMAGES}" rm -rf $(ls -td1R `find -mindepth 1 -maxdepth 1 -type d` | sed -e 1d -e 2d) cat <