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

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

Horible broke update script for 8.x -> 9.x. Do reverse and apply awefull hack
to make sure we re-write the fstab properly if needed.

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