Xmounter – GUI script to mount partitions

Forum Forums General Software Xmounter – GUI script to mount partitions

  • This topic has 7 replies, 4 voices, and was last updated Dec 19-6:14 pm by PPC.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #95762
    Member
    PPC

      I tested the GUI mounter script that currently comes with antiX and found it was “hard” to use, specially if you are a newbie, so I created a new one. For now, it only mounts the selected partition, does not yet unmount.

      Usage: run the script and double click in the partition you want to mount. If asked to, enter your root password. The partition will pop open in the default File Manager.

      Note: if you mount a partition using this script, you’ll have to unmount it with “sudo umount [mount_point]”

      This is only a proof of concept, and I probably will only put more work into it if there’s any interest in using this in antiX…

      P.

      #!/bin/bash
      # GUI to mount any drive/partition
      
      #Get list of partitions
      /sbin/blkid > /tmp/partition_list
      
      # Use a Yad window to select partition to mount
      EXEC=$(yad --title="Xmounter" --width=800 --height=400 --center --separator=" " --list  --column=" Drives/partitions:" --button="Mount"  < /tmp/partition_list)
      
      #keep only the first word and remove the ":" it includes
      selection=$(echo $EXEC | awk '{print $1;}'| tr -d :)
      
      #Do something only if user made a selection:
      if [ -n "$selection" ]; then
      
      #make sure mount point exits (with the same name as the partition) in the home folder
      mount_point_name="${selection:5}"
      echo $mount_point_name
      cd $HOME
      mkdir -p -- "$mount_point_name"
      
      #mount the selected partiton to the mount point folder and wait bit
      ##ask for elevatead privileges in a pretty way:
      gksu "Xmounter"
      sudo mount $selection ~/$mount_point_name
      sleep 0.5
      
      #display the mounted partition in the default file manager:
      desktop-defaults-run -fm ~/$mount_point_name
      
      #close the if
      fi

      Edit: I corrected the “blkid” command, so it still works, even if the script is not launched from the terminal (i.e- you can launch the script from a File Manager or from a .desktop file: menu/icon/etc)

      • This topic was modified 4 months, 3 weeks ago by PPC.
      #95766
      Moderator
      Brian Masinick
        Helpful
        Up
        0
        ::

        While I am not certain I would personally have much use for the tool, I want to thank you once again for your efforts and skills.

        I do hope that others express interest; if not I simply appreciate all that you do.

        --
        Brian Masinick

        #95906
        Member
        oops
          Helpful
          Up
          0
          ::

          While I am not certain I would personally have much use for the tool, I want to thank you once again for your efforts and skills.

          I do hope that others express interest; if not I simply appreciate all that you do.

          +1 … It is a good idea.

          #95907
          Forum Admin
          anticapitalista
            Helpful
            Up
            0
            ::

            OK, but what is wrong with disk-manager?

            Philosophers have interpreted the world in many ways; the point is to change it.

            antiX with runit - leaner and meaner.

            #95908
            Member
            oops
              Helpful
              Up
              0
              ::

              OK, but what is wrong with disk-manager?

              Nothing, I use disk-manager , but it is an (light) alternative.

              • This reply was modified 4 months, 2 weeks ago by oops.
              #95914
              Member
              PPC
                Helpful
                Up
                0
                ::

                OK, but what is wrong with disk-manager?

                Nothing. I’m glad you showed some interest in this thread: I created this script as a possible replacement for mountbox.sh (adapted by you). I found that script too complex for a regular user – if the user does not already know, by heart the device he/she intends to mount- that script does have a button that shows a list of all available partitions, but does not allow the user to select any partition from that list… The user has to write down the partition name and then enter it in the “Device” field- that’s not very user friendly. Mountbox also requires the user to enter a mount point. Finnally, Mountbox does not open the mounted partition in the default file manager, but always opens it in rox-filer.
                My proposed solution mounts any partition with a double click (and, if required, entering the password in a gksu window).

                Edit: also, disk-manager was not preinstalled in my antiX 19 – I had to install it in order to test it. My proposed script is far simpler, and is about 2kb.
                If you want me to, I can make a draft script for unmounting partitions too, with the same interface. Ideally, there should be one script – with a “mount” and an “unmount” button.

                P.

                • This reply was modified 4 months, 2 weeks ago by PPC.
                #95919
                Member
                PPC
                  Helpful
                  Up
                  0
                  ::

                  Dear anticapitalista and all:
                  I pieced together a second version of script that now starts with a simple window asking if the user wishes to mount or unmount a partition and acts acordingly- it’s still a very early version of the script- Probably it would be safer to create mount points in /mnt, instead of in /home to avoid accidental delection of data?
                  Since usually users want to mount partitions, pressing enter in the initial selection window does launch the Xmounter script.- I hate the fact that the script has 2 windows, but probably it makes it simpler to use, avoiding user confusion, specially if they are not too confortable around partitions- this way they get 2 independts lists: one for the mounted partitions, another for the unmounted ones- no “check boxes” to confuse them, but yes, they do get 2 windows instead of a single one… I’m open to suggestions, if this script is to ever be adopted for general usage under antiX… As is, the script seems usable to me (it needs a nice icon, but I did not spend time searching for one).

                  EDIT: I envision that this script would mostly be used, in antiX Full, by people that want to access NTFS partitions, on dual boot computers… The script is tiny- less than 3kb (and almost 50% of that are comments)

                  EDIT2: I can envision an improvement to the script: if the list of partitions to be mounted/unmounted has only a single line, then automatically mount/unmount that partition (reducing the amount of clicks the user has to perform to a single one + entering the root password, if needed).

                  The updated script (I renamed it “Xmount”):

                  #!/bin/bash
                  # GUI to mount/unmount any drive/partition, by PPC, GPL license
                  
                  mounter(){
                  # Start Mount partitions  function
                  # Get list of partitions
                  /sbin/blkid > /tmp/partition_list && sleep 0.1
                  
                  # Use a Yad window to select partition to mount
                  EXEC=$(yad --title="Xmount" --width=800 --height=400 --center --separator=" " --list  --column=" Drives/partitions:" --button="Mount"  < /tmp/partition_list)
                  
                  #keep only the first word and remove the ":" it includes
                  selection=$(echo $EXEC | awk '{print $1;}'| tr -d :)
                  
                  #Do something only if user made a selection:
                  if [ -n "$selection" ]; then
                  
                  #make sure mount point exits (with the same name as the partition) in the home folder
                  mount_point_name="${selection:5}"
                  echo $mount_point_name
                  cd $HOME
                  mkdir -p -- "$mount_point_name"
                  
                  sleep 5  #########
                  
                  #mount the selected partiton to the mount point folder and wait bit
                  ##ask for elevatead privileges in a pretty way:
                  gksu "Xmount"
                  sudo mount $selection ~/$mount_point_name
                  sleep 0.5
                  
                  #display the mounted partition in the default file manager:
                  desktop-defaults-run -fm ~/$mount_point_name
                  
                  #close the if
                  fi
                  } # end of Mount partitions function
                  
                  unmounter(){
                  #UnMount partitions function
                  	#Get list of mounted partitions, (show lines with dev), remove lines with tmpfs and devpts and with noatime (this last one should be the home?) and remove tree character :
                  findmnt | grep \/dev\/ | grep -v -w tmpfs | grep -v -w devpts | grep -v -w rw,noatime  | sed 's/└─//g' | sed 's/├─//g' | sed 's/│ //g' > /tmp/partition_list && sleep 0.1
                  
                  #check if the lis of mounted partitions is empty (it does not allow users to unmount the main partition)
                  #if [ -s /tmp/partition_list ];then
                  if [ <code>cat /tmp/partition_list | wc -l</code> -ge "1" ]; then 
                  
                  # Use a Yad window to select partition to unmount
                  EXEC=$(yad --title="Xmount" --width=800 --height=400 --center --separator=" " --list  --column=" Drives/partitions:" --button="Unmount"  < /tmp/partition_list)
                  
                  #keep only the first word and remove the ":" it includes
                  selection=$(echo $EXEC | awk '{print $1;}'| tr -d :)
                  
                  #Do something only if user made a selection:
                  if [ -n "$selection" ]; then
                  
                  #unmount mount point:
                  mount_point_name="${selection:1}"
                  ##ask for elevatead privileges in a pretty way:
                  gksu "Xunmounter"
                  sudo umount /$mount_point_name
                  sleep 0.5
                  yad --center --title="Xmount" --text="\n $mount_point_name was unmounted! " --button="ok" --timeout=5 --timeout-indicator=bottom
                  
                  #close the if from the Selection
                  fi
                  
                  #if the check for the contents of the file list don't retune any line, display warning and exit:
                   else
                   yad --center --title="Xmount" --text="No unmountable partitions were found!" --button="ok" --timeout=5 --timeout-indicator=bottom
                   exit
                  fi 
                  
                  }	# end of UnMount partitions function
                  
                  #Main selection window- the user selects what to do: mount or unmount partition	
                  yad --center --title="Xmount" --text="\n Do you want to mount or unmount partitions? " --button="Mount":2 --button="UnMount":1
                  
                  foo=$?
                  [[ $foo -eq 1 ]] && unmounter
                  [[ $foo -eq 2 ]] && mounter 
                  • This reply was modified 4 months, 2 weeks ago by PPC.
                  • This reply was modified 4 months, 2 weeks ago by PPC.
                  • This reply was modified 4 months, 2 weeks ago by PPC.
                  #95927
                  Member
                  PPC
                    Helpful
                    Up
                    1
                    ::

                    OK, for now, my last attempt at creating a fully usable script:

                    Changes:
                    – if only one partition is mounted (other than the system one, that is ignored by the script- so so I hope), it’s automatically unmounted
                    – I removed the sleep command, that was added when debuging the script
                    – I added an icon to all yad windows, making them look more “polished”.
                    – I made the mount/unmount windows a bit more explicit and easier to understand.

                    As is, unless a bug is found, the script seems to be almost production ready… anyone interested, please do test it and report back any “bugs”- it’s a work in progress!!!

                    The code:

                    #!/bin/bash
                    # GUI to mount/unmount any drive/partition, by PPC, GPL license
                    
                    mounter(){
                    # Start Mount partitions  function
                    # Get list of partitions
                    /sbin/blkid > /tmp/partition_list && sleep 0.1
                    
                    # Use a Yad window to select partition to mount
                    EXEC=$(yad --window-icon="drive-harddisk" --title="Xmount" --width=800 --height=400 --center --separator=" " --list  --column=" Double click the Drive/Partition you want to mount (access):" --button="Mount"  < /tmp/partition_list)
                    
                    #keep only the first word and remove the ":" it includes
                    selection=$(echo $EXEC | awk '{print $1;}'| tr -d :)
                    
                    #Do something only if user made a selection:
                    if [ -n "$selection" ]; then
                    
                    #make sure mount point exits (with the same name as the partition) in the hoem folder
                    mount_point_name="${selection:5}"
                    echo $mount_point_name
                    cd $HOME
                    mkdir -p -- "$mount_point_name"
                    
                    #mount the selected partiton to the mount point folder and wait bit
                    ##ask for elevatead privileges in a pretty way:
                    gksu "Xmount"
                    sudo mount $selection ~/$mount_point_name
                    sleep 0.5
                    
                    #display the mounted partition in the default file manager:
                    desktop-defaults-run -fm ~/$mount_point_name
                    
                    #close the if
                    fi
                    } # end of Mount partitions function
                    
                    unmounter(){
                    #UnMount partitions function
                    	#Get list of mounted partitions, (show lines with dev), remove lines with tmpfs and devpts and with noatime (this last one should be the home?) and remove tree character :
                    findmnt | grep \/dev\/ | grep -v -w tmpfs | grep -v -w devpts | grep -v -w rw,noatime  | sed 's/└─//g' | sed 's/├─//g' | sed 's/│ //g' > /tmp/partition_list && sleep 0.1
                    
                    #If there's only 1 mounted partition (other than the OS one), simply unmount it and exit
                    if [ <code>cat /tmp/partition_list | wc -l</code> -eq "1" ]; then
                     selection=$(cat  /tmp/partition_list | awk '{print $1;}'| tr -d :)
                     mount_point_name="${selection:1}"
                     ##ask for elevatead privileges in a pretty way:
                     gksu "Xunmounter"
                     #unmount
                     sudo umount /$mount_point_name && yad --center --window-icon="drive-harddisk" --title="Xmount" --text="\n $mount_point_name was unmounted! " --button="ok" --timeout=5 --timeout-indicator=bottom
                     exit
                    fi
                    
                    #check if the lis of mounted partitions is empty (it does not allow users to unmount the main partition)
                    #if [ -s /tmp/partition_list ];then
                    if [ <code>cat /tmp/partition_list | wc -l</code> -gt "1" ]; then 
                    
                    # Use a Yad window to select partition to unmount
                    EXEC=$(yad --window-icon="drive-harddisk" --title="Xmount" --width=800 --height=400 --center --separator=" " --list  --column=" Double click the Drive/partition you want to unmount:" --button="Unmount"  < /tmp/partition_list)
                    
                    #keep only the first word and remove the ":" it includes
                    selection=$(echo $EXEC | awk '{print $1;}'| tr -d :)
                    
                    #Do something only if user made a selection:
                    if [ -n "$selection" ]; then
                    
                    #unmount mount point:
                    mount_point_name="${selection:1}"
                    ##ask for elevatead privileges in a pretty way:
                    gksu "Xunmounter"
                    sudo umount /$mount_point_name && yad --center --window-icon="drive-harddisk"  --title="Xmount" --text="\n $mount_point_name was unmounted! " --button="ok" --timeout=5 --timeout-indicator=bottom
                    
                    #close the if from the Selection
                    fi
                    
                    #if the check for the contents of the file list don't retune any line, display warning and exit:
                     else
                     yad --center --window-icon="drive-harddisk" --title="Xmount" --text="No unmountable partitions were found!" --button="ok" --timeout=5 --timeout-indicator=bottom
                     exit
                    fi 
                    
                    }	# end of UnMount partitions function
                    
                    #Main selection window- the user selects what to do: mount or unmount partition	
                    yad --center --window-icon="drive-harddisk" --title="Xmount" --text="\n Do you want to mount (access) or unmount (eject) a Drive/Partition? " --button="Mount":2 --button="UnMount":1
                    
                    foo=$?
                    [[ $foo -eq 1 ]] && unmounter
                    [[ $foo -eq 2 ]] && mounter 
                    • This reply was modified 4 months, 2 weeks ago by PPC.
                  Viewing 8 posts - 1 through 8 (of 8 total)
                  • You must be logged in to reply to this topic.