-
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?
Changes from 1 commit
232fc0d
79533de
0b8d3b5
63717d2
2e5b690
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,6 +338,15 @@ tmpfsmount() { | |
mount -i -t tmpfs -o "rw${2:+,}$2" tmpfs "$target" | ||
} | ||
|
||
# Determines currently-logged in user | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
fi | ||
echo $activeuser | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
} | ||
|
||
# If /var/run isn't mounted, we know the chroot hasn't been started yet. | ||
if mountpoint -q "`fixabslinks '/var/run'`"; then | ||
firstrun='' | ||
|
@@ -436,9 +445,21 @@ elif [ ! -f "$shares" ]; then | |
downloads ~/Downloads | ||
EOF | ||
fi | ||
|
||
activeuser=$(getactiveuser) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Just a nice-to-have. Removed... |
||
fi | ||
|
||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. Although 'activeuser' is populated and valid, both 'localdownloads' locations appear empty:
Yet when I list 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 commentThe 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 Would you mind checking the output of There was a problem hiding this comment. Choose a reason for hiding this commentThe 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):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're correct, I only have one account setup on this device.
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 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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 commentThe 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. ,-) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done! There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, else you'd get a literal |
||
else | ||
localdownloads='/home/chronos/user/Downloads' | ||
fi | ||
if [ ! -d "$localdownloads" ]; then | ||
localdownloads='' | ||
fi | ||
|
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...