adduser.sh 1.1 KB

1234567891011121314151617181920212223242526272829
  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 audio,video,wheel -s /bin/sh
  12. chroot ${NEWROOT} passwd -d $USERNAME 2>&1 >/dev/null
  13. # Enable sudo permission by default.
  14. if [ -f ${NEWROOT}/etc/sudoers ]; then
  15. echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> ${NEWROOT}/etc/sudoers
  16. fi
  17. # Enable autologin for agetty(8).
  18. if [ -f ${NEWROOT}/usr/lib/systemd/system/[email protected] ]; then
  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]"
  23. fi