adduser.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. USERNAME=$(getarg live.user)
  6. [ -z "$USERNAME" ] && USERNAME=anon
  7. # Create /etc/default/live.conf to store USER.
  8. echo "USERNAME=$USERNAME" >> ${NEWROOT}/etc/default/live.conf
  9. chmod 644 ${NEWROOT}/etc/default/live.conf
  10. # Create new user and remove password. We'll use autologin by default.
  11. chroot ${NEWROOT} useradd -c $USERNAME -m $USERNAME -G \
  12. systemd-journal,wheel -s /bin/bash
  13. chroot ${NEWROOT} passwd -d $USERNAME >/dev/null 2>&1
  14. # Enable sudo permission by default.
  15. if [ -f ${NEWROOT}/etc/sudoers ]; then
  16. echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> ${NEWROOT}/etc/sudoers
  17. fi
  18. # Enable autologin for agetty(8).
  19. if [ -d ${NEWROOT}/etc/systemd/system ]; then
  20. rm -f "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  21. sed -e "s|/sbin/agetty --noclear|& -a ${USERNAME}|g" \
  22. "${NEWROOT}/usr/lib/systemd/system/[email protected]" > \
  23. "${NEWROOT}/etc/systemd/system/[email protected]"
  24. ln -sf /etc/systemd/system/[email protected] \
  25. "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  26. fi
  27. if [ -d ${NEWROOT}/etc/polkit-1 ]; then
  28. # If polkit is installed allow users in the wheel group to run anything.
  29. cat > ${NEWROOT}/etc/polkit-1/rules.d/void-live.rules <<_EOF
  30. polkit.addAdminRule(function(action, subject) {
  31. return ["unix-group:wheel"];
  32. });
  33. polkit.addRule(function(action, subject) {
  34. if (subject.isInGroup("wheel")) {
  35. return polkit.Result.YES;
  36. }
  37. });
  38. _EOF
  39. chroot ${NEWROOT} chown polkitd:polkitd /etc/polkit-1/rules.d/void-live.rules
  40. fi