
runs in root had menu enter with kdesu in command line. will test (adhok method) for mount a nd umount state and ask what to do and clean up desktop when done. This was just a learning thing so its got wiead stuff in it, but it does work. I am now learn better ways of doing the same things.
##!/bin/bash
#
#************************************************************************************************
# *(pupthai)
# *Script name: DriveUM
# *Script Purpose: Mount or Umount the (sda1) and (sda2) drives in the fstab locations.
# * Special: Not for general use and distribution just for learning to script
# * related info from fstab
# * /dev/sda1 /home/<user>/Share ntfs-3g defaults,user,auto,UTF-8 1 2
# * /dev/sda2 /home/<user>/ExtRepos ntfs-3g defaults,user,auto,UTF-8 1 2
#*************************************************************************************************
#declare
clear
Status=" " MtS=" " MtE=" " Me=$USER Mu=" " Tm="DriveUM"
Ccu="CleanUp has been run" CTks="Thanks for using DriveUM" Mti="What would you like to do?"
Im1="Mounting and UnMounting the Share and Repos drives in the assigned locations in the home direactory."
#*************************************************************************************************
#Introduction
kdialog --title "$Tm" --passivepopup "$Im1" 4
#
#*************************************************************************************************
#read and set: read and test Mount condition codes for Share and ExtRepos
#method is ad hok there are better ways, file must be present on partitions to test for.
#If drive not mounted the present direactory will not have those files.
test -f /home/$Me/Share/mntestShare
MtS=$?
test -f /home/$Me/ExtRepos/mntestExtRepos
MtE=$?
#
#*************************************************************************************************
#Set Status: Set bits for Status and Case dialog
if [ "$MtS" = "0" ] && [ "$MtE" = "0" ]
then
Status="0"
elif [ "$MtS" = "0" ] && [ "$MtE" = "1" ]
then
Status="1"
elif [ "$MtS" = "1" ] && [ "$MtE" = "0" ]
then
Status="2"
elif [ "$MtS" = "1" ] && [ "$MtE" = "1" ]
then
Status="3"
fi
#
#************************************************************************************************
#Report Status
#Declare Case and Status dialog: Status and Q statements Array
C=("Case 0: Both the Share and ExtRepos Drives are mounted" "Case 1: Only the Share Drive is mounted" "Case 2: Only the ExtRepos Drive is mounted" "Case 3: Nether Drive is yet mounted")
Ca=("Un-Mount both Drives, Please?" "Mount the ExtRepos Drive as well?" "Mount the Share Drive as well?" "Mount both Drives?")
Cb=("Un-Mount the Share Drive only?" "Un-Mount the Share Drive and Mount the ExtRepos Drive?" "Un-Mount the ExtRepos Drive and Mount the Share Drive?" "Mount the Share Drive only?")
Cc=("Un-Mount the ExtRepos Drive only?" "Un-Mount the Share Drive as well?" "Un-Mount the ExtRepos Drive as well?" "Mount the ExtRepos Drive only?")
#Closing Msg's
Cma=("Both Drives have been Un-Mounted." "The ExtRepos Drive has been Mounted as well." "The Share Drive has been Mounted as well" "Both Drives have been Mounted.")
Cmb=("The Share Drive has been Un-Mounted." "Share Drive is Un-Mounted and ExtRepos is Mounted." "Share Drive is Mounted and ExtRepos is Un-Mounted." "Only the Share Drive has been mounted.")
Cmc=("The ExtRepos Drive has been Un-Mounted." "The Share Drive has been Un-Mounted as well." "The ExtRepos Drive has been Un-Mounted as well." "Only the ExtRepos Drive has been Mounted.")
# **********************************************************************************************
#Case in work
case $Status in
# Case 0: Both the Share and ExtRepos Drives are mounted
0) kdialog --title "$Tm" --passivepopup "${C[0]}" 3
Ac=`kdialog --menu "$Mti" a "${Ca[0]}" b "${Cb[0]}" c "${Cc[0]}"`
case $Ac in
a) umount /dev/sda1
umount /dev/sda2
kdialog --title "$Tm" --passivepopup "${Cma[0]}" 2
;;
b) umount /dev/sda1
kdialog --title "$Tm" --passivepopup "${Cmb[0]}" 2
;;
c) umount /dev/sda2
kdialog --title "$Tm" --passivepopup "${Cmc[0]}" 2
;;
esac
;;
# Case 1: Only the Share Drive is mounted
1) kdialog --title "$Tm" --passivepopup "${C[1]}" 3
Ac=`kdialog --menu "$Mti" a "${Ca[1]}" b "${Cb[1]}" c "${Cc[1]}"`
case $Ac in
a) mount /dev/sda2
kdialog --title "$Tm" --passivepopup "${Cma[1]}" 2
;;
b) umount /dev/sda1
mount /dev/sda2
kdialog --title "$Tm" --passivepopup "${Cmb[1]}" 2
;;
c) umount /dev/sda1
kdialog --title "$Tm" --passivepopup "${Cmc[1]}" 2
;;
esac
;;
# Case 2: Only the ExtRepos Drive is mounted
2) kdialog --title "$Tm" --passivepopup "${C[2]}" 3
Ac=`kdialog --menu "$Mti" a "${Ca[2]}" b "${Cb[2]}" c "${Cc[2]}"`
case $Ac in
a) mount /dev/sda1
kdialog --title "$Tm" --passivepopup "${Cma[2]}" 2
;;
b) umount /dev/sda2
mount /dev/sda1
kdialog --title "$Tm" --passivepopup "${Cmb[2]}" 2
;;
c) umount /dev/sda2
kdialog --title "$Tm" --passivepopup "${Cmc[2]}" 2
;;
esac
;;
# Case 3: Nether Drive is yet mounted
3) kdialog --title "$Tm" --passivepopup "${C[3]}" 3
Ac=`kdialog --menu "$Mti" a "${Ca[3]}" b "${Cb[3]}" c "${Cc[3]}"`
case $Ac in
a) mount /dev/sda1
mount /dev/sda2
kdialog --title "$Tm" --passivepopup "${Cma[3]}" 2
;;
b) mount /dev/sda1
kdialog --title "$Tm" --passivepopup "${Cmb[3]}" 2
;;
c) mount /dev/sda2
kdialog --title "$Tm" --passivepopup "${Cmc[3]}" 2
;;
esac
;;
esac
#**************************************************************************************************
#Closing
sleep 2
dcop --user $Me kdesktop KDesktopIface rearrangeIcons
sleep 1
kdialog --title "$Tm" --passivepopup "$Ccu" 2
kdialog --title "$Tm" --passivepopup "$CTks" 5
exit
It was fun I even made my own desktop icon for it out of an old picture of my car.