From abd5262630d28a01768fb19af706b750b31f8b37 Mon Sep 17 00:00:00 2001 From: sose Date: Tue, 28 Aug 2018 17:39:44 +0000 Subject: [PATCH] Added scripts --- deluser.sh | 6 ++++++ listen.sh | 3 +++ login.sh | 3 +++ lxcinit.sh | 7 +++++++ newuser.sh | 14 ++++++++++++++ sendmsg.sh | 9 +++++++++ tmuxinit.sh | 10 ++++++++++ 7 files changed, 52 insertions(+) create mode 100755 deluser.sh create mode 100755 listen.sh create mode 100755 login.sh create mode 100755 lxcinit.sh create mode 100755 newuser.sh create mode 100755 sendmsg.sh create mode 100755 tmuxinit.sh diff --git a/deluser.sh b/deluser.sh new file mode 100755 index 0000000..8619121 --- /dev/null +++ b/deluser.sh @@ -0,0 +1,6 @@ +#!/bin/sh +USER=$1 +lxc stop $USER +sudo rm -rf $USER +sudo userdel $USER +lxc delete $USER diff --git a/listen.sh b/listen.sh new file mode 100755 index 0000000..0f9080c --- /dev/null +++ b/listen.sh @@ -0,0 +1,3 @@ +#!/bin/sh +nc -l localhost 9191 +#cat gamelog.txt | nc -q2 10.161.77.78 9090 diff --git a/login.sh b/login.sh new file mode 100755 index 0000000..fdbd964 --- /dev/null +++ b/login.sh @@ -0,0 +1,3 @@ +#!/bin/sh +. /etc/profile.d/apps-bin-path.sh +lxc exec $(whoami) /usr/bin/tmuxinit.sh diff --git a/lxcinit.sh b/lxcinit.sh new file mode 100755 index 0000000..0bb87ad --- /dev/null +++ b/lxcinit.sh @@ -0,0 +1,7 @@ +#!/bin/bash +#WARRNING: THIS SHOULD ONLY BE INVOKED FROM newuser.sh +echo " Launching container for user $(whoami)" +. /etc/profile.d/apps-bin-path.sh \ + && lxc launch ubuntu: $(whoami) +lxc file push /home/slbr/tmuxinit.sh $(whoami)/usr/bin/tmuxinit.sh +lxc file push /home/slbr/suicidebash.bashrc $(whoami)/etc/bash.bashrc diff --git a/newuser.sh b/newuser.sh new file mode 100755 index 0000000..438f33d --- /dev/null +++ b/newuser.sh @@ -0,0 +1,14 @@ +#!/bin/sh +USER=$1 + +echo "Creating homedir..." +mkdir "/home/slbr/$USER" +echo "lxc exec $USER bash" > "/home/slbr/$USER/.profile" +chmod -w "/home/slbr/$USER/.profile" +echo "Creating user..." +sudo useradd $USER -d "/home/slbr/$USER" +sudo usermod -a -G lxd $USER +sudo chown "$USER:$USER" "/home/slbr/$USER" +sudo chsh $USER -s /home/slbr/login.sh +echo "Creating container..." +sudo su $USER -s /bin/sh -c "/home/slbr/lxcinit.sh" diff --git a/sendmsg.sh b/sendmsg.sh new file mode 100755 index 0000000..f5685e9 --- /dev/null +++ b/sendmsg.sh @@ -0,0 +1,9 @@ +#!/bin/bash +function send { + ADRESSES=$(lxc list | cut -f 4 -d '|' \ + | grep -Eo "[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*") + for ADRESS in $ADRESSES + do + echo $1 | nc -q2 $ADRESS 9090 + done +} diff --git a/tmuxinit.sh b/tmuxinit.sh new file mode 100755 index 0000000..4cf92f6 --- /dev/null +++ b/tmuxinit.sh @@ -0,0 +1,10 @@ +#!/bin/sh +CNFHANDLE="function command_not_found_handle { echo Wrong; }" +tmux new-session -d -n test +tmux select-window -t 0:0 +tmux send -t 0:0 'nc -lkp 9090' ENTER +tmux split-window -h bash +tmux send -t 0:1 $CNFHANDLE ENTER +tmux select-layout +tmux resize-pane -t 1 -L 60 +tmux a