Mounting HDD or DVD in both Thunar and PCmanFM: "Not authorized to perform operation"

69 respostas [Última entrada]
pragmatist

I am a member!

Desconectado
Joined: 03/03/2016

Hey, if it works for you great! Problem solved. If you run into problems, I would focus on udev. GNU/Linux switched to that years ago for a reason. I try not to create hacks just to create hacks. I create hacks if I don't have a better solution available. Use udev.

If you nevertheless still want to fool around with things at this level, maybe you should look at the hdparm utility. It was installed on my system by default. Just type: man hdparm
Apparently it can be used to control spinning down a disk.

Good luck!

hack and hack
Desconectado
Joined: 04/02/2015

I have yet to read the udev manual about that, but if I have to assign a name to each new device I plug in, that's not manageable.
However, if it's an automatic process, it's udev all the way :D !

I just quickly checked hdparm, but it seems way too technical for me :(

The thing is, I have a rough script that works.
Then, provided udev does what I imagine, I can refine it (less lines in the script), and hopefully operate it fully without sudo.
But first of all, I must make the Thunar personalized command work.
Now that I've put the script in the bin folder, I got this:
/bin/sh: 1: myscript.sh: Permission denied

Supposedly, it's about chmod. But it was already allowed before copying and pasting. It indeed has rwx.
ls -l gives me this now: -rwx--x--x 1 root root, as I tried to allow execution everywhere without much thinking (not wanting to spend too much time on the details of chmod right now).
But something changed. Now Thunar (from the CLI) says:
/bin/bash: /bin/safelyremovehdd.sh: Permission non accordée

pragmatist

I am a member!

Desconectado
Joined: 03/03/2016

The concept of udev is that instead of the computer saying "you plugged in a block device, I will give it a name--what name is next? /dev/sdc ok give it /dev/sdc" in udev it is "you plugged in a block device, what it its name? 982p4q9834uafdfkajdsf Oh, let me look that up: that is the unique name for this exact WD hard drive" If you plug in a different WD hard drive it will also have a unique udev name. Absolute names instead of relative names. That is my understanding--I could be wrong.

What are the actual permissions? ------rwx or rwxrwxrwx or r-xr-xrwx and so on. Who is the owner of the file and what is the group? Just do ll or ls -l

hack and hack
Desconectado
Joined: 04/02/2015

-rwx--x--x

As long as udev assigns absolute names automatically (without any intervention of mine), I can only adopt it with a warm welcome.
Then, I'd have to make sure that my script pick the absolute names up, in avariable probably.

this (https://unix.stackexchange.com/questions/16623/file-permission-execute-only) tells me execution rights only are not enough. So chmod 777 works, but I probably don't need that much (just skimmed through the link).

pragmatist

I am a member!

Desconectado
Joined: 03/03/2016

I also asked who the owner and group were.

Read the udev manual, it shows you how to use the absolute names.

hack and hack
Desconectado
Joined: 04/02/2015

I don't know. I don't know about users and groups, and I barely know about permissions. I'm not an expert, sorry.

Again, what would absolute naming would do if I can't make the final script work in Thunar? It's an enhancement, definitely, but as such, it's not essential right now, so sorry it it bothers you that I choose to focus on the main dish first.

pragmatist

I am a member!

Desconectado
Joined: 03/03/2016

In your link it says: "You need both read and execute permissions on a script to be able to execute it. If you can't read the contents of the script, you aren't able to execute it either."

hack and hack
Desconectado
Joined: 04/02/2015

Yeah, hence the 777 I tried right after. I just need to read it again because this might be too much permission, that's all I meant.

hack and hack
Desconectado
Joined: 04/02/2015

Now, I can right-clic on the HDD folder in Thunar, and unmount then power it off.

That's a HUGE step forward for me.
The first problem is: it does work only when I clic on the drive folder.

pragmatist

I am a member!

Desconectado
Joined: 03/03/2016

LOL I just realized that you aren't actually asking anything! You are just giving us a play-by-play of what you are doing. I'll leave you to it--good luck with whatever it is you are trying to do.

hack and hack
Desconectado
Joined: 04/02/2015

I mostly posted without help here, so yeah, it might look like play-by-play because I have no damn choice.
And when help was actually given (which i'm grateful for), I actually USED it.
If you've read the previous posts, you'll know that (btw, you don't read much of what I write either since I had to repeat myself twice already).

I'll tell you a third time: udev might help, but it won't likely solve my main problem, just a part of it that's I'll take care of later because it's not the most essential.
What good would it make me to have absolute naming if Thunar doesn't recognize the final script?

And why the hell would I waste so much time trying to solve such a basic functionality (that exists in proprietary OS) by myself?
I just want it to work because I care about free software being usable and painless for new users.

I'd rather spend that time doing something else, so if you have a way to make the whole thing work (not just a part that would make it better), I'd take it right now.

Thanks for the luck though. And for the help, because eventually I will use what you posted, even if you think otherwise.

hack and hack
Desconectado
Joined: 04/02/2015

LAST POST on this thread:

I have a script that roughly works since today, but with sudo. Thunar is great, but launching scripts globally seems impossible.

My focus is now on dmenu. It seems there are ways to launch scripts as sudo. It is also a better solution since it's a bit more global (some people might want another file manager, even a command-line-based file manager).

THEN if this works, I'll get back to udev to hopefully tighten the script.

To recap, and safely removing an HDD is nearly done (OK solution on Thunar right now, but hopefully a great solution with a much more flexible dmenu).
Need to fix DVD copy and I'm done here.

But I don't need to post on this thread anymore,
since the biggest problems are mostly solved, at last.
Thanks for your help everyone!

pragmatist

I am a member!

Desconectado
Joined: 03/03/2016

This is how the i3 window manager describes itself:
"Please be aware i3 is primarily targeted at advanced users and developers."

This is how you describe yourself:
"advanced beginner"

"I waste so much time trying to solve such a basic functionality (that exists in proprietary OS)"

That is completely unfair to compare a proprietary OS to your home made version of Trisquel. Does Trisquel do what you want to do with the HD if you use the default Trisquel configuration? Take a LiveCD and see. Does it work automagically there?

You can't make a major change like installing a different window manager (a self-proclaimed advanced window manager no less!), a non-default file manager, and whatever else you've done using the > 45,000 programs in the repositories and then expect things to work like they do in a proprietary OS! The proprietary OS makers designed a system their way and it works their way. Trisquel designed a system their way and it works their way. The differences are it is free software, and you can modify the system all you like. But don't expect that whatever major changes you make deserve help here to make them work.

Use the default system and if basic functionality does not work, it is reasonable to expect help with it. Make big changes to the defaults and things don't work--ask for help, but do not expect it.

I use i3wm (and fluxbox, and Trisquel, and Gnome, and XFCE, and openbox...) I like to play around with window managers, but I don't expect help when I'm using non-standard setups. I may ask, but I don't expect it.

In i3wm when I want to access a HD I hit mod1+2 to switch to my workspace number 2 which always contains a terminal. Then I plug in the HD, and type dmesg in the terminal to find out the device file name. Then I switch into the drive using: sudo mount /dev/sdx /media/usb then I switch to /media/usb and do whatever I want with the files. i3wm emphasizes keyboard shortcuts, not using the mouse alot.

If I wanted to work with a mouse and file manager I probably wouldn't use i3wm. If I still wanted to, I'd use nautilus or whatever the default, already installed and configured, file manager is. If that didn't work I'd probably try to use some script but I would first look for somebody who did this and use their script. If I had to write a script I would try to do it with nautilus, and then with whatever file manager it is easiest to use scripts with.

All of that would be hacking. It isn't the default way of doing things. You don't have to do things in the default way, but if there is already a working solution and you don't use it, you should not expect help. You can ask for help.

When you ask for help, you need to give feedback. Yes, I tried your suggestion and here were the results. Here is the complete script. Here are the permissions/owner/group. You ask specific questions, you try suggestions and explain the exact results posting output from a terminal.

Your last post, which is a 'recap' does not even post the script! You don't even ask a question! That is why I said you are just giving a play-by-play. Want help? Ask exact questions, try exact suggestions, give exact feedback, post exact output.

hack and hack
Desconectado
Joined: 04/02/2015

It's not in my last post, but it is posted earlier.
I asked tons of exact questions, I posted outputs from my terminal, and gave tons of feedback. I mean did you even read the thread?

But since you refer to your intervention, I told you (which is feedback in a way) that what you're suggesting might help make the script tighter, but since the scripts roughly works already, that's obviously not where the focus should be. Yet.

I don't see why it wouldn't deserve help more than anything else.
Most likely, I don't help when I don't know about the solution, not because it's a problem related to a non-standard install. So of course I expect it, that's why I ask for it.
And when I don't get the help, I try on my own, that's all there is to it. No hard feelings or anything.

Ok it's a bit unfair since it's a netinstall with i3wm, but seriously, not that much. It should't be that obscure to make it work. It's not even hard, all it took was to create a text file, and automount worked, regardless of the file manager. Because if you read the thread, you'll see that I tried Thunar, PCmanFM, AND Nautilus. The problem was global. and Nautilus is much heavier, that's why I don't use it.
Also I didn't look for a script specific to ThunEventually, I'm aware I didn't choose the standard route, since I wanted a light system. But seriously, this is like exploring a new territory.ar, a script can be launched in different ways.

But such a simple and essential information (from the advanced beginner's POV, I admit that), it took me ages to find. Thankfully, I learned some stuff on the way, so it's not all wasted. Plus it can be useful to someone else.

The safely remove thing should be also simpler to setup.
It's one clic from a rooted gnome-disks, and that equals 2 commands I'm aware of (posted in this thread). And they work.
But making them work without root, that's harder.
hell, maybe the answer is within udev. Now I can try and find out.

i3wm is for advanced users, but that's how you become advanced, by advancing. Plus it's not rocket science. It's indeed not supposed to be used with the mouse, because th keyboard is faster. But when the command is longer than two mouse clics, it's deeply idiotic to stic to the keyboard in that case. Specially when the same right-clic action can be done with the keyboard with 2 stokes.

Anyway, now I can detach the HDD in 4 clicks and my password. Still better and faster than 1 keyboard stroke to launch the CLI, typing one long command without typo (provided I don't have to identify the drive first), then 1 keystroke and my password. But there must be a better way.
If I can make the command word without password prompt, then dmenu and goodbye. done before I can blink an eye.

But your're right, I should make a proper recap of what works, maybe in the wiki.

pragmatist

I am a member!

Desconectado
Joined: 03/03/2016

"But when the command is longer than two mouse clics, it's deeply idiotic to stic to the keyboard in that case. Specially when the same right-clic action can be done with the keyboard with 2 stokes."

Tell that to all of the people who work without a gui! If you are inexperienced with the CLI or the keyboard, then you are right. It would be deeply idiotic for you to use the CLI if that was slower for you and you weren't trying to get better at using the CLI. But learn the CLI, and you'll do many, many, things more efficiently. One of the main advantages is you don't lose time moving between your keyboard and your mouse.

hack and hack
Desconectado
Joined: 04/02/2015

There are really nice CLI apps, and I personally intend to improve my skills on the keyboard (I want for example to vimify the whole thing, not only i3wm windows. That way, even the gui apps can have basic vim keystrokes).

But besides having a CLI fetish, Working without a gui is most likely to access a server. It definitely can be the faster way, but not always.
And sometimes it is the only way.

In that specific case we're talking about, mounting, unmounting and detaching through the CLI is a pain in the ass, no matter how fast I can type or how much of a vim/emacs keyboard ninja I will become. just having to remember the proper syntax is annoying.
1 clic vs a whole phrase to mount, 4 clics vs one long phrase to unmount and detach, we're talking seconds (and 4 clics is still too much) yet it's still faster and more convenient.

But my goal is a simple keyboard shortcut to unmount and detach.
And to mount also. That way, no mouse at all.
Can hardly make it faster and convenient than calling the scripts from dmenu.
making the script work without sudo would make it super fast. It would beat the CLI even more in that specific case, if it works.
That would maybe even make the polkit rule useless for me eventually.

The whole thing that's blocking me is this (--no-user-interaction doesn't effectively replace sudo here. it prevents the the red lettered authentication password prompt, but then fails, whereas sudo works):
udisksctl power-off -b /dev/sdb1 --no-user-interaction
Error powering off drive: Not authorized to perform operation (udisks-error-quark, 4)

Yeah, I was supposed to close the thread ;)

pragmatist

I am a member!

Desconectado
Joined: 03/03/2016

You are probably right about that. Most people would find it easier to do it your way.

I've tinkered with attaching devices to GNU/Linux for 14 years, so that meant typing "sudo mount ..." like a million times already :-) Nothing to remember in my case.

Back in the old days you were happy if you could buy a device that would work at all! Using a GUI or CLI wasn't the important issue.

Just so you know, Richard M. Stallman prefers the CLI to a GUI. So, not just for sys admins. But it can be a PITA compared to a GUI. If you are a hacker, however, you must like using the CLI. I think it is in the rules somewhere. :)

hack and hack
Desconectado
Joined: 04/02/2015

Hehe, well honestly, I feel I'm getting closer and closer to the pure CLI myself. After all, I'm doing this for speed, but also to have a minimum of code on my machine.

I mean as long as I can launch my scripts with some shortcut, nothing is faster.

Provided I can still use gui programs like GIMP for more complex work, and can still tile programs, that's all I'd need.

hack and hack
Desconectado
Joined: 04/02/2015

After making a new file in sudoers.d, I allowed sudo udisksctl in some ways without password. Read the steps carefully in order to do that:
https://askubuntu.com/questions/159007/how-do-i-run-specific-sudo-commands-without-a-password

It uses vi by default btw. Some additional info: https://wiki.archlinux.org/index.php/Sudo#Sudoers_default_file_permissions

This script works like a charm (tried with several drives at the same time):
#!/bin/bash
udisksctl unmount -b /dev/sdb1 && sudo udisksctl power-off -b /dev/sdb1
udisksctl unmount -b /dev/sdb2 && sudo udisksctl power-off -b /dev/sdb2
udisksctl unmount -b /dev/sdb3 && sudo udisksctl power-off -b /dev/sdb3
udisksctl unmount -b /dev/sdc1 && sudo udisksctl power-off -b /dev/sdc1
udisksctl unmount -b /dev/sdc2 && sudo udisksctl power-off -b /dev/sdc2
udisksctl unmount -b /dev/sdc3 && sudo udisksctl power-off -b /dev/sdc3

I could make a very similar one to mount the plugged in drives, then launch those 2 scripts with dmenu as needed. I need to test that without the polkit tweaks though.

Now I'll try the udev rules. But from what I understand, I need to write a persistent name by hand, so it's not an automated process. I don't want to have to do this for every new drive I plug in.

Since mounting/unmounting works, (logically, the polkit rule is only needed for Thunar and other managers to have mount/unmount interaction on clic. Why? Because CLI commands did work before), as well as powering the drive off works,
I'll take care of the DVD copy issue in another thread.

Solved (finally, after nearly 4 months...).