create desktop item for all harddrives mounted.

New features which should be implemented in Porteus; suggestions are welcome. All questions or problems with testing releases (alpha, beta, or rc) should go in their relevant thread here, rather than the Bug Reports section.
Proxx
White ninja
White ninja
Posts: 10
Joined: 11 May 2011, 20:13
Location: Home

create desktop item for all harddrives mounted.

Post#1 by Proxx » 15 May 2011, 19:29

crashman requested a script to create desktop icons for all mounted harddrives.

i have started on the script it is partially ready. the links does not work.
there are frends with me at home. and to not bore them to death i cannot finish the script this time.

Code: Select all

#!/bin/sh

function fadd {
for i in $(cat /etc/mtab |cut -d' ' -f1 |grep -v "sysfs" |grep -v "proc" |grep -v "fusectl" |grep -v "aufs") ;do # i think that this isnt the best way. (mayby /proc/self/mount* or mtab/fstab is a better solution)
	PICON=0
#	if [ ! -f ~/Desktop/$hdp.desktop ];then
      hdp=$(echo "$i" | cut -d'/' -f3)
      echo "[Desktop Entry]" >> ~/Desktop/$hdp.desktop
      filesys=$(cat /etc/mtab |grep $hdp |cut -d' ' -f3)
      if [ "$filesys" == "vfat" ];then echo "Icon=hd" >> ~/Desktop/$hdp.desktop ;PICON=1 ;fi
      if [ "$filesys" == "fuseblk" ];then echo "Icon=hd-windows" >> ~/Desktop/$hdp.desktop ;PICON=1 ;fi
      if [[ "$filesys" == ext? ]];then echo "Icon=hd-linux" >> ~/Desktop/$hdp.desktop ;PICON=1 ;fi
      if [ "$filesys" == "iso9660" ];then echo "Icon=cdimage" >> ~/Desktop/$hdp.desktop ;PICON=1 ;fi
	  if [ "$PICON" == "0" ];then echo "Icon=hd" >> ~/Desktop/$hdp.desktop ;fi
	  echo "Name[en_US]=$hdp" >> ~/Desktop/$hdp.desktop
      echo "Name=system:/media/$hdp" >> ~/Desktop/$hdp.desktop
      echo "Type=Link" >> ~/Desktop/$hdp.desktop
      echo "URL[\$e]=system:/media/$hdp" >> ~/Desktop/$hdp.desktop
	  echo "$hdp - $filesys"
#  fi
done
}
if [ "$1" == "-d" ];then if [-e ~/Desktop/$1.desktop ];then rm ~/Desktop/$1.desktop ;fi ;exit 0 ;fi
fadd

# it will be nicer if the desktop links will disappear when the drive is unmounted.
# maybe use functions in the script for options to do on boot,unmount and mount.
# /etc/udev/rules.d/ is the appropriate way to do that. i wil make a setup for that tomorrow
# RUN+="/usr/bin/this_script mount/unmount" to add / remove a link
edit: updated the code. this time it is working!

going to improve the script to detect cdrom ntfs fat usb or network media and use the appropriate icon
going to using udev to detect mount / unmount events to add / remove desktop icon.
Last edited by Proxx on 16 May 2011, 19:19, edited 4 times in total.

crashman
Contributor
Contributor
Posts: 118
Joined: 28 Dec 2010, 17:03
Location: Poland

Re: automaticly create desktop item to all harddrives.

Post#2 by crashman » 16 May 2011, 18:26

Thank you Proxx

Testing your script and work :good: but i have three partition sda1-NTFS sda2-NTFS sda3-EXT4 and your script show only icon for sda3 partition.

regards
Last edited by crashman on 16 May 2011, 18:35, edited 1 time in total.

Proxx
White ninja
White ninja
Posts: 10
Joined: 11 May 2011, 20:13
Location: Home

Re: automaticly create desktop item to all harddrives.

Post#3 by Proxx » 16 May 2011, 18:34

i know that there are some flaws in the script.
are all the mounts done in the /mnt dir ?

i wil edit the script to search in mtab so that the script wil detect mounts on other dirs than /mnt

crashman
Contributor
Contributor
Posts: 118
Joined: 28 Dec 2010, 17:03
Location: Poland

Re: automaticly create desktop item to all harddrives.

Post#4 by crashman » 16 May 2011, 18:38

In my laptop porteus always mount all drivers, your script mount from 'system:/media/sda3' path, unmount not work.

Proxx
White ninja
White ninja
Posts: 10
Joined: 11 May 2011, 20:13
Location: Home

Re: automaticly create desktop item to all harddrives.

Post#5 by Proxx » 16 May 2011, 19:11

you mean that the script does not remove the icon from the desktop when a drive is unmounted ? im working on that.
i fixed the script so that it will show all your drives. working on ntfs icon as we speak (need to format flashdrive to ntfs to test =])

to let the icon be removed on unmount i need to edit the /etc/udev/rules.d/file im testing this as we speak.

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: create desktop item for all harddrives mounted.

Post#6 by brokenman » 16 May 2011, 23:24

Sounds like a useful script.

Also you may consider this:
Right click/go to Configure desktop--> Behavior---->Device icons/ and check the box saying "Show device icons"
How do i become super user?
Wear your underpants on the outside and put on a cape.

Proxx
White ninja
White ninja
Posts: 10
Joined: 11 May 2011, 20:13
Location: Home

Re: create desktop item for all harddrives mounted.

Post#7 by Proxx » 17 May 2011, 10:24

brokenman do u know why there are like 4 different things to manage the auto-mounting ?
it is getting me nuts. (but i learned a lot from it)

udev/hal/udisks/pcmanfm :%)

whoho: im a white ninja from now

crashman
Contributor
Contributor
Posts: 118
Joined: 28 Dec 2010, 17:03
Location: Poland

Re: create desktop item for all harddrives mounted.

Post#8 by crashman » 17 May 2011, 19:34

@Proxx
Thank you very much yor script work now :) is very usefull :good:

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: create desktop item for all harddrives mounted.

Post#9 by brokenman » 24 May 2011, 19:27

brokenman do u know why there are like 4 different things to manage the auto-mounting ?
Not exactly sure what you mean here by automounting. Do you mean during boot time, or when you plug something in?
How do i become super user?
Wear your underpants on the outside and put on a cape.

Post Reply