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

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

Deploying and rebuilding and image every time might be a bit too much ;-), wrapping
into functions to make the calling tree clear.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
File size: 3.7 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
27
28deploy_image() {
29 # Find object directory
30 img=${OBJDIR}/_.disk.image
31
32 if [ ! -r "$img" ]; then
33 p_err Source $img does not exists
34 exit 1
35 fi
36
37 prompt_timeout=5
38 p_warn "Going to DEPLOY $img to $host"
39 $do_reboot && p_warn "AND will REBOOT the $host"
40 p_warn "Press CTRL+C in $prompt_timeout seconds to CANCEL"
41 sleep $prompt_timeout
42
43 ssh $host mount || exit 1
44 cat $img | ssh $host /tools/update || exit 1
45 if $do_reboot; then
46 ssh $host reboot
47 fi
48}
49
50
51build_image() {
52 p_info Forcefully building kernel: $FORCE_KERNEL
53 p_info Forcefully building world : $FORCE_WORLD
54
55 NANOBSD_EXTRA=${NANOBSD_EXTRA:-''}
56
57 if [ ! -r "${NANOBSD}" ]; then
58 p_err ${NANOBSD} does not exists
59 exit 1
60 fi
61
62 if [ ! -x "${NANOBSD}" ]; then
63 NANOBSD="sh ${NANOBSD}"
64 fi
65
66 # Find object directory
67 OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
68
69 if [ -d "${OBJDIR}" ]; then
70 NANOBSD_FLAGS=""
71
72 # Detect succesfull buildworld
73 tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
74 if [ $? -eq 0 -a ${FORCE_WORLD} = "no" ]; then
75 p_info NO building of world
76 NANOBSD_FLAGS="${NANOBSD_FLAGS} -w"
77 fi
78
79 # Detect succesfull buildkernel
80 tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
81 if [ $? -eq 0 -a ${FORCE_KERNEL} = "no" ]; then
82 p_info NO building of kernel
83 NANOBSD_FLAGS="${NANOBSD_FLAGS} -k"
84 fi
85
86 else
87 p_warn Nothing yet, starting fresh
88 NANOBSD_FLAGS=""
89 fi
90
91 # Provide verbose output by default
92 COMMAND="${NANOBSD} ${NANOBSD_FLAGS} -c ${NANO_CFG_FILE} -v ${NANOBSD_EXTRA}"
93 f_time ${COMMAND}
94 RETVAL=$?
95
96 # Verify on build failures
97 tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
98 if [ $? -eq 1 ]; then
99 p_err Building world FAILED, check ${OBJDIR}/_.bw
100 fi
101 tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
102 if [ $? -eq 1 ]; then
103 p_err Building kernel FAILED, check ${OBJDIR}/_.bk
104 fi
105 if [ $RETVAL -ne 0 ]; then
106 p_err "Errors in building NanoBSD Image ($RETVAL)"
107 fi
108 p_info End time: `date`
109 exit ${RETVAL}
110}
111
112
113#
114# Argument parsing
115#
116FORCE_KERNEL=${FORCE_KERNEL:-"no"}
117FORCE_WORLD=${FORCE_WORLD:-"no"}
118if [ -z "$1" ]; then
119 usage; exit 1
120elif [ "$1" = "build" ]; then
121 if [ -z "$2" ]; then
122 elif [ "$2" = "force" ]; then
123 if [ "$3" = "kernel" ]; then
124 FORCE_KERNEL="yes"
125 elif [ "$3" = "world" ]; then
126 FORCE_WORLD="yes"
127 else
128 echo "Argument Error - '$3'"; exit 128
129 fi
130 else
131 echo "Argument Error - '$2'"; exit 128
132 fi
133 build_image
134elif [ "$1" = "rebuild" ]; then
135 FORCE_KERNEL="yes"
136 FORCE_WORLD="yes"
137 build_image
138elif [ "$1" = "deploy" -a "$2" = "on" ]; then
139 if [ -z "$3" ]; then
140 echo "Argument Error - '$3'"; exit 128
141 fi
142 host=$3
143 do_reboot=false
144 if [ -n "$4" -o -n "$5" ]; then
145 if [ "$4" = "and" -a "$5" = "reboot" ]; then
146 do_reboot=true
147 else
148 echo "Argument Error - '$4 $5'"; exit 128
149 fi
150 fi
151 deploy_image
152else
153 echo "Argument Error - '$1'"; exit 128
154fi
155
Note: See TracBrowser for help on using the repository browser.