dtoverlay: Use SUDO_USER in -pre and -post scripts

This patch replaces the hardcoded "pi" user in the dtoverlay-pre and
dtoverlay-post scripts with $SUDO_USER, which is set by the sudo command
to the ID of the user calling it. In the event that SUDO_USER isn't set,
$LOGNAME is used (set by login shells), with an ultime fallback to "pi".
This change is necessary for users who have changed the login ID, perhaps
as a security measure.
This commit is contained in:
Phil Elwell
2018-02-02 10:24:20 +00:00
committed by popcornmix
parent 6312ae528d
commit d574b51a60
2 changed files with 17 additions and 3 deletions

View File

@@ -4,7 +4,14 @@ if [ "$DISPLAY" == "" ]; then
fi
CMD="which lxpanelctl >/dev/null 2>&1 && lxpanelctl alsastart >/dev/null"
if [ $EUID -eq 0 ]; then
exec su pi -c "$CMD"
if [ "$SUDO_USER" != "" ]; then
user=$SUDO_USER
elif [ "$LOGNAME" != "" ]; then
user=$LOGNAME
else
user=pi
fi
exec su $user -c "$CMD"
else
exec $CMD
fi

View File

@@ -4,7 +4,14 @@ if [ "$DISPLAY" == "" ]; then
fi
CMD="which lxpanelctl >/dev/null 2>&1 && lxpanelctl alsastop >/dev/null"
if [ $EUID -eq 0 ]; then
exec su pi -c "$CMD"
if [ "$SUDO_USER" != "" ]; then
user=$SUDO_USER
elif [ "$LOGNAME" != "" ]; then
user=$LOGNAME
else
user=pi
fi
exec su $user -c "$CMD"
else
exec $CMD
fi