#!/bin/sh

echo "Replace event.d file with new if used in previous version"
if [ -e /tmp/relocateswap_bak ];
 then
  # Set Upstart event
   cp /opt/flopswap/script/relocateswap /etc/event.d/relocateswap

  # Set swap_sd as 1 (for latest CSSU upstart)
   sed -i -e "s@swap_sd=\"0\"@swap_sd=\"1\"@" /etc/default/mount-opts-overwrite
    if [ $? -ne 0 ] ;
     then
  echo "swap_sd=\"1\"" >> /etc/default/mount-opts-overwrite
  echo "Added swap_sd 1 EOF"
    else
  echo "Sucessfully replaced swap_sd with 1"
    fi
fi

# just in case, clean up any existing flopswap.sudoers file
echo "Remove sudoers"
rm /etc/sudoers.d/flopswap.sudoers

# now, create the file
echo "Create sudoers"

echo "user ALL = NOPASSWD: /opt/flopswap/script/*
user ALL = NOPASSWD: /opt/flopswap/bin/flopswap" > /etc/sudoers.d/flopswap.sudoers

echo "Updating sudoers"
update-sudoers

echo "Updating icon cache"
gtk-update-icon-cache -f /usr/share/icons/hicolor

exit 0
