#!/bin/sh

hostname=stone.home

if test "$1" = all || test "$1" = dist && ! test -d out
then
  echo "find . | cpio -H newc -o > /tmp/gopherhole.cpio"
  find . | cpio -H newc -o > /tmp/gopherhole.cpio
  echo mkdir -p public_gopher public_xhtml
  mkdir -p public_gopher public_xhtml
  echo cp -fr static/* public_gopher/
  cp -fr static/* public_gopher/
  echo mv /tmp/gopherhole.cpio public_gopher/software/gopherhole/
  mv /tmp/gopherhole.cpio public_gopher/software/gopherhole/
  echo "nroff templates/about.roff > public_gopher/about.txt"
  nroff templates/about.roff > public_gopher/about.txt
  echo "nroff templates/meet.roff > public_gopher/meet.txt"
  nroff templates/meet.roff > public_gopher/meet.txt
  echo "nroff templates/articles/instr.roff > public_gopher/articles/instr.txt"
  nroff templates/articles/instr.roff > public_gopher/articles/instr.txt
  echo cp -fr public_gopher/* public_xhtml/
  cp -fr public_gopher/* public_xhtml/
  echo cp -fr gopher/* public_gopher/
  cp -fr gopher/* public_gopher/
  echo cp -fr xhtml/* public_xhtml/
  cp -fr xhtml/* public_xhtml/
fi

if test "$1" = clean
then
  echo rm -fr public_*
  rm -fr public_*
fi

if test "$1" = dist
then
  which rsync > /dev/null
  if test $? -ne 0
    then
      echo Error: remote sync is unavailable >&2
      exit 1
  fi
  if test -z "$RSYNC_PASSWORD"
  then
    read -p "Password for ${hostname}: " RSYNC_PASSWORD
    export RSYNC_PASSWORD
  fi
  echo rsync -a --delete public_gopher/ rsync://${hostname}/gopherhole/
  rsync -a --delete public_gopher/ rsync://${hostname}/gopherhole/
  echo rsync -a --delete public_xhtml/ rsync://${hostname}/website/
  rsync -a --delete public_xhtml/ rsync://${hostname}/website/
fi
