about summary refs log tree commit diff
path: root/dracut/adduser.sh
blob: 4b7acb3bc9f355e05f07584f9ce5a8ac485542f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
# ex: ts=8 sw=4 sts=4 et filetype=sh

type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh

echo void-live > ${NEWROOT}/etc/hostname

USERNAME=$(getarg live.user)
[ -z "$USERNAME" ] && USERNAME=anon

# Create /etc/default/live.conf to store USER.
echo "USERNAME=$USERNAME" >> ${NEWROOT}/etc/default/live.conf
chmod 644 ${NEWROOT}/etc/default/live.conf

# Create new user and remove password. We'll use autologin by default.
chroot ${NEWROOT} useradd -c $USERNAME -m $USERNAME -G systemd-journal,wheel -s /bin/bash
chroot ${NEWROOT} passwd -d $USERNAME >/dev/null 2>&1

# Setup default root password (voidlinux).
chroot ${NEWROOT} sh -c 'echo "root:voidlinux" | chpasswd -c SHA512'

# Enable sudo permission by default.
if [ -f ${NEWROOT}/etc/sudoers ]; then
    echo "${USERNAME}  ALL=(ALL) NOPASSWD: ALL" >> ${NEWROOT}/etc/sudoers
fi

# Enable autologin for agetty(8) on tty1 and disable pam_systemd.
if [ -d ${NEWROOT}/etc/runit ]; then
    sed -e "s|\-8|& -a $USERNAME|g" -i ${NEWROOT}/etc/sv/agetty-tty1/run
    sed -e '/systemd/d' -i ${NEWROOT}/etc/pam.d/*
fi

# Enable autologin for agetty(8) on tty1 with systemd.
if [ -d ${NEWROOT}/etc/systemd/system ]; then
    rm -f "${NEWROOT}/etc/systemd/system/getty.target.wants/getty@tty1.service"
    sed -e "s|/sbin/agetty --noclear|& -a ${USERNAME}|g" \
        "${NEWROOT}/usr/lib/systemd/system/getty@.service" > \
        "${NEWROOT}/etc/systemd/system/getty@.service"
    ln -sf /etc/systemd/system/getty@.service \
        "${NEWROOT}/etc/systemd/system/getty.target.wants/getty@tty1.service"
fi

if [ -d ${NEWROOT}/etc/polkit-1 ]; then
    # If polkit is installed allow users in the wheel group to run anything.
    cat > ${NEWROOT}/etc/polkit-1/rules.d/void-live.rules <<_EOF
polkit.addAdminRule(function(action, subject) {
    return ["unix-group:wheel"];
});

polkit.addRule(function(action, subject) {
    if (subject.isInGroup("wheel")) {
        return polkit.Result.YES;
    }
});
_EOF
    chroot ${NEWROOT} chown polkitd:polkitd /etc/polkit-1/rules.d/void-live.rules
fi