adduser.sh 1.0 KB

12345678910111213141516171819202122232425262728
  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. rm -f "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  20. sed -e "s|/sbin/agetty --noclear|& -a ${USERNAME}|g" \
  21. "${NEWROOT}/usr/lib/systemd/system/[email protected]" > \
  22. "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"