vmklive-adduser.sh 1.1 KB

123456789101112131415161718192021222324252627
  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. USERNAME=$(getarg live.user)
  5. [ -z "$USERNAME" ] && USERNAME=anon
  6. # Create /etc/default/live.conf to store USER.
  7. echo "USERNAME=$USERNAME" >> ${NEWROOT}/etc/default/live.conf
  8. chmod 644 ${NEWROOT}/etc/default/live.conf
  9. # Create new user and remove password. We'll use autologin by default.
  10. chroot ${NEWROOT} useradd -c $USERNAME -m $USERNAME -G audio,video,wheel -s /bin/sh
  11. chroot ${NEWROOT} passwd -d $USERNAME 2>&1 >/dev/null
  12. # Enable sudo permission by default.
  13. if [ -f ${NEWROOT}/etc/sudoers ]; then
  14. echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> ${NEWROOT}/etc/sudoers
  15. fi
  16. # Enable autologin for agetty(8).
  17. if [ -f ${NEWROOT}/usr/lib/systemd/system/[email protected] ]; then
  18. rm -f "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  19. sed -e "s|/sbin/agetty --noclear|& -a ${USERNAME}|g" \
  20. "${NEWROOT}/usr/lib/systemd/system/[email protected]" > \
  21. "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  22. fi