New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider $SUDO_USER on Linux for locating the sketchbook folder #5055

Merged
merged 3 commits into from May 8, 2017

Conversation

Projects
None yet
2 participants
@gohai
Contributor

gohai commented May 6, 2017

This is #5054 but also overwrites getSettingsFolder taking $HOME into account, so that sudo -E works. Since now the root user is now potentially writing into the settings folder, the patch tries to make those files world-writable.

Compared to #5054, this also handles these situations:

  • more than one user running sudo -E processing (previously this created settings in the root users home directory pointing the sketch directory to the first that called)
  • user having a custom path for the sketch folder set
  • the root user having .processing & sketchbook herself (this is still possible to make use of by running sudo without the -E)

Modifying all files that get created by P5 to be world-writable is probably a futile attempt, but if this is the way to go I would consider adding this at least for:

  • creating the sketchbook and .processing folders (so that sudo -E without them being already present wouldn't create folders that can later not be written into)
  • Processing's save family of functions

gohai added some commits May 5, 2017

Consider the $HOME on Linux for locating the sketchbook folder
The aim of this change is to make "sudo -E processing{,-java}" work with custom libraries installed in the invoking user's home directory.

@gohai gohai requested a review from benfry May 6, 2017

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry May 7, 2017

Member

Doesn't -H handle this with sudo?

Member

benfry commented May 7, 2017

Doesn't -H handle this with sudo?

@gohai

This comment has been minimized.

Show comment
Hide comment
@gohai

gohai May 7, 2017

Contributor

It's a bit odd sudo -H doesn't seem to work on the Pi (Debian derivative), because of some settings in /etc/sudoers that sanitize the environment. sudo -E does work, probably because it forces the environment to be preserved.

I think I found a way for doing this even with plain sudo: $SUDO_USER seems to be always set to the original user - one could get to this user's home directory with echo ~$SUDO_USER.

@benfry Do you think this is worth it? Or should I just have the reader make a symlink from their sketchbook folder to /root/sketchbook instead?

Contributor

gohai commented May 7, 2017

It's a bit odd sudo -H doesn't seem to work on the Pi (Debian derivative), because of some settings in /etc/sudoers that sanitize the environment. sudo -E does work, probably because it forces the environment to be preserved.

I think I found a way for doing this even with plain sudo: $SUDO_USER seems to be always set to the original user - one could get to this user's home directory with echo ~$SUDO_USER.

@benfry Do you think this is worth it? Or should I just have the reader make a symlink from their sketchbook folder to /root/sketchbook instead?

Use $SUDO_USER instead of $HOME
This seems to be set even when executing "sudo" without any special flags like "-E" or "-H".
@gohai

This comment has been minimized.

Show comment
Hide comment
@gohai

gohai May 8, 2017

Contributor

I like the way this looks and functions now. Believe all that is missing would be to sprinkle some setWritable(true, false) at places...

Contributor

gohai commented May 8, 2017

I like the way this looks and functions now. Believe all that is missing would be to sprinkle some setWritable(true, false) at places...

@gohai gohai changed the title from Consider the $HOME on Linux for locating the sketchbook folder, take 2 to Consider the $SUDO_USER on Linux for locating the sketchbook folder May 8, 2017

@gohai gohai changed the title from Consider the $SUDO_USER on Linux for locating the sketchbook folder to Consider $SUDO_USER on Linux for locating the sketchbook folder May 8, 2017

}
public static String getHomeDir(String user) throws IOException {

This comment has been minimized.

@benfry

benfry May 8, 2017

Member

PApplet.createReader() here will save a lot of lines and these funky indents.

@benfry

benfry May 8, 2017

Member

PApplet.createReader() here will save a lot of lines and these funky indents.

@benfry benfry merged commit 11cb6e2 into processing:master May 8, 2017

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry May 8, 2017

Member

Started review but decided easier to just fix it up… Fixed placement of a comment, catching Exception instead of IOException (could cause an NPE or others), other shortening misc.

Member

benfry commented May 8, 2017

Started review but decided easier to just fix it up… Fixed placement of a comment, catching Exception instead of IOException (could cause an NPE or others), other shortening misc.

@benfry

This comment has been minimized.

Show comment
Hide comment
@benfry

benfry May 8, 2017

Member

I'm a little wary of the tacit encouragement this gives people to run the environment using sudo, but I guess the alternative is worse, that people would simply run as root anyway.

Member

benfry commented May 8, 2017

I'm a little wary of the tacit encouragement this gives people to run the environment using sudo, but I guess the alternative is worse, that people would simply run as root anyway.

@gohai

This comment has been minimized.

Show comment
Hide comment
@gohai

gohai May 8, 2017

Contributor

Thanks @benfry. I'll look for your edits, to pick up a trick or two! Agree about not wanting to promote sudo

Contributor

gohai commented May 8, 2017

Thanks @benfry. I'll look for your edits, to pick up a trick or two! Agree about not wanting to promote sudo

@gohai

This comment has been minimized.

Show comment
Hide comment
@gohai

gohai May 8, 2017

Contributor

(with createReader this is indeed way nicer!)

Contributor

gohai commented May 8, 2017

(with createReader this is indeed way nicer!)

@gohai gohai deleted the gohai:linux-sudo-2 branch May 22, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment