#!/bin/sh
set -e || exit "$?"
case $ZSH_VERSION in ?*) alias -g '${1+"$@"}="$@"';; esac

match_() {
  (eval "
   case \$2 in
     $1);;
     *) exit 100;;
   esac")
}

die_() {
  if set x "${program_+$program_: }$*" &&
     case $2 in
       -*|*\\*) cat <<EOT
$2
EOT
         ;;
       *) echo "$2";;
     esac >&2
    then exit 100
    else exit 100
  fi
}

echo_() {
  case $* in
    -*|*\\*)
      # Avoid echo's nonportable behavior for switches and escapes.
      cat <<EOT
$*
EOT
      ;;
    *)
      # Use echo when we can get away with it, since it's typically a builtin.
      echo "$*";;
  esac
}

unset_() {
  while test "$#" != 0; do
    { eval "$1=" &&
      unset "$1" &&
      shift
    } || return "$?"
  done
}

if test 1 != "$#"; then
  die_ 'usage: package/elsewhere /path/to/dir'
fi

mkdir "$1"
unset_ x
x=`sed q < conf-compile/package_home`
ln -s "$x" "$1/.real"

tar -cf "$1/conf-compile.tar" conf-compile/.
cd "$1"
tar -xf conf-compile.tar
rm -f conf-compile.tar

x=conf-compile/package_home
{ if (match_ '/*' "$1")
    then echo_ "$1"
    else pwd
  fi &&
  sed 1d < "$x"
} > "$x{new}"
mv -f "$x{new}" "$x"

for x in \
    package \
    src; do
  ln -s .real/"$x" ./
done


syntax highlighted by Code2HTML, v. 0.9.1