From 232fc0d951e5ad096d2255381003b87f281517f7 Mon Sep 17 00:00:00 2001 From: Alex Ibrado Date: Fri, 24 Nov 2017 23:41:31 +0800 Subject: [PATCH 1/5] 1. For multilogin, use the Downloads folder of user who first started the chroot 2. Add /etc/crouton/user with account/email address of said user --- host-bin/enter-chroot | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/host-bin/enter-chroot b/host-bin/enter-chroot index 698e0bc1d..8a3571807 100755 --- a/host-bin/enter-chroot +++ b/host-bin/enter-chroot @@ -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) + fi + echo $activeuser +} + # 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) +if [ -n "$firstrun" ]; then + # Store the active user for possible use in other scripts, etc. + activeuserfile="$(fixabslinks '/etc/crouton/user')" + echo $activeuser > $activeuserfile +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) + else + localdownloads='/home/chronos/user/Downloads' + fi if [ ! -d "$localdownloads" ]; then localdownloads='' fi From 79533deb8f78949ee8d73f116537001c8f45a292 Mon Sep 17 00:00:00 2001 From: Alex Ibrado Date: Sun, 26 Nov 2017 01:47:17 +0800 Subject: [PATCH 2/5] Check for empty localdownloads (single user) --- host-bin/enter-chroot | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/host-bin/enter-chroot b/host-bin/enter-chroot index 8a3571807..dcddda355 100755 --- a/host-bin/enter-chroot +++ b/host-bin/enter-chroot @@ -457,7 +457,8 @@ fi if [ -z "$NOLOGIN" -a -f "$shares" ]; then 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) - else + fi + if [ -z "$localdownloads" ]; then localdownloads='/home/chronos/user/Downloads' fi if [ ! -d "$localdownloads" ]; then From 0b8d3b58d28067e0c6407185b5a50d9446e3f654 Mon Sep 17 00:00:00 2001 From: Alex Ibrado Date: Thu, 28 Dec 2017 09:45:18 +0800 Subject: [PATCH 3/5] Quote variable usage, command output, and paths --- host-bin/enter-chroot | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/host-bin/enter-chroot b/host-bin/enter-chroot index dcddda355..a4e95960d 100755 --- a/host-bin/enter-chroot +++ b/host-bin/enter-chroot @@ -342,7 +342,7 @@ tmpfsmount() { getactiveuser() { local activeuser="Default" if [ -x "/usr/bin/jq" ]; then - activeuser=$(jq -r .LastActiveUser /home/chronos/Local\ State) + activeuser="$(jq -r .LastActiveUser '/home/chronos/Local State')" fi echo $activeuser } @@ -450,13 +450,13 @@ activeuser=$(getactiveuser) if [ -n "$firstrun" ]; then # Store the active user for possible use in other scripts, etc. activeuserfile="$(fixabslinks '/etc/crouton/user')" - echo $activeuser > $activeuserfile + echo "$activeuser" > $activeuserfile fi # Bind-mount the stuff in $CHROOT/etc/crouton/shares, unless NOLOGIN is set if [ -z "$NOLOGIN" -a -f "$shares" ]; then 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) + localdownloads="$(jq -r '.profile.info_cache | to_entries[] | select(.value.user_name == "'$activeuser'") | "/home/chronos/\(.key)/Downloads"' '/home/chronos/Local State')" fi if [ -z "$localdownloads" ]; then localdownloads='/home/chronos/user/Downloads' From 63717d212fde0ce95f83bb87c65daf56519110c3 Mon Sep 17 00:00:00 2001 From: Alex Ibrado Date: Thu, 28 Dec 2017 10:12:51 +0800 Subject: [PATCH 4/5] Break up long line --- host-bin/enter-chroot | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/host-bin/enter-chroot b/host-bin/enter-chroot index a4e95960d..b8c4f7f02 100755 --- a/host-bin/enter-chroot +++ b/host-bin/enter-chroot @@ -456,7 +456,9 @@ fi # Bind-mount the stuff in $CHROOT/etc/crouton/shares, unless NOLOGIN is set if [ -z "$NOLOGIN" -a -f "$shares" ]; then 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')" + localdownloads="$(jq -r '.profile.info_cache | to_entries[] + | select(.value.user_name == "'$activeuser'") + | "/home/chronos/\(.key)/Downloads"' '/home/chronos/Local State')" fi if [ -z "$localdownloads" ]; then localdownloads='/home/chronos/user/Downloads' From 2e5b6904fcf84a5e3bd3c4fce4d2221dd43c1011 Mon Sep 17 00:00:00 2001 From: Alex Ibrado Date: Thu, 28 Dec 2017 10:21:16 +0800 Subject: [PATCH 5/5] - Remove getactiveuser function - Don't create /etc/crouton/user --- host-bin/enter-chroot | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/host-bin/enter-chroot b/host-bin/enter-chroot index b8c4f7f02..487859d66 100755 --- a/host-bin/enter-chroot +++ b/host-bin/enter-chroot @@ -338,15 +338,6 @@ 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')" - fi - echo $activeuser -} - # If /var/run isn't mounted, we know the chroot hasn't been started yet. if mountpoint -q "`fixabslinks '/var/run'`"; then firstrun='' @@ -446,16 +437,13 @@ downloads ~/Downloads EOF fi -activeuser=$(getactiveuser) -if [ -n "$firstrun" ]; then - # Store the active user for possible use in other scripts, etc. - activeuserfile="$(fixabslinks '/etc/crouton/user')" - echo "$activeuser" > $activeuserfile -fi - # Bind-mount the stuff in $CHROOT/etc/crouton/shares, unless NOLOGIN is set if [ -z "$NOLOGIN" -a -f "$shares" ]; then - if [ "$activeuser" != "Default" ]; then + activeuser='' + if [ -x "/usr/bin/jq" ]; then + activeuser="$(jq -r .LastActiveUser '/home/chronos/Local State')" + fi + 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')"