vmklive-adduser.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 getty(1).
  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|/usr/sbin/live-getty|g" \
  20. "${NEWROOT}/usr/lib/systemd/system/[email protected]" > \
  21. "${NEWROOT}/etc/systemd/system/getty.target.wants/[email protected]"
  22. fi
  23. # Create /usr/sbin/live-getty.
  24. cat > ${NEWROOT}/usr&sbin/live-getty <<_EOF
  25. #!/bin/sh
  26. if [ -x /usr/sbin/agetty ]; then
  27. _getty=/usr&sbin/agetty
  28. elif [ -x /usr/sbin/getty ]; then
  29. _getty=/usr/sbin/getty
  30. fi
  31. exec \${_getty} -n -l /usr/sbin/live-autologin \$*
  32. _EOF
  33. chmod 755 ${NEWROOT}/usr/sbin/live-getty
  34. # Create /usr/sbin/live-autologin.
  35. cat > ${NEWROOT}/usr/sbin/live-autologin <<_EOF
  36. #!/bin/sh
  37. . /etc/default/live.conf
  38. exec /usr/bin/login -f \$USERNAME
  39. _EOF
  40. chmod 755 ${NEWROOT}/usr/sbin/live-autologin