File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44GROUP_NAME=" defguard"
55SERVICE_NAME=" defguard-service"
66
7+ # Get the name of user who is installing the client
8+ get_installing_user () {
9+ # Method 1: Check standard environment variables when installing with CLI
10+ if [ -n " $SUDO_USER " ] && [ " $SUDO_USER " != " root" ]; then
11+ INSTALLING_USER=" $SUDO_USER "
12+ elif [ -n " $USER " ] && [ " $USER " != " root" ]; then
13+ INSTALLING_USER=" $USER "
14+ fi
15+ if [ -n " $INSTALLING_USER " ]; then
16+ echo " $INSTALLING_USER "
17+ return 0
18+ fi
19+
20+ # Method 2: Check loginctl for latest session
21+ username=$( loginctl list-users --no-legend | awk ' $1 >= 1000 {print $2; exit}' )
22+ if [ -n " $username " ]; then
23+ echo " $username "
24+ return 0
25+ fi
26+
27+ return 1
28+ }
29+
730case " $1 " in
831 1|configure)
932 # Create the group if it doesn't exist
@@ -15,12 +38,7 @@ case "$1" in
1538 fi
1639
1740 # Determine target user
18- TARGET_USER=" "
19- if [ -n " $SUDO_USER " ] && [ " $SUDO_USER " != " root" ]; then
20- TARGET_USER=" $SUDO_USER "
21- elif [ -n " $USER " ] && [ " $USER " != " root" ]; then
22- TARGET_USER=" $USER "
23- fi
41+ TARGET_USER=$( get_installing_user)
2442 echo " Installation triggered by user $TARGET_USER "
2543
2644 # Add user to group if we found a valid target
You can’t perform that action at this time.
0 commit comments