source: hybrid/branches/releng-9.0/nanobsd/tools/image@ 10592

Last change on this file since 10592 was 10592, checked in by rick, 13 years ago

I also like to use it for deployments.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
File size: 3.5 KB
Line 
1#!/bin/sh
2#
3BASEDIR=`dirname $0`
4. ${BASEDIR}/package-build.inc.sh
5
6NANOBSD="$NANO_SRC/tools/tools/nanobsd/nanobsd.sh"
7
8usage() {
9cat <<EOF
10# Usage $0 <arguments>"
11#
12# Wrapper around nanobsd.sh with autodetection of already processed steps to
13# provide some failsafe net, which avoids building world and/or kernel by
14# default.
15#
16# Rick van der Zwet <rick@wirelessleiden.nl>
17#
18# Arguments:
19# build - Build NanoBSD parts which are not build yet
20# build force kernel - Build NanoBSD and force rebuilding the kernel
21# build force world - Build NanoBSD and force rebuilding world
22# rebuild - Rebuild NanoBSD (aka force rebuilding all)
23# deploy on <node> [and reboot] - Deploy the image on node and reboot if needed
24EOF
25}
26
27FORCE_KERNEL=${FORCE_KERNEL:-"no"}
28FORCE_WORLD=${FORCE_WORLD:-"no"}
29
30if [ -z "$1" ]; then
31 usage; exit 1
32elif [ "$1" = "build" ]; then
33 if [ -z "$2" ]; then
34 elif [ "$2" = "force" ]; then
35 if [ "$3" = "kernel" ]; then
36 FORCE_KERNEL="yes"
37 elif [ "$3" = "world" ]; then
38 FORCE_WORLD="yes"
39 else
40 echo "Argument Error - '$3'"; exit 128
41 fi
42 else
43 echo "Argument Error - '$2'"; exit 128
44 fi
45elif [ "$1" = "rebuild" ]; then
46 FORCE_KERNEL="yes"
47 FORCE_WORLD="yes"
48elif [ "$1" = "deploy" -a "$2" = "on" ]; then
49 if [ -z "$3" ]; then
50 echo "Argument Error - '$3'"; exit 128
51 fi
52 host=$3
53 do_reboot=false
54 if [ -n "$4" -o -n "$5" ]; then
55 if [ "$4" = "and" -a "$5" = "reboot" ]; then
56 do_reboot=true
57 else
58 echo "Argument Error - '$4 $5'"; exit 128
59 fi
60 fi
61
62 # Find object directory
63 img=${OBJDIR}/_.disk.image
64
65 if [ ! -r "$img" ]; then
66 p_err Source $img does not exists
67 exit 1
68 fi
69
70 prompt_timeout=5
71 p_warn "Going to DEPLOY $img to $host"
72 $do_reboot && p_warn "AND will REBOOT the $host"
73 p_warn "Press CTRL+C in $prompt_timeout seconds to CANCEL"
74 sleep $prompt_timeout
75
76 ssh $host mount || exit 1
77 cat $img | ssh $host /tools/update || exit 1
78 if do_reboot; then
79 ssh $host reboot
80 exit 0
81 fi
82else
83 echo "Argument Error - '$1'"; exit 128
84fi
85
86p_info Forcefully building kernel: $FORCE_KERNEL
87p_info Forcefully building world : $FORCE_WORLD
88
89NANOBSD_EXTRA=${NANOBSD_EXTRA:-''}
90
91if [ ! -r "${NANOBSD}" ]; then
92 p_err ${NANOBSD} does not exists
93 exit 1
94fi
95
96if [ ! -x "${NANOBSD}" ]; then
97 NANOBSD="sh ${NANOBSD}"
98fi
99
100# Find object directory
101OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
102
103if [ -d "${OBJDIR}" ]; then
104 NANOBSD_FLAGS=""
105
106 # Detect succesfull buildworld
107 tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
108 if [ $? -eq 0 -a ${FORCE_WORLD} = "no" ]; then
109 p_info NO building of world
110 NANOBSD_FLAGS="${NANOBSD_FLAGS} -w"
111 fi
112
113 # Detect succesfull buildkernel
114 tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
115 if [ $? -eq 0 -a ${FORCE_KERNEL} = "no" ]; then
116 p_info NO building of kernel
117 NANOBSD_FLAGS="${NANOBSD_FLAGS} -k"
118 fi
119
120else
121 p_warn Nothing yet, starting fresh
122 NANOBSD_FLAGS=""
123fi
124
125# Provide verbose output by default
126COMMAND="${NANOBSD} ${NANOBSD_FLAGS} -c ${NANO_CFG_FILE} -v ${NANOBSD_EXTRA}"
127f_time ${COMMAND}
128RETVAL=$?
129
130# Verify on build failures
131tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
132if [ $? -eq 1 ]; then
133 p_err Building world FAILED, check ${OBJDIR}/_.bw
134fi
135tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
136if [ $? -eq 1 ]; then
137 p_err Building kernel FAILED, check ${OBJDIR}/_.bk
138fi
139if [ $RETVAL -ne 0 ]; then
140 p_err "Errors in building NanoBSD Image ($RETVAL)"
141fi
142p_info End time: `date`
143exit ${RETVAL}
Note: See TracBrowser for help on using the repository browser.