Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #This script will do the following based on the MACs.txt mac address provided in the same folder:
- #Make a home directory.
- #Add a system user assigned to home directory.
- #Assign ownership to home directory.
- #Set user's password.
- #Add a corrosponding entry in '/var/lib/tftpboot/ltsp/i386/lts.conf'
- #Set lts.conf to a default state.
- #Any changes made to lts.conf need to be made here, or be overriden.
- cat > /var/lib/tftpboot/ltsp/i386/lts.conf <<EOF
- # http://manpages.ubuntu.com/manpages/maverick/en/man5/lts.conf.5.html
- [default]
- LDM_DIRECTX = TRUE
- LDM_GUESTLOGIN = TRUE
- VOLUME = 75
- X_RAMPERC = 80
- LANG = en_US.UTF-8
- LANGUAGE = en_US.UTF-8
- DNS_SERVER = 192.168.41.1
- HOSTNAME_BASE = lava-lab-
- HASTNAME_EXTRA = mac
- TIMEZONE = GMT-7
- TIMERSERVER = 192.168.41.1
- SHUTDOWN_TIME = 16:00:00
- SOUND = TRUE
- SOUND_DAEMON = pulse
- HEADPHONE_VOLUME = 75
- FRONT_VOLUME = 0
- EOF
- #Define create_account() function.
- #create_account() is called while looping through MACs.txt on each mac address.
- create_account()
- {
- #user2 should be the full mac address passed to create_account()
- user2=$1
- #Test if user already exists
- if getent passwd $user2 >/dev/null; then
- #user exists
- echo User Exists, skipping: $user2
- else
- #user does not exists
- echo Creating home directory for user: $user2
- sudo mkdir /home/$user2 && sudo useradd $user2 -d /home/$user2 && sudo chown -R $user2 /home/$user2
- echo "$user2:PASSWORD" | sudo chpasswd
- fi
- }
- create_account student-template
- #loop through MACs.txt and perform actions on each mac, line by line.
- cat MACs.txt \
- | while read mac; do
- shortmac=`echo $mac | perl -pe 's/(..):(..):(..):(..):(..):(..)/$5$6/'`
- user=student-$shortmac
- cat >> /var/lib/tftpboot/ltsp/i386/lts.conf<<EOF
- [$mac]
- HOSTNAME = LHA-Student-LAB-$shortmac
- LDM_USERNAME = $user
- LDM_PASSWORD = PASSWORD
- LDM_AUTOLOGIN = TRUE
- EOF
- create_account $user
- done
- exit 0
Add Comment
Please, Sign In to add comment