adduser.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh -x
  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. [ -x $NEWROOT/bin/bash -a -z "$USERSHELL" ] && USERSHELL=/bin/bash
  10. [ -z "$USERSHELL" ] && USERSHELL=/bin/sh
  11. # Create /etc/default/live.conf to store USER.
  12. echo "USERNAME=$USERNAME" >> ${NEWROOT}/etc/default/live.conf
  13. chmod 644 ${NEWROOT}/etc/default/live.conf
  14. if ! grep -q ${USERSHELL} ${NEWROOT}/etc/shells ; then
  15. echo ${USERSHELL} >> ${NEWROOT}/etc/shells
  16. fi
  17. # Create new user and remove password. We'll use autologin by default.
  18. chroot ${NEWROOT} useradd -m -c $USERNAME -G wheel -s $USERSHELL $USERNAME
  19. chroot ${NEWROOT} passwd -d $USERNAME >/dev/null 2>&1
  20. # Setup default root/user password (voidlinux).
  21. chroot ${NEWROOT} sh -c 'echo "root:voidlinux" | chpasswd -c SHA512'
  22. chroot ${NEWROOT} sh -c "echo "$USERNAME:voidlinux" | chpasswd -c SHA512"
  23. # Enable sudo permission by default.
  24. if [ -f ${NEWROOT}/etc/sudoers ]; then
  25. echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> ${NEWROOT}/etc/sudoers
  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