続 build.sh wrapper script

以前晒したやつだと同一 MACHINE で release しながら kernel できなかったので更新。

#!/bin/sh

progname=$0

usage() {
  echo "Usage: ${progname} <machine> <date> <operation>"
  exit 1
}

if [ "x$1" = x ]; then
  usage
fi
target_machine=$1
shift

if [ "x$1" = x ]; then
  usage
fi
build_date=$1
shift

if [ "x$1" = x ]; then
  usage
fi
full_operation=$1
operation=`echo ${full_operation} | sed -e 's/\([^=]*\)[=].*/\1/'`
shift

LANG=C; export LANG
LC_ALL=C; export LC_ALL
LC_CTYPE=C; export LC_CTYPE

case ${operation} in
install|installmodules)
  if [ `id -u` -ne 0 ]; then
    if [ -x /usr/pkg/bin/sudo ]; then
      sudo_cmd=/usr/pkg/bin/sudo
    else
      echo "Please run as root user."
      exit 1
    fi
  fi
  ;;
*)
  ;;
esac
build_opt="${build_opt} -U"

parallel_make=true
while true
do
  if [ $# -eq 0 ]; then
    break
  fi

  opt=$1
  echo ${opt} | fgrep " " > /dev/null 2>&1
  if [ $? -eq 0 ]; then
    opt="\"${opt}\""
  fi
  build_opt="${build_opt} ${opt}"
  if [ "${opt}" = "-x" ]; then
    parallel_make=false
  fi
  shift
done
if [ "${parallel_make}" = "true" ]; then
  build_opt="${build_opt} -j 2"
fi

${sudo_cmd} time ./build.sh -m ${target_machine} \
  -D /home/snapshot/${build_date}/root/${target_machine} \
  -R /home/snapshot/${build_date}/release \
  -T /usr/local/netbsd-tools/${target_machine} \
  ${build_opt} \
  ${full_operation} \
  2>&1 | tee ${build_date}-${target_machine}-${operation}.log
retval=$?
exit ${retval}