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

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

Merge config into tools/image

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
File size: 5.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# config [for <node>] - Configure image to be used for <node>
23# rebuild - Rebuild NanoBSD (aka force rebuilding all)
24# deploy on <node> [and reboot] - Deploy the image on node and reboot if needed
25# ports update - Update the packages from ports
26# ports force rebuild - Forcefully rebuilding all required packages
27EOF
28}
29
30
31deploy_image() {
32 # Find object directory
33 img=${OBJDIR}/_.disk.image
34
35 if [ ! -r "$img" ]; then
36 p_err Source $img does not exists
37 exit 1
38 fi
39
40 prompt_timeout=5
41 p_warn "Going to DEPLOY $img to $host"
42 $do_reboot && p_warn "AND will REBOOT the $host"
43 p_warn "Press CTRL+C in $prompt_timeout seconds to CANCEL"
44 sleep $prompt_timeout
45
46 ssh $host mount || exit 1
47 # Hack to make sure we update the fstab the right way when converting from
48 # 8.X-RELEASE to 9.X-RELEASE. ad0 naming changed to ada0.
49 ssh $HOST 'echo NANO_DRIVE=ada0 > /etc/nanobsd.conf' || exit 1
50 cat $img | ssh $host /tools/update || exit 1
51 if $do_reboot; then
52 ssh $host reboot
53 fi
54}
55
56config_image() {
57 node_name=${1:+"-b -c $1"}
58
59 img=$OBJDIR/_.disk.full
60
61 mnt=`mktemp -d -t $(basename $0)`
62 md=`mdconfig -a -t vnode -f $img`
63
64 # Clean up when done
65 trap "umount $mnt/dev; umount $mnt/cfg; umount $mnt; mdconfig -d -u $md; rm -d $mnt" 0
66 trap "exit 1" 1 2 3 15
67
68 # Root filesystem
69 mount /dev/${md}s1a $mnt || exit 1
70
71 # /dev/null in chroot
72 mount -t devfs devfs ${mnt}/dev || exit 1
73
74 # Config files lives at /cfg location
75 mount /dev/${md}s3 $mnt/cfg || exit 1
76
77 # Try to fetch and store config
78 chroot $mnt /tools/wl-config -d -n -m startup $node_name || exit 1
79}
80
81
82build_image() {
83 p_info Forcefully building kernel: $FORCE_KERNEL
84 p_info Forcefully building world : $FORCE_WORLD
85
86 NANOBSD_EXTRA=${NANOBSD_EXTRA:-''}
87
88 if [ ! -r "${NANOBSD}" ]; then
89 p_err ${NANOBSD} does not exists
90 exit 1
91 fi
92
93 if [ ! -x "${NANOBSD}" ]; then
94 NANOBSD="sh ${NANOBSD}"
95 fi
96
97 # Find object directory
98 OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
99
100 if [ -d "${OBJDIR}" ]; then
101 NANOBSD_FLAGS=""
102
103 # Detect succesfull buildworld
104 tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
105 if [ $? -eq 0 -a ${FORCE_WORLD} = "no" ]; then
106 p_info NO building of world
107 NANOBSD_FLAGS="${NANOBSD_FLAGS} -w"
108 fi
109
110 # Detect succesfull buildkernel
111 tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
112 if [ $? -eq 0 -a ${FORCE_KERNEL} = "no" ]; then
113 p_info NO building of kernel
114 NANOBSD_FLAGS="${NANOBSD_FLAGS} -k"
115 fi
116
117 else
118 p_warn Nothing yet, starting fresh
119 NANOBSD_FLAGS=""
120 fi
121
122 # Provide verbose output by default
123 COMMAND="${NANOBSD} ${NANOBSD_FLAGS} -c ${NANO_CFG_FILE} -v ${NANOBSD_EXTRA}"
124 f_time ${COMMAND}
125 RETVAL=$?
126
127 # Verify on build failures
128 tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
129 if [ $? -eq 1 ]; then
130 p_err Building world FAILED, check ${OBJDIR}/_.bw
131 fi
132 tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
133 if [ $? -eq 1 ]; then
134 p_err Building kernel FAILED, check ${OBJDIR}/_.bk
135 fi
136 if [ $RETVAL -ne 0 ]; then
137 p_err "Errors in building NanoBSD Image ($RETVAL)"
138 fi
139 p_info End time: `date`
140 exit ${RETVAL}
141}
142
143#
144# Argument parsing
145#
146FORCE_KERNEL=${FORCE_KERNEL:-"no"}
147FORCE_WORLD=${FORCE_WORLD:-"no"}
148if [ -z "$1" ]; then
149 usage; exit 1
150elif [ "$1" = "build" ]; then
151 if [ -z "$2" ]; then
152 elif [ "$2" = "force" ]; then
153 if [ "$3" = "kernel" ]; then
154 FORCE_KERNEL="yes"
155 elif [ "$3" = "world" ]; then
156 FORCE_WORLD="yes"
157 else
158 echo "Argument Error - '$3'"; exit 128
159 fi
160 else
161 echo "Argument Error - '$2'"; exit 128
162 fi
163 build_image
164elif [ "$1" = "rebuild" ]; then
165 FORCE_KERNEL="yes"
166 FORCE_WORLD="yes"
167 build_image
168elif [ "$1" = "deploy" -a "$2" = "on" ]; then
169 if [ -z "$3" ]; then
170 echo "Argument Error - '$3'"; exit 128
171 fi
172 host=$3
173 do_reboot=false
174 if [ -n "$4" -o -n "$5" ]; then
175 if [ "$4" = "and" -a "$5" = "reboot" ]; then
176 do_reboot=true
177 else
178 echo "Argument Error - '$4 $5'"; exit 128
179 fi
180 fi
181 deploy_image
182elif [ "$1" = "ports" ]; then
183 if [ "$2" = "update" ]; then
184 # Fetch the latest details and provide listing of packages to be updated
185 portsnap fetch update || exit 1
186
187 # HACK: install our own ports _inside_ the normal ports dir
188 cp -fR $WL_PORTSDIR/* $PORTSDIR || exit 1
189
190 # Make sure portmaster is present to update all ports
191 portmaster --version 1>/dev/null 2>/dev/null || make -C /usr/ports/ports-mgmt/portmaster BATCH=yes install clean || exit 1
192
193 # Update via portmaster
194 portmaster --no-confirm --update-if-newer -y -d -G `echo $PKG_MAKE_ARGS | xargs -n1 echo -m ` $PACKAGE_LIST
195
196 . ${BASEDIR}/package-build.sh
197 elif [ "$2" = "force" -a "$3" = "rebuild" ]; then
198 export FORCE_REBUILD=1
199 . ${BASEDIR}/package-build.sh
200 else
201 shift 1
202 echo "Arguments Error - '$*'"; exit 128
203 fi
204elif [ "$1" = "config" ]; then
205 if [ "$2" = "for" ]; then
206 if [ -n "$3" ]; then
207 node_name=$3
208 else
209 echo "Arguments Error - '$*'"; exit 128
210 fi
211 else
212 echo "Arguments Error - '$*'"; exit 128
213 fi
214 config_image $node_name
215else
216 echo "Argument Error - '$1'"; exit 128
217fi
218
Note: See TracBrowser for help on using the repository browser.