#!/bin/sh

# $Id: zip-fetch 25873 2008-10-14 12:12:52Z joostvb $
# $URL: https://infix.uvt.nl/its-id/trunk/sources/zip-fetch/zip-fetch $

# Copyright (C) 2007, 2008 Tilburg University http://www.uvt.nl/
#
# This file is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
#
# You should have received a copy of the GNU GPL along with this file, see
# e.g. the file named COPYING.  If not, see <http://www.gnu.org/licenses/>.

set -e

varroot=${ZIP_FETCH_ROOT:-/var/php}

vhost="$1"   # sans-upk
sourcehost="$2"  # anne@radix
sourcefile="$3"  # upk.z
docroot="$4" # /var/www/$vhost/http

test -d $varroot/$vhost/var/staging || mkdir -p $varroot/$vhost/var/staging
cd $varroot/$vhost/var/staging
scp -q $sourcehost:$sourcefile . > /tmp/$vhost.log 2>&1
unzip -qq $sourcefile >> /tmp/$vhost.log 2>&1
rm -r $varroot/$vhost/var/yesterday
mv $docroot $varroot/$vhost/var/yesterday
mv $varroot/$vhost/var/staging $docroot

