#!/hint/bash post_install+=(testuser:post_install) testuser:post_install() { local arg_mountpoint=$1 useradd --root="$arg_mountpoint" \ --gid=users \ --comment='Test User' \ --create-home \ testuser local init init=$(readlink -- "${arg_mountpoint}"/bin/init) init="${init##*/}" case "$init" in systemd) cat <<-'EOT' > "${arg_mountpoint}/etc/systemd/system/testuser.service" [Unit] Description=chown /home/testuser [Service] Type=oneshot ExecStart=/bin/chown -R testuser: /home/testuser [Install] WantedBy=basic.target EOT systemctl --root="$arg_mountpoint" enable testuser.service ;; openrc-init) install -m755 /dev/stdin "$arg_mountpoint/etc/init.d/testuser" <<-'EOT' #!/sbin/openrc-run description="Set up tmpfiles.d entries" depend() { need localmount } start() { ebegin "chown /home/testuser" /bin/chown -R testuser: /home/testuser eend $? } EOT mkdir -p "$arg_mountpoint/etc/runlevels/boot" ln -s -t "$arg_mountpoint/etc/runlevels/boot" /etc/init.d/testuser ;; *) error 2 'The testuser module does not know how to work with %s' "$init" ;; esac }