#!/bin/bash -x
# script to copy the power logs to a USB stick

# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
    echo "This script must be run as root. Please type 'su' and issue command again." 1>&2
    exit 1
fi

mkdir -p /tmp/usb
mount /dev/sda1 /tmp/usb
if [ $? -ne 0 ];then
  echo "not able to mount usb stick"
else
  DEPLOY=
  if [ -f /root/deployment ];then
    DEPLOY=`cat /root/deployment`
  fi
  acpower -dp > /tmp/usb/${DEPLOY}acpower.txt
  tar czf /tmp/usb/${DEPLOY}acpower.tgz /home/olpc/power-logs 
  umount /tmp/usb
  echo "================================================"
  echo 
  echo "Report, and tarred, zipped data written to USB stick"  
  echo 
  echo "================================================"
fi
