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