]> git.wh0rd.org - home.git/blobdiff - .bin/cros-board
cros-board: update
[home.git] / .bin / cros-board
index 30603da89010153b1be3efa89d75eafc0ce4c668..228ff2c47c949e21226312bdeb1ec45deddaf887 100755 (executable)
@@ -3,31 +3,73 @@
 die() { eerror "$*"; exit 1; }
 set -e
 
-cd ${HOME}/trunk/src/scripts/
+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="${HOME}/trunk/src/build/images/${BOARD}"
+IMAGES="${BASE}/src/build/images/${BOARD}"
 BUILD="/build/${BOARD}"
 
+usage() {
+       exec cat <<EOF
+Usage: cros-board [options]
+
+Build for the board listed in \${BOARD} (current: ${BOARD}).
+Normally only builds a dev image.
+
+Options:
+  -t          Build test packages & image
+  --autotest  Build & install autotest packages.
+  --factory   Build factory packages & image.
+  --nousepkg  Force build from source.
+
+  --clean     ?
+
+  -Y          Write image to ${ARG_DEV} w/out prompting.
+  -y <dev>    Write image to <dev> 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="/dev/sdc"
+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
@@ -47,7 +89,7 @@ run() {
                piperet
                eend $? || exit $?
        else
-               einfo "$*"
+               echo "$*"
        fi
        set -e
 }
@@ -59,28 +101,30 @@ rm -f "${IMAGES}"/log.*
 
 einfo "Log root: ${IMAGES}/log."
 
-run ./update_chroot
+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 setup_board --board=${BOARD} --skip-chroot-upgrade
+       if [[ $? -ne 0 ]] ; then
                run sudo rm -rf "${BUILD}"
                exit 1
        fi
 fi
 
-run ./build_packages \
+run cros build-packages \
        --board=${BOARD} \
        --nowithdebug \
-       --skip_chroot_upgrade \
-       $(tfe ${ARG_AUTOTEST} --{,no}withautotest) \
-       $(tfe ${ARG_NOPKG} --{no,}usepkg) \
-       $(tfe ${ARG_TEST} --{,no}withtest)
-BUILD_IMG="./build_image --board=${BOARD} --noenable_rootfs_verification $(tfe ${ARG_TEST} --test) dev"
+       --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="./image_to_usb.sh --board=${BOARD} -y --to=${ARG_DEV}"
+IMG_TO_USB="cros flash --yes usb://${ARG_DEV} xbuddy://local/${BOARD}/latest/dev"
 if ${ARG_DEV_USER} ; then
        run ${IMG_TO_USB}
        sync &
@@ -95,15 +139,19 @@ cat <<EOF
 ${IMG_TO_USB}
 
 ### KVM
-./image_to_vm.sh --board=${BOARD} --from=../build/images/${BOARD}/latest
-kvm -m 1024 -vga std -net nic,model=virtio -net user,hostfwd=tcp::9222-:22 -hda ~/chromiumos/src/build/images/${BOARD}/latest/chromiumos_qemu_image.bin
+cros vm --board=${BOARD} --start --no-display --image-path=\${HOME}/chromiumos/src/build/images/${BOARD}/latest/chromiumos_test_image.bin
+
+/usr/local/autotest/bin/autologin.py
+
+export CROS_USER_ID_HASH=\$(ls /home/user/)
+sudo -u chronos CROS_USER_ID_HASH="${CROS_USER_ID_HASH}" crosh
+  vmc start termina  # might run twice
 
 ### RECOVERY
-./mod_image_for_recovery.sh --board=${BOARD}
-${IMG_TO_USB} --image_name=recovery_image.bin
+~/chromiumos/src/scripts/mod_image_for_recovery.sh --board=${BOARD}
+${IMG_TO_USB%/dev}/recovery
 
 ### FACTORY
 ${BUILD_IMG} --factory_install
 ${IMG_TO_USB} -i factory_install_shim.bin
-
 EOF