#!/bin/bash
# AQ
# 20111101

for device in /dev/disk/by-id/usb*part*; do
    udisks --mount $device
done

echo
MOUNTPOINT=`mount | grep -e "/media/" | awk '{print $3}'`
if [ -z "$MOUNTPOINT" ]; then
    echo "External media not connected"
    sleep 3
    echo
    exit 1
fi

echo "Creating an archive with log files in $MOUNTPOINT"
tar -cjf $MOUNTPOINT/logfiles.tar.bz2 /home/terminal/atm/log/
echo
if [ $? -eq 0 ] ; then
        echo "Archive Created"
else
        echo "Error while creating archive"
fi
echo "Device sync"
sync
sleep 3
echo "Completed"

for device in /dev/disk/by-id/usb*part*; do
    udisks --unmount $device
done

exit 0
