Changeset 10593 in hybrid for branches


Ignore:
Timestamp:
Apr 26, 2012, 3:24:04 PM (13 years ago)
Author:
rick
Message:

Deploying and rebuilding and image every time might be a bit too much ;-), wrapping
into functions to make the calling tree clear.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/releng-9.0/nanobsd/tools/image

    r10592 r10593  
    88usage() {
    99cat <<EOF
    10 # Usage $0 <arguments>"
     10# Usage $0 <arguments>
    1111#
    1212# Wrapper around nanobsd.sh with autodetection of already processed steps to
     
    2525}
    2626
    27 FORCE_KERNEL=${FORCE_KERNEL:-"no"}
    28 FORCE_WORLD=${FORCE_WORLD:-"no"}
    2927
    30 if [ -z "$1" ]; then
    31   usage; exit 1
    32 elif [ "$1" = "build" ]; then
    33   if [ -z "$2" ]; then
    34   elif [ "$2" = "force" ]; then
    35     if [ "$3" = "kernel" ]; then
    36       FORCE_KERNEL="yes"
    37     elif [ "$3" = "world" ]; then
    38       FORCE_WORLD="yes"
    39     else
    40       echo "Argument Error - '$3'"; exit 128
    41     fi
    42   else
    43     echo "Argument Error - '$2'"; exit 128
    44   fi
    45 elif [ "$1" = "rebuild" ]; then
    46   FORCE_KERNEL="yes"
    47   FORCE_WORLD="yes"
    48 elif [ "$1" = "deploy" -a "$2" = "on" ]; then
    49   if [ -z "$3" ]; then
    50       echo "Argument Error - '$3'"; exit 128
    51   fi
    52   host=$3
    53   do_reboot=false
    54   if [ -n "$4" -o -n "$5" ]; then
    55     if [ "$4" = "and" -a "$5" = "reboot" ]; then
    56       do_reboot=true
    57     else
    58       echo "Argument Error - '$4 $5'"; exit 128
    59     fi
    60   fi
    61  
     28deploy_image() {
    6229  # Find object directory
    6330  img=${OBJDIR}/_.disk.image
     
    7643  ssh $host mount || exit 1
    7744  cat $img | ssh $host /tools/update || exit 1
    78   if do_reboot; then
     45  if $do_reboot; then
    7946    ssh $host reboot
    80     exit 0
    8147  fi
     48}
     49
     50
     51build_image() {
     52  p_info Forcefully building kernel: $FORCE_KERNEL
     53  p_info Forcefully building world : $FORCE_WORLD
     54 
     55  NANOBSD_EXTRA=${NANOBSD_EXTRA:-''}
     56 
     57  if [ ! -r "${NANOBSD}" ]; then
     58    p_err ${NANOBSD} does not exists
     59    exit 1
     60  fi
     61 
     62  if [ ! -x "${NANOBSD}" ]; then
     63    NANOBSD="sh ${NANOBSD}"
     64  fi
     65 
     66  # Find object directory
     67  OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
     68 
     69  if [ -d "${OBJDIR}" ]; then
     70    NANOBSD_FLAGS=""
     71   
     72    # Detect succesfull buildworld
     73    tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
     74    if [ $? -eq 0 -a ${FORCE_WORLD} = "no" ]; then
     75       p_info NO building of world
     76       NANOBSD_FLAGS="${NANOBSD_FLAGS} -w"
     77    fi 
     78 
     79    # Detect succesfull buildkernel
     80    tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
     81    if [ $? -eq 0 -a ${FORCE_KERNEL} = "no" ]; then
     82       p_info NO building of kernel
     83       NANOBSD_FLAGS="${NANOBSD_FLAGS} -k"
     84    fi 
     85 
     86  else
     87    p_warn Nothing yet, starting fresh
     88    NANOBSD_FLAGS=""
     89  fi
     90 
     91  # Provide verbose output by default
     92  COMMAND="${NANOBSD} ${NANOBSD_FLAGS} -c ${NANO_CFG_FILE} -v ${NANOBSD_EXTRA}"
     93  f_time ${COMMAND}
     94  RETVAL=$?
     95 
     96  # Verify on build failures
     97  tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
     98  if [ $? -eq 1 ]; then
     99    p_err Building world FAILED, check ${OBJDIR}/_.bw
     100  fi
     101  tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
     102  if [ $? -eq 1 ]; then
     103    p_err Building kernel FAILED, check ${OBJDIR}/_.bk
     104  fi 
     105  if [ $RETVAL -ne 0 ]; then
     106    p_err "Errors in building NanoBSD Image ($RETVAL)"
     107  fi
     108  p_info End time: `date`
     109  exit ${RETVAL}
     110}
     111
     112
     113#
     114# Argument parsing
     115#
     116FORCE_KERNEL=${FORCE_KERNEL:-"no"}
     117FORCE_WORLD=${FORCE_WORLD:-"no"}
     118if [ -z "$1" ]; then
     119  usage; exit 1
     120elif [ "$1" = "build" ]; then
     121  if [ -z "$2" ]; then
     122  elif [ "$2" = "force" ]; then
     123    if [ "$3" = "kernel" ]; then
     124      FORCE_KERNEL="yes"
     125    elif [ "$3" = "world" ]; then
     126      FORCE_WORLD="yes"
     127    else
     128      echo "Argument Error - '$3'"; exit 128
     129    fi
     130  else
     131    echo "Argument Error - '$2'"; exit 128
     132  fi
     133  build_image
     134elif [ "$1" = "rebuild" ]; then
     135  FORCE_KERNEL="yes"
     136  FORCE_WORLD="yes"
     137  build_image
     138elif [ "$1" = "deploy" -a "$2" = "on" ]; then
     139  if [ -z "$3" ]; then
     140      echo "Argument Error - '$3'"; exit 128
     141  fi
     142  host=$3
     143  do_reboot=false
     144  if [ -n "$4" -o -n "$5" ]; then
     145    if [ "$4" = "and" -a "$5" = "reboot" ]; then
     146      do_reboot=true
     147    else
     148      echo "Argument Error - '$4 $5'"; exit 128
     149    fi
     150  fi
     151  deploy_image
    82152else
    83153  echo "Argument Error - '$1'"; exit 128
    84154fi
    85155
    86 p_info Forcefully building kernel: $FORCE_KERNEL
    87 p_info Forcefully building world : $FORCE_WORLD
    88 
    89 NANOBSD_EXTRA=${NANOBSD_EXTRA:-''}
    90 
    91 if [ ! -r "${NANOBSD}" ]; then
    92   p_err ${NANOBSD} does not exists
    93   exit 1
    94 fi
    95 
    96 if [ ! -x "${NANOBSD}" ]; then
    97   NANOBSD="sh ${NANOBSD}"
    98 fi
    99 
    100 # Find object directory
    101 OBJDIR="/usr/obj/nanobsd.${NANO_NAME}"
    102 
    103 if [ -d "${OBJDIR}" ]; then
    104   NANOBSD_FLAGS=""
    105  
    106   # Detect succesfull buildworld
    107   tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
    108   if [ $? -eq 0 -a ${FORCE_WORLD} = "no" ]; then
    109      p_info NO building of world
    110      NANOBSD_FLAGS="${NANOBSD_FLAGS} -w"
    111   fi 
    112 
    113   # Detect succesfull buildkernel
    114   tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
    115   if [ $? -eq 0 -a ${FORCE_KERNEL} = "no" ]; then
    116      p_info NO building of kernel
    117      NANOBSD_FLAGS="${NANOBSD_FLAGS} -k"
    118   fi 
    119 
    120 else
    121   p_warn Nothing yet, starting fresh
    122   NANOBSD_FLAGS=""
    123 fi
    124 
    125 # Provide verbose output by default
    126 COMMAND="${NANOBSD} ${NANOBSD_FLAGS} -c ${NANO_CFG_FILE} -v ${NANOBSD_EXTRA}"
    127 f_time ${COMMAND}
    128 RETVAL=$?
    129 
    130 # Verify on build failures
    131 tail -10 ${OBJDIR}/_.bw | grep 'World build completed'
    132 if [ $? -eq 1 ]; then
    133   p_err Building world FAILED, check ${OBJDIR}/_.bw
    134 fi
    135 tail -10 ${OBJDIR}/_.bk | grep 'Kernel build for .* completed'
    136 if [ $? -eq 1 ]; then
    137   p_err Building kernel FAILED, check ${OBJDIR}/_.bk
    138 fi 
    139 if [ $RETVAL -ne 0 ]; then
    140   p_err "Errors in building NanoBSD Image ($RETVAL)"
    141 fi
    142 p_info End time: `date`
    143 exit ${RETVAL}
Note: See TracChangeset for help on using the changeset viewer.