adduser.sh 1.5 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. echo void-live > ${NEWROOT}/etc/hostname
  6. USERNAME=$(getarg live.user)
  7. USERSHELL=$(getarg live.shell)
  8. [ -z "$USERNAME" ] && USERNAME=anon
  9. [ -z "$USERSHELL" ] && USERSHELL=/bin/sh
  10. # Create /etc/default/live.conf to store USER.
  11. echo "USERNAME=$USERNAME" >> ${NEWROOT}/etc/default/live.conf
  12. chmod 644 ${NEWROOT}/etc/default/live.conf
  13. if ! grep -q ${USERSHELL} ${NEWROOT}/etc/shells ; then
  14. echo ${USERSHELL} >> ${NEWROOT}/etc/shells
  15. fi
  16. # Create new user and remove password. We'll use autologin by default.
  17. chroot ${NEWROOT} useradd -c $USERNAME -m $USERNAME -G wheel -s $USERSHELL
  18. chroot ${NEWROOT} passwd -d $USERNAME >/dev/null 2>&1
  19. # Setup default root password (voidlinux).
  20. chroot ${NEWROOT} sh -c 'echo "root:voidlinux" | chpasswd -c SHA512'
  21. # Enable sudo permission by default.
  22. if [ -f ${NEWROOT}/etc/sudoers ]; then
  23. echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> ${NEWROOT}/etc/sudoers
  24. fi
  25. if [ -d ${NEWROOT}/etc/polkit-1 ]; then
  26. # If polkit is installed allow users in the wheel group to run anything.
  27. cat > ${NEWROOT}/etc/polkit-1/rules.d/void-live.rules <<_EOF
  28. polkit.addAdminRule(function(action, subject) {
  29. return ["unix-group:wheel"];
  30. });
  31. polkit.addRule(function(action, subject) {
  32. if (subject.isInGroup("wheel")) {
  33. return polkit.Result.YES;
  34. }
  35. });
  36. _EOF
  37. chroot ${NEWROOT} chown polkitd:polkitd /etc/polkit-1/rules.d/void-live.rules
  38. fi