#!/bin/sh
# Script/function to remove desktop icons for all partitions of a certain device
# device name (without "/dev/") passed as argument
## yet another dubious Dougal script for Puppy Linux, April 2007
## Latest update: June 12th (fixed finding of mountpoints)
# now removing entries from globicons

[ "$1" ] || exit
ADEV="$1"

## files used:
PINFILE=/root/Choices/ROX-Filer/PuppyPin
#PINFILE=$HOME/.config/rox.sourceforge.net/ROX-Filer/pb_Default
FSTAB=/etc/fstab

#APPDIR="`dirname $0`"
# list of all mountpoints in fstab matching ADEV (but not those commented out)
MNTPNTS="`grep -F "/dev/$ADEV" $FSTAB | grep -F -v '#' | tr '\t' ' ' | tr -s ' '| cut -d' ' -f2`"
## Above isn't good, since when running in two daemons fstab is already cleaned.
#MNTPNTS="`grep -F ">/mnt/$ADEV" $PINFILE |cut -d'>' -f2 | cut -d'<' -f1 | tr '\n' ' '`"
##  to avoid removing links users set to dirs on the device...will only pass
##+ ">/mnt/$ADEV" + 0 or more alphanumeric chars until the "<" -- no "/"!
#MNTPNTS="`grep -E ">/mnt/$ADEV[[:alnum:]]*<" $PINFILE |cut -d'>' -f2 | cut -d'<' -f1 | tr '\n' ' '`"

# list of all mountpoints currently linked on desktop
#CRRNTLINKS="`grep -E '>/mnt/[a-z]?[[:alnum:]]+<' $PINFILE | cut -d'>' -f2 | cut -d'<' -f1 | tr '\n' ' '` " # note space at end

## SOAP code for removal of icons:
REMOVEHEAD='<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
 <env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
  <PinboardRemove>'

REMOVETAIL='  </PinboardRemove>
 </env:Body>
</env:Envelope>'

ICONHEAD='<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2001/12/soap-envelope">
 <env:Body xmlns="http://rox.sourceforge.net/SOAP/ROX-Filer">
  <UnsetIcon>'

ICONTAIL='  </UnsetIcon>
 </env:Body>
</env:Envelope>'

## go through the relevant mountpoints and remove icons
for APNT in $MNTPNTS
do
  # remove from desktop
  echo -e "$REMOVEHEAD\n   <Path>$APNT</Path>\n$REMOVETAIL" | rox -R
  # remove from globicons
  echo -e "$ICONHEAD\n   <Path>$APNT</Path>\n$ICONTAIL" | rox -R
done

exit
