]> git.wh0rd.org Git - home.git/blob - .bin/cros-board
installkernel: improve s390 logic
[home.git] / .bin / cros-board
1 #!/bin/bash
2 . /etc/init.d/functions.sh || exit 1
3 die() { eerror "$*"; exit 1; }
4 set -e
5
6 cd "${HOME}/trunk/src/scripts/"
7
8 : ${BOARD:=`cat .default_board 2>/dev/null`}
9 if [[ -z ${BOARD} ]] ; then
10         die "missing BOARD"
11 fi
12 IMAGES="${HOME}/trunk/src/build/images/${BOARD}"
13 BUILD="/build/${BOARD}"
14
15 ARG_CLEAN=false
16 ARG_DEV="/dev/sdc"
17 ARG_DEV_USER=false
18 ARG_PRETEND=false
19 ARG_NOPKG=false
20 ARG_AUTOTEST=false
21 ARG_FACTORY=false
22 ARG_VERBOSE=false
23 ARG_TEST=false
24 while [[ $# -ne 0 ]] ; do
25         case $1 in
26         --clean) ARG_CLEAN=true;;
27         -p) ARG_PRETEND=true;;
28         -Y) ARG_DEV_USER=true;;
29         -y) shift; ARG_DEV=$1; ARG_DEV_USER=true;;
30         -v) ARG_VERBOSE=true;;
31         -t) ARG_TEST=true;;
32         --nousepkg) ARG_NOPKG=true;;
33         --autotest) ARG_AUTOTEST=true;;
34         --factory) ARG_FACTORY=true;;
35         -h) exec sed -n '/^while/,/^done/p' "$0";;
36         *) echo "unknown opt: $*"; exit 1;;
37         esac
38         shift
39 done
40
41 piperet() { set -- ${PIPESTATUS[@]/0}; [[ $# -eq 0 ]]; }
42 run() {
43         set +e
44         if ! ${ARG_PRETEND} ; then
45                 ebegin "$*"
46                 local log="${IMAGES}"/log.${1##*/}
47                 if ${ARG_VERBOSE} ; then
48                         "$@" |& tee "${log}"
49                 else
50                         "$@" >& "${log}"
51                 fi
52                 piperet
53                 eend $? || exit $?
54         else
55                 einfo "$*"
56         fi
57         set -e
58 }
59
60 tfe() { ($1 && echo $2 || echo $3); }
61
62 mkdir -p "${IMAGES}"
63 rm -f "${IMAGES}"/log.*
64
65 einfo "Log root: ${IMAGES}/log."
66
67 run ./update_chroot --toolchain_boards=${BOARD}
68
69 if ${ARG_CLEAN} || [[ ! -d ${BUILD} ]] ; then
70         run sudo rm -rf "${BUILD}"
71         run ./setup_board --board=${BOARD} --skip_chroot_upgrade
72         if [ $? -ne 0 ] ; then
73                 run sudo rm -rf "${BUILD}"
74                 exit 1
75         fi
76 fi
77
78 run ./build_packages \
79         --board=${BOARD} \
80         --nowithdebug \
81         --skip_chroot_upgrade \
82         $(tfe ${ARG_AUTOTEST} --{,no}withautotest) \
83         $(tfe ${ARG_FACTORY} --{,no}withfactory) \
84         $(tfe ${ARG_NOPKG} --{no,}usepkg) \
85         $(tfe ${ARG_TEST} --{,no}withtest)
86 BUILD_IMG="./build_image --board=${BOARD} --noenable_rootfs_verification $(tfe ${ARG_TEST} test) dev"
87 run ${BUILD_IMG}
88
89 IMG_TO_USB="cros flash --yes usb://${ARG_DEV} xbuddy://local/${BOARD}/latest/dev"
90 if ${ARG_DEV_USER} ; then
91         run ${IMG_TO_USB}
92         sync &
93 fi
94
95 cd "${IMAGES}"
96 rm -rf $(ls -td1R `find -mindepth 1 -maxdepth 1 -type d` | sed -e 1d -e 2d)
97
98 d="~/trunk/src/scripts"
99 BUILD_IMG="${d}/${BUILD_IMG#./}"
100 cat <<EOF
101
102 ### LIVE
103 ${IMG_TO_USB}
104
105 ### KVM
106 ${d}/image_to_vm.sh --board=${BOARD} --from=../build/images/${BOARD}/latest
107 ${d}/image_to_vm.sh --board=${BOARD} --from=../build/images/${BOARD}/latest --test_image
108 ~/chromiumos/src/scripts/bin/cros_start_vm --no_graphics --image_path=\${HOME}/chromiumos/src/build/images/${BOARD}/latest/chromiumos_qemu_image.bin
109 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
110
111 ### RECOVERY
112 ${d}/mod_image_for_recovery.sh --board=${BOARD}
113 ${IMG_TO_USB} --image_name=recovery_image.bin
114
115 ### FACTORY
116 ${BUILD_IMG} --factory_install
117 ${IMG_TO_USB} -i factory_install_shim.bin
118
119 EOF