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