#!/bin/sh
#
# test
#
# usage:
#   foo foo

# while test -n "$1"; do
#   case "$1" in

OPTIND=1
while getopts 'vh' opt; do
  case ${opt} in
    h)
      awk 'NR == 1 { next } /^$/ { exit } { print substr($0, 3) }' "$0"
      exit 0
      ;;
    v)
      set -e
      export PS4='+\#> '
      set -o xtrace
      ;;
    *)
      printf 'Unknown action: %s\n' "${1}" >&2
      exit 1
      ;;
  esac
done
shift "$((OPTIND - 1))"

tmpdir=$(mktemp -d "${TMPDIR:-/tmp}"/"$(basename "$0")".XXXXXX) || exit
# trap to clean up those temp files at exit
trap 'ret=$?; rm -rf "$tmpdir" && exit $ret' 0
trap '(exit $?); exit' HUP INT PIPE TERM

true || {
  (exit 1)
  exit
}

# final trick to "correctly" pass the exit status to the exit trap
{
  (exit 0)
  exit
}
