- Tries to determine the offset to the USB scsi devices if a machine already has some SCSI disks. It does this by grabbing all /dev/sd* entries from mount and seeing if they are in /etc/fstab, incrementing the scsi offset if they are.
- Allows for a relocated KDE Desktop directory by reading the kdeglobals file. It assumes kdeglobals is in $HOME/.kde/share/config/kdeglobals. Perhaps this should be made configurable.
- Creates the desktop file as the user. This was needed in our NFS /home directory environment where root did not have write permission in the home directory.
Orion
--- /opt/src/usb-mount-v0.3/image/usr/local/bin/usb-mount 2003-09-04
02:10:36.000000000 -0600
+++ usb-mount-0.4/usb-mount 2003-09-17 12:10:12.000000000 -0600
@@ -62,7 +62,17 @@
}
function scsiDevFromScsiUsb {
- echo $1 | awk -F"[-/]" '{ n=$(NF-1); print "/dev/sd"
substr("abcdefghijklmnopqrstuvwxyz", n+1, 1) "1" }'
+ #Determine offset to scsi device file from mount and /etc/fstab
+ scsibase=0
+ for dir in `mount | sort | awk '$1 ~ "^/dev/sd" { print $3}'`
+ do
+ if grep -q $dir /etc/fstab
+ then
+ let scsibase++
+ fi
+ done
+
+ echo $1 | awk -F"[-/]" -v offset=$scsibase '{ n=$(NF); print "/dev/sd"
substr("abcdefghijklmnopqrstuvwxyz", n+offset, 1) "1" }'
}
function allAttachedScsiUsb {
@@ -135,7 +145,15 @@
local user="$1"
local name="$(basename $2)"
local home="$(eval echo ~$user)"
- echo "$home/Desktop/usb-storage-$name.desktop"
+ local kdeglobals="$home/.kde/share/config/kdeglobals"
+ local desktop="$home/Desktop"
+ local kdedesktop
+ if [ -f $kdeglobals ]
+ then
+ kdedesktop=`awk -F= '$1 == "Desktop" { print $2 }' $kdeglobals`
+ desktop=${kdedesktop:-$desktop}
+ fi
+ echo "$desktop/usb-storage-$name.desktop"
}
function makeDesktopFile {
@@ -151,7 +169,7 @@
feedback "Creating desktop file $desktopFile"
home=$(eval echo ~$user)
- cat > "$desktopFile" <<-EOF
+ su -s /bin/sh $user -c "cat > $desktopFile" <<-EOF
[Desktop Action Unmount]
Exec=/usr/local/bin/usb-umount $mountPoint
Name=Unmount
@@ -191,11 +209,9 @@
esac
feedback "Altering $desktopFile icon to $icon"
tmpfile=$(dirname $desktopFile)/.$(basename $desktopFile).old
- mv $desktopFile $tmpfile
- awk -vicon=$icon '
- { sub("^Icon=.*$", "Icon=" icon, $0);
- print $0; } ' $tmpfile > $desktopFile
- rm $tmpfile
+ su -s /bin/sh $user -c "mv $desktopFile $tmpfile"
+ su -s /bin/sh $user -c "awk -vicon=$icon '{ sub(\"^Icon=.*$\", \"Icon=\" icon,
\$0); print \$0; }' $tmpfile > $desktopFile"
+ su -s /bin/sh $user -c "rm $tmpfile"
}
