🛠 Project: New Teammate Script
New people join the web team every month, and each one needs the same setup. Ivana's list is in ~/new-hires.txt. Doing it by hand means five commands per person, and one day someone gets forgotten in the wrong group. Your job: one script that does it all:
sudo ~/scripts/onboard.sh lena
What the script has to do
- Without a name, print how to use it (
Usage: onboard.sh USERNAME) and stop with an error - Create the account, with a home folder and bash as its shell
- Put it into the
developersgroup - Make a
projectsfolder in the new home folder, owned by the new user - Say that it's done
Building blocks
echo "Hello, $1" # $1: the first word after the script's name
if [ -z "$1" ]; then echo "no name"; exit 1; fi # -z: empty; exit 1 stops with an error
useradd -m -s /bin/bash NAME # Account, home folder (-m), shell (-s)
usermod -aG developers NAME # Into the group, keeping the others (-a)
mkdir /home/NAME/projects
chown NAME:NAME /home/NAME/projects # Owner and group
💡 The script runs with
sudo, so everything in it runs as root — nosudoneeded inside. Test the "no name" case too:~/scripts/onboard.sh; echo $?shows the exit status.