File wcs-cg14-tool of Package wcs-au-quotidien

#!/bin/sh -e

APPDIR=/var/lib/wcs-au-quotidien

COMMAND=$1
VHOST=$2
FILENAME=$3

if [ -z "$VHOST" ]; then
    echo "Usage: $0 export vhost"
    echo "       $0 import vhost filename.tgz"
    exit 2
fi
APPDIR=$APPDIR/$VHOST
cd $APPDIR || exit 2
su wcs-au-quotidien -c /usr/bin/id >/dev/null || exit 2

OUTFILE=/tmp/$VHOST-datas-`date +%Y%m%d-%H%M%S`-$$.tgz

tar_c() {
    cd $APPDIR
    tar zcf $OUTFILE categories roles formdefs workflows models links themes
    echo "$OUTFILE created"
}

tar_x() {
    tar ztf "$FILENAME" > /dev/null || exit 2
    cd $APPDIR
    echo "extract $FILENAME in $APPDIR:"
    tar zxvf "$FILENAME" || exit 2
    chown -R wcs-au-quotidien categories roles formdefs workflows models links themes
    echo "synchronize sql tables"
    su wcs-au-quotidien -c /usr/bin/python << EOPY
import os
from wcs import publisher
from wcs.formdef import FormDef

APP_DIR = '/var/lib/wcs-au-quotidien'
VHOST = '$VHOST'

pub = publisher.WcsPublisher.create_publisher()
pub.app_dir = os.path.join(APP_DIR, VHOST)

for f in FormDef.select():
    print f.name.strip(), ' ... ',
    f.store()
    print 'ok'
EOPY
    chown -R wcs-au-quotidien formdefs # superstition ...
}

case "$1" in
    export)
        tar_c
        ;;
    import)
        tar_x
        ;;
    *)
        echo "Usage: $0 export vhost"
        echo "       $0 import vhost filename.tgz"
        exit 2
esac