1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | BASEDIR=`dirname $0`
|
---|
4 | . ${BASEDIR}/package-build.inc.sh
|
---|
5 |
|
---|
6 | NANOBSD="$NANO_SRC/tools/tools/nanobsd/nanobsd.sh"
|
---|
7 |
|
---|
8 | usage() {
|
---|
9 | cat <<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
|
---|
24 | EOF
|
---|
25 | }
|
---|
26 |
|
---|
27 | FORCE_KERNEL=${FORCE_KERNEL:-"no"}
|
---|
28 | FORCE_WORLD=${FORCE_WORLD:-"no"}
|
---|
29 |
|
---|
30 | if [ -z "$1" ]; then
|
---|
31 | usage; exit 1
|
---|
32 | elif [ "$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
|
---|
45 | elif [ "$1" = "rebuild" ]; then
|
---|
46 | FORCE_KERNEL="yes"
|
---|
47 | FORCE_WORLD="yes"
|
---|
48 | elif [ "$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
|
---|
82 | else
|
---|
83 | echo "Argument Error - '$1'"; exit 128
|
---|
84 | fi
|
---|
85 |
|
---|
86 | p_info Forcefully building kernel: $FORCE_KERNEL
|
---|
87 | p_info Forcefully building world : $FORCE_WORLD
|
---|
88 |
|
---|
89 | NANOBSD_EXTRA=${NANOBSD_EXTRA:-''}
|
---|
90 |
|
---|
91 | if [ ! -r "${NANOBSD}" ]; then
|
---|
92 | p_err ${NANOBSD} does not exists
|
---|
93 | exit 1
|
---|
94 | fi
|
---|
95 |
|
---|
96 | if [ ! -x "${NANOBSD}" ]; then
|
---|
97 | NANOBSD="sh ${NANOBSD}"
|
---|
98 | fi
|
---|
99 |
|
---|
100 | # Find object directory
|
---|
101 | OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
|
---|
102 |
|
---|
103 | if [ -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 |
|
---|
120 | else
|
---|
121 | p_warn Nothing yet, starting fresh
|
---|
122 | NANOBSD_FLAGS=""
|
---|
123 | fi
|
---|
124 |
|
---|
125 | # Provide verbose output by default
|
---|
126 | COMMAND="${NANOBSD} ${NANOBSD_FLAGS} -c ${NANO_CFG_FILE} -v ${NANOBSD_EXTRA}"
|
---|
127 | f_time ${COMMAND}
|
---|
128 | RETVAL=$?
|
---|
129 |
|
---|
130 | # Verify on build failures
|
---|
131 | tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
|
---|
132 | if [ $? -eq 1 ]; then
|
---|
133 | p_err Building world FAILED, check ${OBJDIR}/_.bw
|
---|
134 | fi
|
---|
135 | tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
|
---|
136 | if [ $? -eq 1 ]; then
|
---|
137 | p_err Building kernel FAILED, check ${OBJDIR}/_.bk
|
---|
138 | fi
|
---|
139 | if [ $RETVAL -ne 0 ]; then
|
---|
140 | p_err "Errors in building NanoBSD Image ($RETVAL)"
|
---|
141 | fi
|
---|
142 | p_info End time: `date`
|
---|
143 | exit ${RETVAL}
|
---|