| 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: (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
|
---|
| 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 | NANOBSD_FLAGS=""
|
---|
| 175 |
|
---|
| 176 | # Detect succesfull buildworld
|
---|
| 177 | tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
|
---|
| 178 | if [ $? -eq 0 -a ${FORCE_WORLD} = "no" ]; then
|
---|
| 179 | p_info NO building of world
|
---|
| 180 | NANOBSD_FLAGS="${NANOBSD_FLAGS} -w"
|
---|
| 181 | fi
|
---|
| 182 |
|
---|
| 183 | # Detect succesfull buildkernel
|
---|
| 184 | tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
|
---|
| 185 | if [ $? -eq 0 -a ${FORCE_KERNEL} = "no" ]; then
|
---|
| 186 | p_info NO building of kernel
|
---|
| 187 | NANOBSD_FLAGS="${NANOBSD_FLAGS} -k"
|
---|
| 188 | fi
|
---|
| 189 |
|
---|
| 190 | else
|
---|
| 191 | p_warn Nothing yet, starting fresh
|
---|
| 192 | NANOBSD_FLAGS=""
|
---|
| 193 | fi
|
---|
| 194 |
|
---|
| 195 | # Provide verbose output by default
|
---|
| 196 | COMMAND="${NANOBSD} ${NANOBSD_FLAGS} -c ${NANO_CFG_FILE} -v ${NANOBSD_EXTRA}"
|
---|
| 197 | f_time ${COMMAND}
|
---|
| 198 | RETVAL=$?
|
---|
| 199 |
|
---|
| 200 | # Verify on build failures
|
---|
| 201 | tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
|
---|
| 202 | if [ $? -eq 1 ]; then
|
---|
| 203 | p_err Building world FAILED, check ${OBJDIR}/_.bw
|
---|
| 204 | fi
|
---|
| 205 | tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
|
---|
| 206 | if [ $? -eq 1 ]; then
|
---|
| 207 | p_err Building kernel FAILED, check ${OBJDIR}/_.bk
|
---|
| 208 | fi
|
---|
| 209 | if [ $RETVAL -ne 0 ]; then
|
---|
| 210 | p_err "Errors in building NanoBSD Image ($RETVAL)"
|
---|
| 211 | fi
|
---|
| 212 | p_info End time: `date`
|
---|
| 213 | exit ${RETVAL}
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | #
|
---|
| 217 | # Argument parsing
|
---|
| 218 | #
|
---|
| 219 | FORCE_KERNEL=${FORCE_KERNEL:-"no"}
|
---|
| 220 | FORCE_WORLD=${FORCE_WORLD:-"no"}
|
---|
| 221 | if [ -z "$1" ]; then
|
---|
| 222 | usage; exit 1
|
---|
| 223 | elif [ "$1" = "build" ]; then
|
---|
| 224 | if [ -z "$2" ]; then
|
---|
| 225 | elif [ "$2" = "force" ]; then
|
---|
| 226 | if [ "$3" = "kernel" ]; then
|
---|
| 227 | FORCE_KERNEL="yes"
|
---|
| 228 | elif [ "$3" = "world" ]; then
|
---|
| 229 | FORCE_WORLD="yes"
|
---|
| 230 | else
|
---|
| 231 | echo "Argument Error - '$3'"; exit 128
|
---|
| 232 | fi
|
---|
| 233 | else
|
---|
| 234 | echo "Argument Error - '$2'"; exit 128
|
---|
| 235 | fi
|
---|
| 236 | build_image
|
---|
| 237 | elif [ "$1" = "rebuild" ]; then
|
---|
| 238 | FORCE_KERNEL="yes"
|
---|
| 239 | FORCE_WORLD="yes"
|
---|
| 240 | build_image
|
---|
| 241 | elif [ "$1" = "deploy" -a "$2" = "on" ]; then
|
---|
| 242 | if [ -z "$3" ]; then
|
---|
| 243 | echo "Argument Error - '$3'"; exit 128
|
---|
| 244 | fi
|
---|
| 245 | host=$3
|
---|
| 246 | do_reboot=false
|
---|
| 247 | if [ -n "$4" -o -n "$5" ]; then
|
---|
| 248 | if [ "$4" = "and" -a "$5" = "reboot" ]; then
|
---|
| 249 | do_reboot=true
|
---|
| 250 | else
|
---|
| 251 | echo "Argument Error - '$4 $5'"; exit 128
|
---|
| 252 | fi
|
---|
| 253 | fi
|
---|
| 254 | deploy_image
|
---|
| 255 | elif [ "$1" = "ports" ]; then
|
---|
| 256 | if [ "$2" = "update" ]; then
|
---|
| 257 | # Fetch the latest details and provide listing of packages to be updated
|
---|
| 258 | portsnap fetch update || exit 1
|
---|
| 259 |
|
---|
| 260 | # HACK: install our own ports _inside_ the normal ports dir
|
---|
| 261 | cp -fR $WL_PORTSDIR/* $PORTSDIR || exit 1
|
---|
| 262 |
|
---|
| 263 | # Make sure portmaster is present to update all ports
|
---|
| 264 | portmaster --version 1>/dev/null 2>/dev/null || make -C /usr/ports/ports-mgmt/portmaster BATCH=yes install clean || exit 1
|
---|
| 265 |
|
---|
| 266 | # Update via portmaster
|
---|
| 267 | CMD="env `echo $PKG_MAKE_ARGS` portmaster --no-confirm --update-if-newer -t -y -d -G `echo $PACKAGE_LIST`"
|
---|
| 268 | echo "# Going to run port upgrade cycle: $CMD"; $CMD || exit 1
|
---|
| 269 |
|
---|
| 270 | . ${BASEDIR}/package-build.sh
|
---|
| 271 | elif [ "$2" = "force" -a "$3" = "rebuild" ]; then
|
---|
| 272 | export FORCE_REBUILD=1
|
---|
| 273 | . ${BASEDIR}/package-build.sh
|
---|
| 274 | else
|
---|
| 275 | shift 1
|
---|
| 276 | echo "Arguments Error - '$*'"; exit 128
|
---|
| 277 | fi
|
---|
| 278 | elif [ "$1" = "config" ]; then
|
---|
| 279 | if [ "$2" = "for" ]; then
|
---|
| 280 | if [ -n "$3" ]; then
|
---|
| 281 | node_name=$3
|
---|
| 282 | else
|
---|
| 283 | echo "Arguments Error - '$*'"; exit 128
|
---|
| 284 | fi
|
---|
| 285 | else
|
---|
| 286 | echo "Arguments Error - '$*'"; exit 128
|
---|
| 287 | fi
|
---|
| 288 | config_image $node_name
|
---|
| 289 | elif [ "$1" = "edit" ]; then
|
---|
| 290 | edit_image
|
---|
| 291 | else
|
---|
| 292 | echo "Argument Error - '$1'"; exit 128
|
---|
| 293 | fi
|
---|
| 294 |
|
---|