clean_desk_icons 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. #BK called from /root/.xinitrc
  3. #v410 remove icons when drives removed.
  4. #v410 omit icon if optical drive; defer it to pup_event_frontend_d
  5. #w014 bugfix, refresh icons if removable drive swapped when PC turned off.
  6. #120131 rodin.s: internationalized. See warning about "Size:" translation.
  7. #120213 /var/local/pup_event_icon_change_flag path changed from /tmp.
  8. #120222 internationalization introduced bug, fixed it (caused drive icons to redraw every time X starts).
  9. # i18n gettext
  10. TEXTDOMAIN=clean_desk_icons
  11. export TEXTDOMAIN
  12. . /usr/bin/gettext.sh
  13. export LANG=C
  14. . /etc/eventmanager #has RAMSAVEINTERVAL, ICONDESK, ICONPARTITIONS, HOTPLUGNOISY, HOTPLUGON, FLOPPYICON.
  15. ePUPPYPIN="`grep -v '/root/.pup_event/drive_' /root/Choices/ROX-Filer/PuppyPin | grep -v '</pinboard>'`"
  16. #v403 /usr/sbin/eventmanager creates this file if all icons need to be rebuilt...
  17. #120213 note, /var/local/pup_event_icon_change_flag is written to by /usr/sbin/xorgwizard, video-wizard, eventmanager.
  18. if [ -f /var/local/pup_event_icon_change_flag ];then #120213 path changed from /tmp
  19. rm -f /var/local/pup_event_icon_change_flag
  20. echo "$ePUPPYPIN" > /root/Choices/ROX-Filer/PuppyPin
  21. echo '</pinboard>' >> /root/Choices/ROX-Filer/PuppyPin
  22. rm -rf /root/.pup_event/drive_* 2>/dev/null
  23. exit
  24. fi
  25. #remove all invalid drive icons off desktop...
  26. echo -n "" > /tmp/pup_event_ok_pin
  27. if [ "$ICONDESK" = "false" ];then
  28. #leave single 'drives' icon on desktop...
  29. grep '/root/.pup_event/drive_drives' /root/Choices/ROX-Filer/PuppyPin >> /tmp/pup_event_ok_pin
  30. rm -rf /root/.pup_event/drive_[^d]* 2>/dev/null #delete all except drive_drives.
  31. else
  32. #v410 Delete drive_ directories for removed drives...
  33. #note, this will not detect removed optical and floppy discs (see /sbin/pup_event_frontend_d).
  34. #Get the directory names for the drives only, not the partitions, to avoid redundant iterations through the for-loop.
  35. DIR_DRVS="`ls -1 /root/.pup_event | sed 's/drive_//' | grep -E "^hd.$|^sd.$|^sr|^mmcblk.$" | tr '\n' ' '`"
  36. for ONEDRV in $DIR_DRVS
  37. do
  38. [ ! -d /root/.pup_event/drive_$ONEDRV ] && continue
  39. [ ! -e /sys/block/${ONEDRV} ] && rm -rf /root/.pup_event/drive_${ONEDRV}*
  40. done
  41. for ONEDRV in `ls -1 /sys/block | grep -vE 'loop|ram' | tr '\n' ' '`
  42. do
  43. odPATTERN="/root/.pup_event/drive_${ONEDRV}"
  44. OKDRV="`grep "$odPATTERN" /root/Choices/ROX-Filer/PuppyPin`"
  45. if [ "$OKDRV" = "" ];then
  46. rm -rf /root/.pup_event/drive_${ONEDRV}* 2>/dev/null
  47. else
  48. [ ! -d /root/.pup_event/drive_${ONEDRV} ] && continue #v408
  49. DRVCUT="`echo -n "$ONEDRV" | cut -c 1,2`" #v410
  50. [ "$DRVCUT" = "sr" ] && continue #v410 omit icon if optical drive; defer it to pup_event_frontend_d
  51. [ "$DRVCUT" = "sc" ] && continue #v410 scd, ditto.
  52. if [ "$DRVCUT" = "hd" ];then
  53. MEDIACAT="`cat /proc/ide/${ONEDRV}/media`"
  54. [ "$MEDIACAT" = "cdrom" ] && continue #v410 omit icon if optical drive; defer it to pup_event_frontend_d
  55. fi
  56. #w014 user may have swapped removable drives while pc turned off...
  57. #120222 above is fixed, however go one step further and eliminate dependency on the translation of "Size:"...
  58. DRVMODEL1="`grep -o '<Summary>.*</Summary>' /root/.pup_event/drive_${ONEDRV}/AppInfo.xml | cut -f 2-9 -d ':' | cut -f 1 -d '<' | tr -s ' ' | rev | cut -f 3-99 -d ' ' | rev | sed -e 's%^ %%'`"
  59. #note, this must be same as done in /sbin/probedisk...
  60. DRVMODEL2="`cat /sys/block/$ONEDRV/device/vendor | tr -s ' '``cat /sys/block/${ONEDRV}/device/model | tr -s ' '`"
  61. if [ "$DRVMODEL1" != "$DRVMODEL2" ];then
  62. rm -rf /root/.pup_event/drive_${ONEDRV}* 2>/dev/null
  63. continue
  64. fi
  65. echo "$OKDRV" >> /tmp/pup_event_ok_pin
  66. fi
  67. done
  68. fi
  69. #if [ "`cat /tmp/pup_event_ok_pin`" != "" ];then
  70. echo "$ePUPPYPIN" > /root/Choices/ROX-Filer/PuppyPin
  71. cat /tmp/pup_event_ok_pin >> /root/Choices/ROX-Filer/PuppyPin
  72. echo '</pinboard>' >> /root/Choices/ROX-Filer/PuppyPin
  73. #fi
  74. ###END###