Nautilus shortcut, unmounted volumes

General support questions
Post Reply
pkcarlisle-dot-com
Posts: 25
Joined: 2014/05/03 21:55:44

Nautilus shortcut, unmounted volumes

Post by pkcarlisle-dot-com » 2015/03/23 21:21:16

Here's what I run:

CentOS 6, 64-bit

Here's what I have:

Volume x. My archives volume. By default, not mounted. If I select volume x I need the admin password to mount it. By default not accessed on-the-fly. Only accessed for archiving the occasional item which really needs immediate backup. All of the above is uh-huh-oh-yeah, the way I like it. I am not looking to have x mounted as a rule, or to change its behavior in any way.

What I want:

To add a desktop or taskbar shortcut to exactly the same thing that happens above, specifically, when I click the taskbar icon, to be prompted for the admin password prior to mounting x OR to bring up x in nautilus if x is already mounted for some reason (normally it won't be mounted already).

What I see:

When I mount x through nautilus, I get the prompt for the admin password, enter it, and get x mounted at /media/x. Perfect. Just what I want.

But

When I try to create a custom launcher with the command nautilus /media/x if x is not mounted I get a 'could not find /media/x/ error box. Well, yeah, I /know/ it can't find /media/x/, it's not mounted yet.

What I would like:

To have my copy/custom shortcut offer the same prompt for a password to mount /media/x/ that I get if I click the volume in nautilus.

Is this possible? I'm guessing so, since either way nautilus is the file manager. Any ideas?

Thanks a lot!

pkcarlisle-dot-com
Posts: 25
Joined: 2014/05/03 21:55:44

Resolved: Nautilus shortcut, unmounted volumes

Post by pkcarlisle-dot-com » 2015/03/25 20:26:15

It feels a bit like a script kiddie (I am more partial to Python, bash scripting is not my strong suit), but I found a solution to the above.

- Zenmap has a script to load in user or in su mode. The su script requires an admin password to proceed.
- I adapted that script for my shortcut.
- Save the script as a script then point a custom launcher to the script.
- If there is anything grossly wrong/insecure/etc. with this approach, please post a response.

Code: Select all

#!/bin/bash
# this code modded by pkc to load nautilus mouting unmounted volume x if
# password provided
##this code is bassed off of the debian su-to-root command
##Joost Witteveen <joostje@debian.org>
##Morten Brix Pedersen
##Bill Allombert <ballombe@debian.org>

PRIV=root
COMMAND="mkdir /media/x; sudo mount /dev/sda1 /media/x$@"

euid=$(id -u)
privid=$(id -u $PRIV)
if test "$euid" = "$privid"; then
    $COMMAND
else
    if test -z "$SU_TO_ROOT_X"; then
      if which gksu >/dev/null 2>&1 ; then
        SU_TO_ROOT_X=gksu
        if test "X$KDE_FULL_SESSION" = "Xtrue" ; then
          if which kdesu >/dev/null 2>&1 ; then
            SU_TO_ROOT_X=kdesu
          elif test -x /usr/lib/kde4/libexec/kdesu ; then
            SU_TO_ROOT_X=kde4su
          fi;
        fi;
      elif which kdesu >/dev/null 2>&1 ; then 
        SU_TO_ROOT_X=kdesu
      elif test -x /usr/lib/kde4/libexec/kdesu ; then
        SU_TO_ROOT_X=kde4su
      elif which ktsuss >/dev/null 2>&1 ; then
        SU_TO_ROOT_X=ktsuss
      elif which xterm>/dev/null 2>&1 ;then
        if which sudo>/dev/null 2>&1 ;then
          SU_TO_ROOT_X=sdterm
        else
          SU_TO_ROOT_X=sterm
        fi;
      else
        SU_TO_ROOT_X=su-to-root
      fi
    fi
    case $SU_TO_ROOT_X in
      gksu) gksu -u "$PRIV" "$COMMAND";;
      kdesu) kdesu -u "$PRIV" -c "$COMMAND";;
      kde4su) /usr/lib/kde4/libexec/kdesu -u "$PRIV" -c "$COMMAND";;
      ktsuss) ktsuss -u "$PRIV" "$COMMAND";;
  # As a last resort, open a new xterm use sudo/su
      sdterm) xterm -e "sudo -u $PRIV $COMMAND";;
      sterm) xterm -e "su -l $PRIV -c $COMMAND";;
    esac;
fi
nautilus /media/x
[Moderator edited to wrap the above shell-script in code tags, thus preserving the formatting and making the code easier to read.]

Post Reply