#!/bin/sh
set -e

if test '(' "$2" = 'all' ')' -o '(' $# -eq 0 -a -z "$SERVER" ')'; then
  for website in $(ls --ignore='scripts' --ignore='sshkeys' /web); do
    source "$0" "$website"
  done
  echo "finished all uploads"
  exit
fi

function upload {
  echo "start uploading to $1"
  echo -n "
    cd /
    lcd '/web/$1'
    put -Rp . .
      " | "/web/scripts/sftp-$1.sh" -b -
  echo "finished uploading to $1"
}

if test $# -eq 0; then
  upload "$SERVER"
elif test "$2" != 'none'; then
  for website in "$@"; do
    upload "$website"
  done
fi
