Choose style:

Author Topic: add mount command to a launcher?  (Read 236 times)

0 Members and 1 Guest are viewing this topic.

Offline murraymint

  • Trusted User
  • Veteran
  • *****
  • Posts: 1964
  • Karma: 341
  • soft boiled with a yolk of gold
    • View Profile
  • Peppermint version(s): 7, 8, 9
add mount command to a launcher?
« on: August 07, 2019, 07:48:37 am »
I'm trying to add the command

Code: [Select]
sudo mount -a

before
Code: [Select]
nemo &U

to make sure my network shares are mounted when I click on my Files launcher. How do I get the mount command to run automatically with elevated privileges like that?

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25692
  • Karma: 2820
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: add mount command to a launcher?
« Reply #1 on: August 07, 2019, 08:56:48 am »
Well this can be done by adding your commands to a script, then allowing that script to be run without having to enter a password by adding a line similar to:-

username ALL= NOPASSWD: /path/to/your/script

to /etc/sudoers (after backing it up of course).

That script (and ONLY that script) should no longer prompt for a password, if run with:
Code: [Select]
sudo /path/to/your/script
so it's run with elevated privileges (meaning you can drop 'sudo' from its contents)



But wouldn't it be easier to just automount your network shares at bootup via /etc/fstab ?

Actually because you're using mount -a I'm guessing you've already added them to fstab but they're not automounting for some reason ?

What's the contents of your
Code: [Select]
xed /etc/fstab
? .. maybe we can fix the entries.



[EDIT]

DO NOT add the
Code: [Select]
nemo %U
line to that script, unless you also want nemo to be started with elevated privileges.

So basically, create a file at say /home/murraymint/my-mountall.sh with the contents
Code: [Select]
#!/bin/bash
mount -a
save the file, then make it executable with
Code: [Select]
sudo chmod +x /home/murraymint/my-mountall.sh
now create another script at say /home/murraymint/my-mountall-nemo.sh with the contents
Code: [Select]
#!/bin/bash
sudo /home/murraymint/my-mountall.sh &
nemo %U
make that executable
Code: [Select]
sudo chmod +x /home/murraymint/my-mountall-nemo.sh
now running that second script with
Code: [Select]
/home/murraymint/my-mountall-nemo.sh
should do what you want.

Hope that made sense.
« Last Edit: August 07, 2019, 09:24:45 am by PCNetSpec »
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline murraymint

  • Trusted User
  • Veteran
  • *****
  • Posts: 1964
  • Karma: 341
  • soft boiled with a yolk of gold
    • View Profile
  • Peppermint version(s): 7, 8, 9
Re: add mount command to a launcher?
« Reply #2 on: August 07, 2019, 06:36:41 pm »

Actually because you're using mount -a I'm guessing you've already added them to fstab but they're not automounting for some reason ?


Yes, the network comes up quite late after reaching the desktop so this fails. I've been trying most of what you suggest but I need to go over it again to see why it didn't work yet.

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25692
  • Karma: 2820
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: add mount command to a launcher?
« Reply #3 on: August 08, 2019, 12:07:01 pm »
What are the contents of your
Code: [Select]
xed /etc/fstab
?



I also think I may have misunderstood what you were attempting to do before.

I take it you mean you're trying to edit the "Command:" line in a panel launcher ?

If "sudo mount -a" works after you reach the desktop, it might be better to just create a script that runs that, and autostart that script.....

What's the output from:
Code: [Select]
sudo cat /etc/sudoers
and
Code: [Select]
whoami
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline murraymint

  • Trusted User
  • Veteran
  • *****
  • Posts: 1964
  • Karma: 341
  • soft boiled with a yolk of gold
    • View Profile
  • Peppermint version(s): 7, 8, 9
Re: add mount command to a launcher?
« Reply #4 on: August 08, 2019, 09:02:39 pm »
What are the contents of your
Code: [Select]
xed /etc/fstab
?
Spoiler (click here to view / hide)
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=87b3c61a-5712-472c-85dd-2e286a5e8bfa /               ext4    errors=remount-ro 0       1
/swapfile                                 none            swap    sw              0       0

192.168.1.21:/mnt/video   /home/tom/Videos   nfs   auto,nofail,noatime 0 0
192.168.1.21:/mnt/4TB /home/tom/Music        nfs     auto,nofail,noatime   0   0
[close]
Quote


I also think I may have misunderstood what you were attempting to do before.

I take it you mean you're trying to edit the "Command:" line in a panel launcher ?

Exactly, I should have made that clear.

Quote
If "sudo mount -a" works after you reach the desktop, it might be better to just create a script that runs that, and autostart that script.....
I've been trying to do that without success. Which user runs the autostart scripts?

Quote
What's the output from:
Code: [Select]
sudo cat /etc/sudoers
Spoiler (click here to view / hide)
$ sudo cat /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults   env_reset
Defaults   mail_badpass
Defaults   secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root   ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

tom ALL=NOPASSWD: /usr/bin/netmnt
[close]
and
Code: [Select]
whoami
[/quote]
Code: [Select]
$ whoami
tom

Offline murraymint

  • Trusted User
  • Veteran
  • *****
  • Posts: 1964
  • Karma: 341
  • soft boiled with a yolk of gold
    • View Profile
  • Peppermint version(s): 7, 8, 9
Re: add mount command to a launcher?
« Reply #5 on: August 08, 2019, 09:05:07 pm »
The workaround now works, with the panel launcher  :)

I used your idea of two scripts so the sudo would only apply to the mount command. I had to use the full path for Nemo to my home directory because &U wasn't recognised when run from the launcher script.

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 25692
  • Karma: 2820
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 8R, 9, and 9R
Re: add mount command to a launcher?
« Reply #6 on: August 08, 2019, 10:23:21 pm »
As you can now use /usr/bin/netmnt to mount your drives without a password, another solution would have been to leave the launcher as default .. then to create an autostart .desktop file to run it after the desktop starts

Make sure
Code: [Select]
xed /usr/bin/netmnt
contains just
Code: [Select]
#!/bin/bash
mount -a
then create an autostart file
Code: [Select]
xed ~/.config/autostart/netmnt-autostart.desktop
with these contents
Code: [Select]
[Desktop Entry]
Type=Application
Name=netmnt-autostart
Comment=Autostart the netmnt script
Exec=bash -c "sleep 5 ; sudo /usr/bin/netmnt"
Terminal=false

That should run 'sudo /usr/bin/netmnt' 5 seconds after the desktop comes up .. I added the 5 second delay to make sure networking had fully come up by that point.



An even better solution might be to simply change your fstab enties from:
Code: [Select]
192.168.1.21:/mnt/video   /home/tom/Videos   nfs   auto,nofail,noatime 0 0
192.168.1.21:/mnt/4TB /home/tom/Music        nfs     auto,nofail,noatime   0   0
to
Code: [Select]
192.168.1.21:/mnt/video   /home/tom/Videos   nfs   noauto,x-systemd.automount,x-systemd.device-timeout=10,timeo=14,x-systemd.idle-timeout=1min,rsize=32768,wsize=32768,intr,noatime 0 0
192.168.1.21:/mnt/4TB /home/tom/Music        nfs     noauto,x-systemd.automount,x-systemd.device-timeout=10,timeo=14,x-systemd.idle-timeout=1min,rsize=32768,wsize=32768,intr,noatime 0 0
which works for me.
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline murraymint

  • Trusted User
  • Veteran
  • *****
  • Posts: 1964
  • Karma: 341
  • soft boiled with a yolk of gold
    • View Profile
  • Peppermint version(s): 7, 8, 9
Re: add mount command to a launcher?
« Reply #7 on: August 09, 2019, 06:52:19 pm »

An even better solution might be to simply change your fstab enties

Strangely enough they won't mount at all with your options. mount -a throws up no errors, they just never appear. I had to put fstab back the way it was.