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