adduser.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 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 with runit.
  21. if [ -d ${NEWROOT}/etc/runit ]; then
  22. sed "s|agetty|& -a $USERNAME|" -i ${NEWROOT}/etc/sv/agetty-tty1/run
  23. fi
  24. # Enable autologin for agetty(8) on tty1 with systemd.
  25. if [ -d ${NEWROOT}/etc/systemd/system ]; then
  26. rm -f "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  27. sed -e "s|/sbin/agetty --noclear|& -a ${USERNAME}|g" \
  28. "${NEWROOT}/usr/lib/systemd/system/[email protected]" > \
  29. "${NEWROOT}/etc/systemd/system/[email protected]"
  30. ln -sf /etc/systemd/system/[email protected] \
  31. "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  32. fi
  33. if [ -d ${NEWROOT}/etc/polkit-1 ]; then
  34. # If polkit is installed allow users in the wheel group to run anything.
  35. cat > ${NEWROOT}/etc/polkit-1/rules.d/void-live.rules <<_EOF
  36. polkit.addAdminRule(function(action, subject) {
  37. return ["unix-group:wheel"];
  38. });
  39. polkit.addRule(function(action, subject) {
  40. if (subject.isInGroup("wheel")) {
  41. return polkit.Result.YES;
  42. }
  43. });
  44. _EOF
  45. chroot ${NEWROOT} chown polkitd:polkitd /etc/polkit-1/rules.d/void-live.rules
  46. fi