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