diff options
author | Simon Rettberg | 2024-02-01 15:18:05 +0100 |
---|---|---|
committer | Simon Rettberg | 2024-02-01 15:18:05 +0100 |
commit | 63bf839ea0b5e4cc9643b70d22e4ac856939d027 (patch) | |
tree | 0611189195c66f58a4bd7b0ab717b478a1059b70 | |
parent | [disk-partitions] Refactor gettmp (diff) | |
download | mltk-63bf839ea0b5e4cc9643b70d22e4ac856939d027.tar.gz mltk-63bf839ea0b5e4cc9643b70d22e4ac856939d027.tar.xz mltk-63bf839ea0b5e4cc9643b70d22e4ac856939d027.zip |
[vbox-src] Add vboxusers at build time, add demo to group
-rw-r--r-- | core/includes/useradd.inc | 13 | ||||
-rwxr-xr-x | core/modules/vbox-src/data/opt/openslx/scripts/systemd-vbox_env | 2 | ||||
-rw-r--r-- | core/modules/vbox-src/module.build | 3 |
3 files changed, 16 insertions, 2 deletions
diff --git a/core/includes/useradd.inc b/core/includes/useradd.inc index 359a859f..d47b43b9 100644 --- a/core/includes/useradd.inc +++ b/core/includes/useradd.inc @@ -138,18 +138,31 @@ groupadd () { command groupadd "${_USER_EXTRA_OPTS[@]}" "${opts[@]}" || perror "groupadd failed" } +# Add user to given group. Not entirely safe as we don't wait for a lock, +# but should not be an issue during build time as system is usually offline. +# $1=user $2=group +add_to_group () { + ua_set_vars + grep -qP "^${2}:.*:.*[:,]${1}(,|$)" "$_GROUP" && return 0 + grep -q "^${2}:" "$_GROUP" || return 1 + sed -i -r "s/^${2}:[^:]*:[^:]*:.+$/&,$1/;s/^${2}:[^:]*:[^:]*:$/&$1/" "$_GROUP" +} + # Get numeric ID of given user (name or ID) getuid () { + ua_set_vars awk -F ':' -v p="$1" -v n= '{if ($1 == p) n = $3; if (n == "" && $3 == p) n = $3;}END{if (length(n)) print n}' "$_PASSWD" } # Get numeric ID of given group (name or ID) getgid () { + ua_set_vars awk -F ':' -v p="$1" -v n= '{if ($1 == p) n = $3; if (n == "" && $3 == p) n = $3;}END{if (length(n)) print n}' "$_GROUP" } # Get numeric ID of primary group of given user (name or ID) getusergroup () { + ua_set_vars awk -F ':' -v p="$1" -v n= '{if ($1 == p) n = $4; if (n == "" && $4 == p) n = $3;}END{if (length(n)) print n}' "$_PASSWD" } diff --git a/core/modules/vbox-src/data/opt/openslx/scripts/systemd-vbox_env b/core/modules/vbox-src/data/opt/openslx/scripts/systemd-vbox_env index a7049f81..f923f2c2 100755 --- a/core/modules/vbox-src/data/opt/openslx/scripts/systemd-vbox_env +++ b/core/modules/vbox-src/data/opt/openslx/scripts/systemd-vbox_env @@ -45,7 +45,7 @@ fi # check/create vboxusers group getent group vboxusers || addgroup --system vboxusers -adduser demo vboxusers +[[ " $( id -Gn demo ) " = *" vboxusers "* ]] || adduser demo vboxusers # set their permissions chmod 0600 /dev/vboxdrv /dev/vboxnetctl diff --git a/core/modules/vbox-src/module.build b/core/modules/vbox-src/module.build index bcf85f9a..f8c03956 100644 --- a/core/modules/vbox-src/module.build +++ b/core/modules/vbox-src/module.build @@ -164,5 +164,6 @@ build() ( ) post_copy() { - : + groupadd --system vboxusers + add_to_group demo vboxusers } |