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

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

For some reason portmaster exits with an 1 after updates. This should not kill my loops.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
File size: 4.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# rebuild - Rebuild NanoBSD (aka force rebuilding all)
23# deploy on <node> [and reboot] - Deploy the image on node and reboot if needed
24# ports update - Update the packages from ports
25# ports force rebuild - Forcefully rebuilding all required packages
26EOF
27}
28
29
30deploy_image() {
31 # Find object directory
32 img=${OBJDIR}/_.disk.image
33
34 if [ ! -r "$img" ]; then
35 p_err Source $img does not exists
36 exit 1
37 fi
38
39 prompt_timeout=5
40 p_warn "Going to DEPLOY $img to $host"
41 $do_reboot && p_warn "AND will REBOOT the $host"
42 p_warn "Press CTRL+C in $prompt_timeout seconds to CANCEL"
43 sleep $prompt_timeout
44
45 ssh $host mount || exit 1
46 cat $img | ssh $host /tools/update || exit 1
47 if $do_reboot; then
48 ssh $host reboot
49 fi
50}
51
52
53build_image() {
54 p_info Forcefully building kernel: $FORCE_KERNEL
55 p_info Forcefully building world : $FORCE_WORLD
56
57 NANOBSD_EXTRA=${NANOBSD_EXTRA:-''}
58
59 if [ ! -r "${NANOBSD}" ]; then
60 p_err ${NANOBSD} does not exists
61 exit 1
62 fi
63
64 if [ ! -x "${NANOBSD}" ]; then
65 NANOBSD="sh ${NANOBSD}"
66 fi
67
68 # Find object directory
69 OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
70
71 if [ -d "${OBJDIR}" ]; then
72 NANOBSD_FLAGS=""
73
74 # Detect succesfull buildworld
75 tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
76 if [ $? -eq 0 -a ${FORCE_WORLD} = "no" ]; then
77 p_info NO building of world
78 NANOBSD_FLAGS="${NANOBSD_FLAGS} -w"
79 fi
80
81 # Detect succesfull buildkernel
82 tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
83 if [ $? -eq 0 -a ${FORCE_KERNEL} = "no" ]; then
84 p_info NO building of kernel
85 NANOBSD_FLAGS="${NANOBSD_FLAGS} -k"
86 fi
87
88 else
89 p_warn Nothing yet, starting fresh
90 NANOBSD_FLAGS=""
91 fi
92
93 # Provide verbose output by default
94 COMMAND="${NANOBSD} ${NANOBSD_FLAGS} -c ${NANO_CFG_FILE} -v ${NANOBSD_EXTRA}"
95 f_time ${COMMAND}
96 RETVAL=$?
97
98 # Verify on build failures
99 tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
100 if [ $? -eq 1 ]; then
101 p_err Building world FAILED, check ${OBJDIR}/_.bw
102 fi
103 tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
104 if [ $? -eq 1 ]; then
105 p_err Building kernel FAILED, check ${OBJDIR}/_.bk
106 fi
107 if [ $RETVAL -ne 0 ]; then
108 p_err "Errors in building NanoBSD Image ($RETVAL)"
109 fi
110 p_info End time: `date`
111 exit ${RETVAL}
112}
113
114#
115# Argument parsing
116#
117FORCE_KERNEL=${FORCE_KERNEL:-"no"}
118FORCE_WORLD=${FORCE_WORLD:-"no"}
119if [ -z "$1" ]; then
120 usage; exit 1
121elif [ "$1" = "build" ]; then
122 if [ -z "$2" ]; then
123 elif [ "$2" = "force" ]; then
124 if [ "$3" = "kernel" ]; then
125 FORCE_KERNEL="yes"
126 elif [ "$3" = "world" ]; then
127 FORCE_WORLD="yes"
128 else
129 echo "Argument Error - '$3'"; exit 128
130 fi
131 else
132 echo "Argument Error - '$2'"; exit 128
133 fi
134 build_image
135elif [ "$1" = "rebuild" ]; then
136 FORCE_KERNEL="yes"
137 FORCE_WORLD="yes"
138 build_image
139elif [ "$1" = "deploy" -a "$2" = "on" ]; then
140 if [ -z "$3" ]; then
141 echo "Argument Error - '$3'"; exit 128
142 fi
143 host=$3
144 do_reboot=false
145 if [ -n "$4" -o -n "$5" ]; then
146 if [ "$4" = "and" -a "$5" = "reboot" ]; then
147 do_reboot=true
148 else
149 echo "Argument Error - '$4 $5'"; exit 128
150 fi
151 fi
152 deploy_image
153elif [ "$1" = "ports" ]; then
154 if [ "$2" = "update" ]; then
155 # Fetch the latest details and provide listing of packages to be updated
156 portsnap fetch update || exit 1
157
158 # HACK: install our own ports _inside_ the normal ports dir
159 cp -fR $WL_PORTSDIR/* $PORTSDIR || exit 1
160
161 # Make sure portmaster is present to update all ports
162 portmaster --version 1>/dev/null 2>/dev/null || make -C /usr/ports/ports-mgmt/portmaster BATCH=yes install clean || exit 1
163
164 # Update via portmaster
165 portmaster --no-confirm --update-if-newer -y -d -G `echo $PKG_MAKE_ARGS | xargs -n1 echo -m ` $PACKAGE_LIST
166
167 . ${BASEDIR}/package-build.sh
168 elif [ "$2" = "force" -a "$3" = "rebuild" ]; then
169 export FORCE_REBUILD=1
170 . ${BASEDIR}/package-build.sh
171 else
172 shift 1
173 echo "Arguments Error - '$*'"; exit 128
174 fi
175else
176 echo "Argument Error - '$1'"; exit 128
177fi
178
Note: See TracBrowser for help on using the repository browser.