I am distributing a VM to my students for a beginners programming course. For speed, instead of getting them to install Ubuntu from scratch, I'm planning to give them a fully set up image that they can just run.
In order to get it set up I've given it a sacrificial hostname, username and password. What's the cleanest way to change this for the students when they get up and running?
I've got as far as this gist, which has some unreliable progress with the hostname, but the username is resisting me changing it.
I'd like it to be as painless a process as possible as this is supposed to happen in their first lab.
It's entirely possible that there is a completely different approach that I ought to take. I'm open to all suggestions.
#!/bin/bash
clear
toilet " CODE1161 " --metal --font future
echo ""
toilet "Let's get started!" --metal --font future
echo ""
echo "We need to make this computer be YOURS"
echo "We need a name for you and your computer, make it short or it'll take up a lot of space."
echo "My computer is called um and my name is ben, so I get ben@um:~$ as my command prompt."
echo ""
read -p "Enter a name for your computer:" compname
read -p "Enter your name: " username
echo ""
toilet "$username@$compname~$" --gay --font wideterm
echo ""
echo "What do you think? If you hate it, press ctrl+c and do this again"
read -p "otherwise, just press enter." sacrificial
# set the host name, in a million places, for some unknown reason.
echo "1"
sed -i "/127\.0\.1\.1\s*vc/ { c \
127.0.1.1 $compname
}" /etc/hosts
echo "2"
sudo hostname -b $compname
echo "3"
sudo hostnamectl set-hostname $compname
echo "4"
sudo groupadd $username
echo "5"
sudo usermod -d /home/$username -m -g $username -l $username ben
expect
- http://www.admin-magazine.com/Articles/Automating-with-Expect-Scripts – Panther Feb 01 '17 at 21:15expect
to take an interactive process and make it non-interactive. Basically, making a script thatexpect
certain output and having the response already known in the script. Ben wants to wait for user input and execute a command based on it. Granted, I'm wrong at least once a day, so this might be the case. – Feb 01 '17 at 21:40exec bash
but it will technically open up a nested terminal. – Feb 02 '17 at 02:00sed
with something like this..sudo sed -i "s/127.0.1.1/& $compname/" /etc/hosts
Which will update the 127.0.1.1 line, and just append the new host to what's there. It will leave the old host in place, but it's compliant to have multiple hosts assigned to one IP. That will prevent the unresolvable issue with your othersudo
command, changing the hostname. – Feb 02 '17 at 02:05