SLBR/newuser.sh

33 lines
1.2 KiB
Bash
Raw Normal View History

2018-08-28 17:39:44 +00:00
#!/bin/sh
# newuser.sh
# creates a new player
2018-09-14 17:39:19 +00:00
SLBRUSER=$1
2018-09-19 15:49:44 +00:00
PUBKEY=$2
test -z "$SLBRUSER" && echo "no user provided" && exit
2018-09-24 18:28:07 +00:00
test -z "$PUBKEY" && echo "no key provided" && exit
PUBKEY="$(cat "$PUBKEY")"
2018-09-25 18:30:12 +00:00
cut -d: -f1 /etc/passwd | grep -qx "$SLBRUSER" && echo "user already exists" && exit
2018-08-28 17:39:44 +00:00
echo "Creating homedir..."
mkdir "/home/slbr/users/$SLBRUSER"
mkdir "/home/slbr/users/$SLBRUSER/.ssh"
2018-09-19 20:43:25 +00:00
echo "Copying key..."
echo "$PUBKEY" >> "/home/slbr/users/$SLBRUSER/.ssh/authorized_keys"
2018-09-19 20:43:25 +00:00
echo "Creating container..."
echo "lxc exec $SLBRUSER bash" > "/home/slbr/users/$SLBRUSER/.profile"
chmod -w "/home/slbr/users/$SLBRUSER/.profile"
2018-08-28 17:39:44 +00:00
echo "Creating user..."
sudo useradd "$SLBRUSER" -d "/home/slbr/users/$SLBRUSER"
sudo usermod -a -G lxd "$SLBRUSER"
sudo cp ./killme.sh "/home/slbr/users/$SLBRUSER/killme.sh"
sudo chmod +x "/home/slbr/users/$SLBRUSER"
sudo chown -R "$SLBRUSER:$SLBRUSER" "/home/slbr/users/$SLBRUSER"
sudo chsh "$SLBRUSER" -s /home/slbr/login.sh
2018-09-19 20:43:25 +00:00
echo "Generating user keypair..."
sudo su "$SLBRUSER" -s /bin/sh -c "ssh-keygen -t rsa -N '' -f /home/slbr/users/$SLBRUSER/.ssh/id_rsa"
2018-09-19 20:43:25 +00:00
echo "Initializing container..."
sudo su "$SLBRUSER" -s /bin/sh -c "/home/slbr/lxcinit.sh"
2018-10-11 04:50:26 +00:00
echo "$SLBRUSER" >> users.txt