#!/bin/bash

if [ $# -ne 2 ]
then
  echo Usage: $(basename $0) '<hosting user> <host server>'
  exit 1
fi

user=$1
host=$2

# 0. SVN export

cd /tmp
if [ -d phpwebgallery ]
then
  rm -rf phpwebgallery
fi
svn export http://svn.gna.org/svn/phpwebgallery/website phpwebgallery
cd phpwebgallery

# 1. preparation

iconv -f iso-8859-1 -t utf8 -o index.html index.iso-8859-1.html
iconv -f iso-8859-1 -t utf8 -o fre/index.html fre/index.iso-8859-1.html
iconv -f iso-8859-1 -t utf8 -o eng/index.html eng/index.iso-8859-1.html
iconv -f iso-8859-1 -t utf8 -o doc/index.html doc/index.iso-8859-1.html

perl -pi -e 's/iso-8859-15?/utf-8/g' \
  index.html fre/index.html eng/index.html doc/index.html

# 2. send files through network
rsync -avr \
      --rsh="ssh" \
      * \
      $user@$host:/home/pwg/public_html
