Better user creation/deletion
This commit is contained in:
parent
500e51695f
commit
8669f5f8aa
|
@ -30,6 +30,8 @@ contact ~ben or sose on tilde.chat (in the #slbr channel) to sign up.
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
- Install-time configuration (setting proper ips, hostname, etc.)
|
- Install-time configuration (setting proper ips, hostname, etc.)
|
||||||
|
- Fix user tracking
|
||||||
|
=======
|
||||||
- A goal and a way to check it
|
- A goal and a way to check it
|
||||||
|
|
||||||
This is a ~ work in progress ~
|
This is a ~ work in progress ~
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
SLBRUSER=$1
|
SLBRUSER=$1
|
||||||
test -z "$SLBRUSER" && echo "no user provided" && exit
|
test -z "$SLBRUSER" && echo "no user provided" && exit
|
||||||
|
grep -qv "$SLBRUSER" users.txt && echo "user not found in users.txt, will not delete" && exit
|
||||||
|
|
||||||
if ps -o stat= -p $PPID | grep -qv S+ #check if this is being called from listen.py
|
if ps -o stat= -p $PPID | grep -qv S+ #check if this is being called from listen.py
|
||||||
then
|
then
|
||||||
echo "YOU ARE ABOUT TO PERMANENTLY DELETE USER $SLBRUSER AND ALL OF THEIR DATA. RE-ENTER THE USERS NAME TO CONTINUE"
|
echo "YOU ARE ABOUT TO PERMANENTLY DELETE USER $SLBRUSER AND ALL OF THEIR DATA. RE-ENTER THE USERS NAME TO CONTINUE"
|
||||||
|
@ -11,5 +13,5 @@ lxc stop "$SLBRUSER"
|
||||||
lxc delete "$SLBRUSER"
|
lxc delete "$SLBRUSER"
|
||||||
sudo rm -rf "$SLBRUSER"
|
sudo rm -rf "$SLBRUSER"
|
||||||
sudo userdel "$SLBRUSER"
|
sudo userdel "$SLBRUSER"
|
||||||
tr '\n' ' ' < users | sed "s/$SLBRUSER //" | tr ' ' '\n' > users.temp
|
tr '\n' ' ' < users.txt | sed "s/$SLBRUSER//g" | tr ' ' '\n' > users.temp
|
||||||
mv users.temp users
|
mv users.temp users
|
||||||
|
|
14
listen.py
14
listen.py
|
@ -24,11 +24,17 @@ def clientthread(conn):
|
||||||
os.system("./sendmsg.sh \"$(tail -n1 gamelog.txt)\"") # oh noooooo
|
os.system("./sendmsg.sh \"$(tail -n1 gamelog.txt)\"") # oh noooooo
|
||||||
print("sent message: " + message)
|
print("sent message: " + message)
|
||||||
|
|
||||||
userisdead = (
|
userisdead = False
|
||||||
True
|
|
||||||
) # Eventually add a check to differentiate death messages from other messages
|
|
||||||
if userisdead:
|
|
||||||
deaduser = message.split(" ")[0]
|
deaduser = message.split(" ")[0]
|
||||||
|
|
||||||
|
print("Looking for user in userfile")
|
||||||
|
with open("users.txt") as userfile:
|
||||||
|
if deaduser in userfile.read():
|
||||||
|
userisdead = True
|
||||||
|
else:
|
||||||
|
print("could not find user in userfile, will not delete")
|
||||||
|
|
||||||
|
if userisdead:
|
||||||
print("eliminating " + deaduser)
|
print("eliminating " + deaduser)
|
||||||
os.system("./deluser.sh " + deaduser)
|
os.system("./deluser.sh " + deaduser)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
|
@ -2,13 +2,17 @@
|
||||||
SLBRUSER=$1
|
SLBRUSER=$1
|
||||||
PUBKEY=$2
|
PUBKEY=$2
|
||||||
test -z "$SLBRUSER" && echo "no user provided" && exit
|
test -z "$SLBRUSER" && echo "no user provided" && exit
|
||||||
|
test -z "$PUBKEY" && echo "no key provided" && exit
|
||||||
|
PUBKEY="$(cat "$PUBKEY")"
|
||||||
|
|
||||||
|
cut -d: -f1 /etc/passwd | grep -q "$SLBRUSER" && echo "user already exists" && exit
|
||||||
|
|
||||||
echo "Creating homedir..."
|
echo "Creating homedir..."
|
||||||
mkdir "/home/slbr/$SLBRUSER"
|
mkdir "/home/slbr/$SLBRUSER"
|
||||||
mkdir "/home/slbr/$SLBRUSER/.ssh"
|
mkdir "/home/slbr/$SLBRUSER/.ssh"
|
||||||
echo "Copying key..."
|
echo "Copying key..."
|
||||||
echo "$PUBKEY" >> "/home/slbr/$SLBRUSER/.ssh/authorized_keys"
|
echo "$PUBKEY" >> "/home/slbr/$SLBRUSER/.ssh/authorized_keys"
|
||||||
echo "$SLBRUSER" >> users
|
echo "$SLBRUSER" >> users.txt
|
||||||
echo "Creating container..."
|
echo "Creating container..."
|
||||||
echo "lxc exec $SLBRUSER bash" > "/home/slbr/$SLBRUSER/.profile"
|
echo "lxc exec $SLBRUSER bash" > "/home/slbr/$SLBRUSER/.profile"
|
||||||
chmod -w "/home/slbr/$SLBRUSER/.profile"
|
chmod -w "/home/slbr/$SLBRUSER/.profile"
|
||||||
|
|
Loading…
Reference in New Issue