Skip to content

Instantly share code, notes, and snippets.

@Epictek
Forked from Zenexer/userdir.sh
Created March 6, 2018 11:38
Show Gist options
  • Save Epictek/eb2797d48b9f6e998e877dc598f17f86 to your computer and use it in GitHub Desktop.
Save Epictek/eb2797d48b9f6e998e877dc598f17f86 to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ $# -lt 1 ]; then
echo "Syntax: $_ USER[ USER[ ...]]" >&2
exit 1
fi
exit_code=0
for user in "$@"; do
home="/home/$user"
cp -R /etc/skel "$home" && echo $'\e[32m'"Copied skeleton to: $home"$'\e[m' || ( exit_code=$?; echo $'\e[31m'"Failed to create: $home"$'\e[m' ) >&2
chown -R "$user:$user" "$home" && echo $'\e[32m'"Set owner on: $home"$'\e[m' || ( exit_code=$?; echo $'\e[31m'"Failed to set owner on: $home"$'\e[m' ) >&2
done
exit $exit_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment