#!/bin/bash
#
# recordum_repo2usb
#
# v0.1 2015-11-20 RE
#
# syncs portal repository for packages/patches/features to USB pen stick

MYSELF=$( basename $0 )

USBDIR='/media/usb/debian'
REMOTE='root@portal.recordum.com'
WEBDIR='/srv/www/htdocs/webinterface/debian/'

if [[ $UID -gt 0 ]]
then
    echo "$MYSELF needs to be run as superuser. You are $USER."
    exit 1
fi
if [[ ! -d ${USBDIR} ]]
then
    echo "USB target missing <-> $USBDIR"
    exit 2
fi

cat <<EOF

SYNC packages:

EOF
if ! su - recordum -c "rsync -rthv --delete --stats ${REMOTE}:${WEBDIR}/packages/ ${USBDIR}/packages/"
then
    echo "SYNC packages: failed"
    exit 3
fi
cat <<EOF

SYNC patches:

EOF
if ! su - recordum -c "rsync -rthv --delete --stats ${REMOTE}:${WEBDIR}/patches/ ${USBDIR}/patches/"
then
    echo "SYNC patches: failed"
    exit 4
fi
cat <<EOF

SYNC features:

EOF
if ! su - recordum -c "rsync -rthv --delete --stats ${REMOTE}:${WEBDIR}/features/ ${USBDIR}/features/"
then
    echo "SYNC features: failed"
    exit 5
fi

exit 0
