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

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

Set the prompt to avoid confusion. While here merge to ./image framework. So
calling it should be now:

./tools/image edit

Reported-By: huub@
Fixes: nodefactory:ticket:179

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