Skip to content

Commit f8a50cd

Browse files
committed
Re-write user check logic for username and group name
1 parent f7761fd commit f8a50cd

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

retropie_packages.sh

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,34 @@ __version="4.8.8"
1616
# main retropie install location
1717
rootdir="/opt/retropie"
1818

19-
# if __user is set, try and install for that user, else use SUDO_USER
20-
if [[ -n "$__user" ]]; then
21-
user="$__user"
22-
if ! id -u "$__user" &>/dev/null; then
23-
echo "User $__user not exist"
24-
exit 1
25-
fi
26-
else
27-
user="$SUDO_USER"
19+
# if no user is specified
20+
if [[ -z "$__user" ]]; then
21+
# get the calling user from sudo env
2822
__user="$SUDO_USER"
29-
[[ -z "$user" ]] && user="$(id -un)"
30-
[[ -z "$__user" ]] && __user="$(id -un $SUDO_USER)"
31-
[[ -z "$__group" ]] && __group="$(id -gn $SUDO_USER)"
23+
# if not called from sudo get the current user
24+
[[ -z "$__user" ]] && __user="$(id -un)"
25+
fi
26+
27+
# check if the user exists
28+
if [[ -z "$(getent passwd "$__user")" ]]; then
29+
echo "User $__user does not exist."
30+
exit 1
31+
fi
32+
33+
# if no group is specified get the users primary group
34+
if [[ -z "$__group" ]]; then
35+
__group="$(id -gn "$__user")"
3236
fi
3337

38+
# check if the group exists
39+
if [[ -z "$(getent group "$__group")" ]]; then
40+
echo "Group $__group does not exist."
41+
exit 1
42+
fi
43+
44+
# backwards compatibility
45+
user="$__user"
46+
3447
home="$(eval echo ~$__user)"
3548
datadir="$home/RetroPie"
3649
biosdir="$datadir/BIOS"

0 commit comments

Comments
 (0)