Corbin22

AddComputers.sh

Mar 29th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.95 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #This script will do the following based on the MACs.txt mac address provided in the same folder:
  4. #Make a home directory.
  5. #Add a system user assigned to home directory.
  6. #Assign ownership to home directory.
  7.  
  8. #Set user's password.
  9. #Add a corrosponding entry in '/var/lib/tftpboot/ltsp/i386/lts.conf'
  10.  
  11. #Set lts.conf to a default state.
  12. #Any changes made to lts.conf need to be made here, or be overriden.
  13. cat > /var/lib/tftpboot/ltsp/i386/lts.conf <<EOF
  14. # http://manpages.ubuntu.com/manpages/maverick/en/man5/lts.conf.5.html
  15.  
  16. [default]
  17. LDM_DIRECTX = TRUE
  18. LDM_GUESTLOGIN = TRUE
  19.  
  20. VOLUME = 75
  21. X_RAMPERC = 80
  22.  
  23. LANG = en_US.UTF-8
  24. LANGUAGE = en_US.UTF-8
  25.  
  26. DNS_SERVER = 192.168.41.1
  27. HOSTNAME_BASE = lava-lab-
  28. HASTNAME_EXTRA = mac
  29. TIMEZONE = GMT-7
  30. TIMERSERVER = 192.168.41.1
  31. SHUTDOWN_TIME = 16:00:00
  32.  
  33. SOUND = TRUE
  34. SOUND_DAEMON = pulse
  35. HEADPHONE_VOLUME = 75
  36. FRONT_VOLUME = 0
  37.  
  38. EOF
  39.  
  40. #Define create_account() function.
  41. #create_account() is called while looping through MACs.txt on each mac address.
  42. create_account()
  43. {
  44. #user2 should be the full mac address passed to create_account()
  45. user2=$1
  46.  
  47. #Test if user already exists
  48. if getent passwd $user2 >/dev/null; then
  49.     #user exists
  50.     echo User Exists, skipping: $user2
  51. else
  52.     #user does not exists
  53.     echo Creating home directory for user: $user2
  54.  
  55.     sudo mkdir /home/$user2 && sudo useradd $user2 -d /home/$user2 && sudo chown -R $user2 /home/$user2
  56.     echo "$user2:PASSWORD" | sudo chpasswd
  57. fi
  58. }
  59.  
  60. create_account student-template
  61.  
  62. #loop through MACs.txt and perform actions on each mac, line by line.
  63. cat MACs.txt \
  64. | while read mac; do
  65.     shortmac=`echo $mac | perl -pe 's/(..):(..):(..):(..):(..):(..)/$5$6/'`
  66.     user=student-$shortmac
  67.  
  68.     cat >> /var/lib/tftpboot/ltsp/i386/lts.conf<<EOF
  69. [$mac]
  70. HOSTNAME = LHA-Student-LAB-$shortmac
  71. LDM_USERNAME = $user
  72. LDM_PASSWORD = PASSWORD
  73. LDM_AUTOLOGIN = TRUE
  74.  
  75. EOF
  76.  
  77.     create_account $user
  78. done
  79.  
  80. exit 0
Add Comment
Please, Sign In to add comment