osi-tools/Documentation/module-examples/testuser.sh

26 lines
644 B
Bash
Raw Normal View History

#!/hint/bash -euE
2018-08-18 18:42:42 +00:00
# Copyright (C) 2018 Luke Shumaker
# SPDX-License-Identifier: AGPL-3.0-or-later
2018-08-06 00:09:42 +00:00
2018-08-06 01:49:45 +00:00
post_install+=(01:testuser:early)
testuser:early() {
2018-08-06 00:09:42 +00:00
local arg_mountpoint=$1
2018-08-12 21:56:14 +00:00
if ! grep -q ^testuser: -- "$arg_mountpoint/etc/passwd"; then
arch-chroot -- "$arg_mountpoint" useradd \
2018-08-12 21:56:14 +00:00
--gid=users \
--comment='Test User' \
--create-home \
testuser
fi
2018-08-06 01:49:45 +00:00
}
2018-08-06 00:09:42 +00:00
post_install+=(90:testuser:late)
2018-08-06 01:49:45 +00:00
testuser:late() {
local arg_mountpoint=$1
2018-08-06 00:09:42 +00:00
2018-08-06 01:49:45 +00:00
local uidgid
uidgid=$(awk -v FS=: -v OFS=: '$1 == "testuser" { print $3, $4 }' < "${arg_mountpoint}/etc/passwd")
chown -R -- "$uidgid" "${arg_mountpoint}/home/testuser"
2018-08-06 00:09:42 +00:00
}