#!/bin/sh
#
# If you are running on a Kubuntu desktop and you would like to have
#  the same desktop on the usb key, you can do so by running this
#  script.  You must be root.
#
. ./config

if [ ! `whoami` = "root" ] ; then
  echo ""
  echo "You need to be root to run this shell script"
  echo ""
  exit 1
fi
echo " "
echo "This script will overwrite a number of directories on the USB key"
echo "for example: .kde .ssh .bashrc .bash_logout .gnupg .mozilla ..."
echo " "
echo "Answer yes to continue "
read a
if [ "$a" != "yes" ] ; then
  echo "Device $USB_DEV unchanged"
  exit 1
fi

if [ ! -d ${MOUNT_POINT}/home-rw ] ; then
   mount ${USB_DEV}3 ${MOUNT_POINT}/home-rw
fi
if [ ! -d ${MOUNT_POINT}/home-rw ] ; then
  echo "Mount of home-rw USB partition failed."
  echo "Please pre-mount the USB stick and run this script again."
  exit 1
fi
cd ${MOUNT_POINT}/home-rw
if [ $? -ne 0 ] ; then
  echo "Could not cd to home-rw USB partition"
  exit 1
fi

mkdir -p ubuntu
chown 1000:1000 ubuntu
cd ubuntu
# Do files
for i in .bashrc .bash_logout ; do 
  if [ -f ${MY_HOME}/$i ] ; then
     cp -f ${MY_HOME}/$i . 
     chown 1000:1000 $i
  fi
done
#
# Special case for .kde
#
echo "Copying .kde ..."
rm -rf .kde
mkdir -p .kde
cd .kde
cp -a $MY_HOME/.kde/share .
cd ..
chown -R 1000:1000 .kde

# Do directories
for i in .gnupg .ssh .mozilla Desktop ; do 
  if [ -d ${MY_HOME}/$i ] ; then
     rm -rf $i
     cp -a ${MY_HOME}/$i . 
     chown -R 1000:1000 $i
  fi
done
sync
sync
