-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Use Downloads folder of the user who launched the chroot #3531
base: master
Are you sure you want to change the base?
Conversation
… the chroot 2. Add /etc/crouton/user with account/email address of said user
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
host-bin/enter-chroot
Outdated
# Bind-mount the stuff in $CHROOT/etc/crouton/shares, unless NOLOGIN is set | ||
if [ -z "$NOLOGIN" -a -f "$shares" ]; then | ||
localdownloads='/home/chronos/user/Downloads' | ||
if [ "$activeuser" != "Default" ]; then | ||
localdownloads=$(jq -r ".profile.info_cache | to_entries[] | select(.value.user_name == \"$activeuser\") | \"/home/chronos/\(.key)/Downloads\"" /home/chronos/Local\ State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although 'activeuser' is populated and valid, both 'localdownloads' locations appear empty:
chronos@localhost ~ $ localdownloads=$(jq -r ".profile.info_cache | to_entries[] | select(.value.user_name == \"$activeuser\") | \"/home/chronos/\(.key)/Downloads\"" /home/chronos/Local\ State)
ls -l $localdownloads
/home/chronos/Default/Downloads:
total 0
/home/chronos/LockScreenAppsProfile/Downloads:
total 0
Yet when I list /home/chronos/user/Downloads
it contains all of my files.
I'm not sure this routine will get you the expected results but I may not understand the full intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I'm guessing you haven't logged in to multiple accounts on that Chromebook?
Even so, I expected that the jq -r
part would not have run (if [ "$activeuser" != "Default" ]
) and /home/chronos/user/Downloads
would have been used instead.
Would you mind checking the output of jq -r .LastActiveUser /home/chronos/Local\ State
? That's what activeuser
should have been set to at line 449.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, here's what I'm getting (except for the edited email address and u- id):
$ activeuser=$(jq -r .LastActiveUser /home/chronos/Local\ State)
$ echo $activeuser
[email protected]
$ localdownloads=$(jq -r ".profile.info_cache | to_entries[] | select(.value.user_name == \"$activeuser\") | \"/home/chronos/\(.key)/Downloads\"" /home/chronos/Local\ State)
$ echo $localdownloads
/home/chronos/u-xxxxxxxe64bcd6851c24f81f6566ef0519e781cba/Downloads
$ ls $localdownloads
...files of [email protected] here...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct, I only have one account setup on this device.
Here's the output you requested with my email masked:
chronos@localhost ~ $ jq -r .LastActiveUser /home/chronos/Local\ State
[email protected]
It could be that when I add another user account I'd get the correct $localdownloads location populated but I'm thinking it might be best not to do that yet so we can test this on devices with only one account. When I run the second part beginning with localdownloads=...
I still get the two empty directories.
Let me know if I'm doing something wrong or if you'd like me to test something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, that works. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I ran both commits on a Chromebook with multiple users and they both worked so I guess it was good to check it on a single user device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woohoo! Yeah, it was good you had that around... I was seriously considering a powerwash earlier. :-P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have four Chromebooks going all the way back to a Cr-48 and now a Pixelbook so I have options. ,-)
I like to run the 'chrx' script, 1st phase only and use partiton 7 as a safe place for crouton so I don't have to worry about powerwashing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't had the guts to try chrx yet, haha! I had 2 Chromebooks before this one, but I lent one and gave the other away...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for implementing this cleanly!
host-bin/enter-chroot
Outdated
getactiveuser() { | ||
local activeuser="Default" | ||
if [ -x "/usr/bin/jq" ]; then | ||
activeuser=$(jq -r .LastActiveUser /home/chronos/Local\ State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quote the path instead of using backslash escapes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
host-bin/enter-chroot
Outdated
getactiveuser() { | ||
local activeuser="Default" | ||
if [ -x "/usr/bin/jq" ]; then | ||
activeuser=$(jq -r .LastActiveUser /home/chronos/Local\ State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quote the output of the command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
host-bin/enter-chroot
Outdated
if [ -x "/usr/bin/jq" ]; then | ||
activeuser=$(jq -r .LastActiveUser /home/chronos/Local\ State) | ||
fi | ||
echo $activeuser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quote variable usage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
host-bin/enter-chroot
Outdated
@@ -436,9 +445,22 @@ elif [ ! -f "$shares" ]; then | |||
downloads ~/Downloads | |||
EOF | |||
fi | |||
|
|||
activeuser=$(getactiveuser) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this needs to be a separate function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok... Since we're not creating /etc/crouton/user anymore (see next comment), there's no reason for it.
host-bin/enter-chroot
Outdated
if [ -n "$firstrun" ]; then | ||
# Store the active user for possible use in other scripts, etc. | ||
activeuserfile="$(fixabslinks '/etc/crouton/user')" | ||
echo $activeuser > $activeuserfile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather not (easily) expose this information to the chroot. Is there a real use for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a nice-to-have. Removed...
host-bin/enter-chroot
Outdated
# Bind-mount the stuff in $CHROOT/etc/crouton/shares, unless NOLOGIN is set | ||
if [ -z "$NOLOGIN" -a -f "$shares" ]; then | ||
localdownloads='/home/chronos/user/Downloads' | ||
if [ "$activeuser" != "Default" ]; then | ||
localdownloads=$(jq -r ".profile.info_cache | to_entries[] | select(.value.user_name == \"$activeuser\") | \"/home/chronos/\(.key)/Downloads\"" /home/chronos/Local\ State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep lines to 80 characters, please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
host-bin/enter-chroot
Outdated
# Bind-mount the stuff in $CHROOT/etc/crouton/shares, unless NOLOGIN is set | ||
if [ -z "$NOLOGIN" -a -f "$shares" ]; then | ||
localdownloads='/home/chronos/user/Downloads' | ||
if [ "$activeuser" != "Default" ]; then | ||
localdownloads=$(jq -r ".profile.info_cache | to_entries[] | select(.value.user_name == \"$activeuser\") | \"/home/chronos/\(.key)/Downloads\"" /home/chronos/Local\ State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote the output of the command
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
host-bin/enter-chroot
Outdated
# Bind-mount the stuff in $CHROOT/etc/crouton/shares, unless NOLOGIN is set | ||
if [ -z "$NOLOGIN" -a -f "$shares" ]; then | ||
localdownloads='/home/chronos/user/Downloads' | ||
if [ "$activeuser" != "Default" ]; then | ||
localdownloads=$(jq -r ".profile.info_cache | to_entries[] | select(.value.user_name == \"$activeuser\") | \"/home/chronos/\(.key)/Downloads\"" /home/chronos/Local\ State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quote the path instead of escaping spaces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
host-bin/enter-chroot
Outdated
# Bind-mount the stuff in $CHROOT/etc/crouton/shares, unless NOLOGIN is set | ||
if [ -z "$NOLOGIN" -a -f "$shares" ]; then | ||
localdownloads='/home/chronos/user/Downloads' | ||
if [ "$activeuser" != "Default" ]; then | ||
localdownloads=$(jq -r ".profile.info_cache | to_entries[] | select(.value.user_name == \"$activeuser\") | \"/home/chronos/\(.key)/Downloads\"" /home/chronos/Local\ State) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The escape before the parentheses...is that meaningful to jq?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, else you'd get a literal (.key)
in the result.
host-bin/enter-chroot
Outdated
# Determines currently-logged in user | ||
getactiveuser() { | ||
local activeuser="Default" | ||
if [ -x "/usr/bin/jq" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that you check for the existence of jq (in case it disappears in the future). Is it possible, though, to do this with awk in a reasonable way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough awk to answer this 😊 .. I do think jq will be around for a while since the config file is json. I actually added this check in case it was new...
- Don't create /etc/crouton/user
@DennisLfromGA Hi... Would you mind checking the latest commits on your single-user device? Thanks! |
localdownloads='/home/chronos/user/Downloads' | ||
activeuser='' | ||
if [ -x "/usr/bin/jq" ]; then | ||
activeuser="$(jq -r .LastActiveUser '/home/chronos/Local State')" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
activeuser="$(sed -n 's/.*"LastActiveUser":\s*"\([^"]*\)".*/\1/p' '/home/chronos/Local State')"
if [ -n "$activeuser" ]; then | ||
localdownloads="$(jq -r '.profile.info_cache | to_entries[] | ||
| select(.value.user_name == "'$activeuser'") | ||
| "/home/chronos/\(.key)/Downloads"' '/home/chronos/Local State')" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not convinced this is better (also not certain it is the correct way of doing it), but if we want to get rid of the jq dependency:
localdownloads="$(grep -l '"account_id":\s*"'"$activeuser"'"' /home/chronos/u-*/Preferences | sed 's/Preferences$/Downloads/;q')"
It looks like something along these lines is being addressed in CrOS: EDIT: There is now an environment variable named 'CROS_USER_ID_HASH' that may be an easier approach:
It looks like it was added just recently here: -DennisLfromGA |
For multiple logins, this uses the
LastActiveUser
in/home/chronos/Local State
to determine which ~/Downloads folder should be mapped in the chroot, i.e. that of the user who started the chroot.Additionally, this creates
/etc/crouton/user
containing the email address of the ~/Downloads "owner".See also issue #1410