ofosos / scratch

public scratchpad
http://ofosos.org
44 stars 8 forks source link

How can I run "remarkable.sh" as a different user? #2

Open RobertHenschel opened 5 years ago

RobertHenschel commented 5 years ago

Hi!

I have installed the new backend but noticed that "remarkble.sh" is executed by the "lp" user. If the "lp" user then runs the "rmapi" binary, rmapi of course lacks he configuration to talk to my tablet. I believe you refer to this in the documentation when you say "...run the script with a custom user." Do you have a quick pointer how this could be accomplished? I spent a few hours trying to figure out how to do that in CUPS but got nowhere.

Thanks!

Robert

PS: I am happy to document this procedure once I get it working, so others can benefit from this as well.

ofosos commented 5 years ago

https://www.cups.org/doc/man-cups-files.conf.html see directive User. This is what I do. I created a custom user to run all those programs.

ofosos commented 5 years ago

This user probably needs to be in the lp group (or similar group, depending on your system).

RobertHenschel commented 5 years ago

Thanks for the pointers, I am going to play with this a bit today. I am on Ubuntu 17.10

RobertHenschel commented 5 years ago

I got this to work by including the User keyword in the cups-files.conf and making it print under a separate user account that has access to the rmapi configuration. Thanks for your help with this!

ofosos commented 5 years ago

Any recommendations on what I could improve in the docs, despite the User directive?

RobertHenschel commented 5 years ago

I can write up a short paragraph outlining what I did if that helps. What I am not clear about is the security implications of doing what I did. I basically created a regular new user account on my system, configured rmapi to be able to talk to my remarkable cloud account and then changed the CUPS config to run your scripts under this new account. I assume that this gives more privileges to the script than if the script was run as the regular lp user.

ofosos commented 5 years ago

I'll be very grateful if you can contribute your experiences :+1:

RobertHenschel commented 5 years ago

I just noticed that this global change in the cups-files.conf file breaks my other printers. :-( Need to do a bit more research how to have remarkable.sh run under a specific user while all other printers are run using the system default lp user.

odinblister commented 5 years ago

I'm also having trouble setting this up. Suppose my usename is "bob". I would like this to work so that I can print pdfs directly from my pdf viewer (in my case Okular) to the remarkable tablet. These are the steps that I followed, based on your info:

  1. Downloaded and configured rmapi. I tested this and I can indeed put files to my remarkable tablet with rmapi. There is a file /home/bob/.rmapi that I assume contains the rmapi config.

  2. I Downloaded the your code from github.

  3. Compiled with ppdc remarkable.drv

  4. Copied the resulting ppd to the right place: sudo cp ppd/remarkable.ppd /usr/share/cups/model/.

  5. Edited the remarkable.sh file to have the line rmapi=/home/bob/bin/rmapi (that's where I put rmapi binay).

  6. Copied this file over to cups backend sudo cp remarkable.sh /usr/lib/cups/backend/remarkable

  7. Secured permissions (exactly as per your instructions)

  8. Added "Remarkable" cups printer, exactly like your instructions.

After this, the remarkable printer shows up in the printer choices when I try to print something. Unfortunately, nothing happens. I tried also adding my username (bob) to the cups-files.conf and restarting cups with systemctl restart cups, but printing still didn't work.

ofosos commented 5 years ago

Hey @odinblister , what Linux distribution are you running?

vchryssos commented 3 years ago

Thank you @RobertHenschel for starting this thread. I (think I) have similar permissions issues. When I open the print dialogue to send a page to rM i see the following next to the printer name: auth.go:62: Code has the wrong length, it should be 8

Not sure how this is related to permissions, though..

JCN-9000 commented 3 years ago

I solved this problem by adding this line to the head of the backend script, after the rmapi= line: export RMAPI_CONFIG=$(eval echo ~${cupsuser}/.config/rmapi/rmapi.conf) cups, usually running as root, will have access to the config file of each printing user, so that multiple users sharing the same PC can print to their own reMarkable tablet (I know, rare)

vchryssos commented 3 years ago

Thank you so much for this @JCN-9000. Your suggestion has changed things for me, yet still not uploading to reMarkable. Now I am getting a "failed to upload file" error (main.go:17). Checking the created file (/tmp directory) I see that it only gives a rw access to the owner (root) of the generated file. Why does the generated file has root as owner. Is this something expected? Not sure where to look from here.

JCN-9000 commented 3 years ago

Now I am getting a "failed to upload file" error (main.go:17). Checking the created file (/tmp directory) I see that it only gives a rw access to the owner (root) of the generated file. Why does the generated file has root as owner. Is this something expected? Not sure where to look from here.

Yes, root is the correct owner while the file is being printed. group should be 'lp'

Are you able to manually push a pdf to the tablet using the rmapi interface ? It should not print errors or explain why it fails. Es. rmapi put MyFile.pdf PrintFolder ?

vchryssos commented 3 years ago

Are you able to manually push a pdf to the tablet using the rmapi interface ? It should not print errors or explain why it fails. Es. rmapi put MyFile.pdf PrintFolder ?

Yes, with rmapi I can upload a .pdf in "Print" folder

christianthechristian commented 3 years ago

export RMAPI_CONFIG=$(eval echo ~${cupsuser}/.config/rmapi/rmapi.conf)

That line was necessary in my case as well and probably will be in most cases. I suggest that this line should be part of the script.