adduser.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
  3. # ex: ts=8 sw=4 sts=4 et filetype=sh
  4. type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
  5. echo void-live > ${NEWROOT}/etc/hostname
  6. USERNAME=$(getarg live.user)
  7. [ -z "$USERNAME" ] && USERNAME=anon
  8. # Create /etc/default/live.conf to store USER.
  9. echo "USERNAME=$USERNAME" >> ${NEWROOT}/etc/default/live.conf
  10. chmod 644 ${NEWROOT}/etc/default/live.conf
  11. # Create new user and remove password. We'll use autologin by default.
  12. chroot ${NEWROOT} useradd -c $USERNAME -m $USERNAME -G systemd-journal,wheel -s /bin/bash
  13. chroot ${NEWROOT} passwd -d $USERNAME >/dev/null 2>&1
  14. # Setup default root password (voidlinux).
  15. chroot ${NEWROOT} sh -c 'echo "root:voidlinux" | chpasswd -c SHA512'
  16. # Enable sudo permission by default.
  17. if [ -f ${NEWROOT}/etc/sudoers ]; then
  18. echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> ${NEWROOT}/etc/sudoers
  19. fi
  20. # Enable autologin for agetty(8) on tty1 and disable pam_systemd.
  21. if [ -d ${NEWROOT}/etc/runit ]; then
  22. sed -e "s|\-8|& -a $USERNAME|g" -i ${NEWROOT}/etc/sv/agetty-tty1/run
  23. sed -e '/systemd/d' -i ${NEWROOT}/etc/pam.d/*
  24. fi
  25. # Enable autologin for agetty(8) on tty1 with systemd.
  26. if [ -d ${NEWROOT}/etc/systemd/system ]; then
  27. rm -f "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  28. sed -e "s|/sbin/agetty --noclear|& -a ${USERNAME}|g" \
  29. "${NEWROOT}/usr/lib/systemd/system/[email protected]" > \
  30. "${NEWROOT}/etc/systemd/system/[email protected]"
  31. ln -sf /etc/systemd/system/[email protected] \
  32. "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  33. fi
  34. if [ -d ${NEWROOT}/etc/polkit-1 ]; then
  35. # If polkit is installed allow users in the wheel group to run anything.
  36. cat > ${NEWROOT}/etc/polkit-1/rules.d/void-live.rules <<_EOF
  37. polkit.addAdminRule(function(action, subject) {
  38. return ["unix-group:wheel"];
  39. });
  40. polkit.addRule(function(action, subject) {
  41. if (subject.isInGroup("wheel")) {
  42. return polkit.Result.YES;
  43. }
  44. });
  45. _EOF
  46. chroot ${NEWROOT} chown polkitd:polkitd /etc/polkit-1/rules.d/void-live.rules
  47. fi