bakeradd
This commit is contained in:
parent
2c70e161c2
commit
90b34e2f9f
|
@ -0,0 +1,45 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# bakeradd: utility to add bakers
|
||||||
|
# run with sudo
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
shell=/bin/bash
|
||||||
|
name=
|
||||||
|
groups=bakers
|
||||||
|
keyfile=
|
||||||
|
user=
|
||||||
|
|
||||||
|
die()
|
||||||
|
{
|
||||||
|
case "$1" in
|
||||||
|
[0-9]*) ec=$?; shift ;;
|
||||||
|
*) ec=1 ;;
|
||||||
|
esac
|
||||||
|
echo "!! bakeradd : $@"
|
||||||
|
exit "$ec"
|
||||||
|
}
|
||||||
|
|
||||||
|
while getopts s:n:G:k:u: opt; do
|
||||||
|
case "$opt" in
|
||||||
|
s) shell="$OPTARG" ;;
|
||||||
|
n) name="$OPTARG" ;;
|
||||||
|
G) groups="$groups${groups:+,}$OPTARG" ;;
|
||||||
|
k) keyfile="$OPTARG" ;;
|
||||||
|
u) user="$OPTARG" ;;
|
||||||
|
\?) die 2 "Unknown arg "-$opt" ;;
|
||||||
|
*) exit 2 ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
[ -z "$name" ] && die "Need a name"
|
||||||
|
[ -z "$user" ] && die "Need a username"
|
||||||
|
[ -z "$keyfile" ] && die "Need a keyfile"
|
||||||
|
|
||||||
|
echo "Adding the user..."
|
||||||
|
adduser --shell="$shell" --gecos="$name" --disabled-password "$user"
|
||||||
|
usermod -a -G"$groups" "$user"
|
||||||
|
|
||||||
|
"echo "Setting up ssh..."
|
||||||
|
sudo --user="$user" mkdir "/home/$user/.ssh"
|
||||||
|
sudo --user="$user" cp "$keyfile" "/home/$user/.ssh/authorized_keys2"
|
Loading…
Reference in New Issue