Skip to content

Commit

Permalink
Make Tsuka working
Browse files Browse the repository at this point in the history
  • Loading branch information
Bisht13 committed Aug 12, 2023
1 parent 3769f05 commit f10eea5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 31 deletions.
25 changes: 13 additions & 12 deletions Tsuka/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def process_IN_MODIFY(self, event):
else:
print("Challenge name does not match specified format: ",filepath)


def start_notifier():
wm = pyinotify.WatchManager()
mask = pyinotify.IN_MODIFY
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch("/opt/katana/", mask, rec=False)
notifier.loop()

class SSHServer(paramiko.ServerInterface):
def check_auth_password(self, username, password):
# In this simple example, we allow authentication with any username and password
Expand All @@ -58,14 +67,6 @@ def check_channel_request(self, kind, chanid):
# We allow all channel requests
return paramiko.OPEN_SUCCEEDED

def start_notifier():
wm = pyinotify.WatchManager()
mask = pyinotify.IN_MODIFY
handler = EventHandler()
notifier = pyinotify.Notifier(wm, handler)
wdd = wm.add_watch(os.environ["ROOT_DIRECTORY"]+"/", mask, rec=False)
notifier.loop()

def start_ssh_server():
server = paramiko.Transport(('0.0.0.0', 22))
server.add_server_key(paramiko.RSAKey.generate(2048))
Expand All @@ -82,12 +83,12 @@ def start_ssh_server():

# TODO: add metrics/monitoring functionality
if __name__ == "__main__":
os.chmod("setup_script.sh", 0o755)
os.system("bash ./setup_script.sh")
os.system("rm -rf setup_script.sh")
os.chmod("setup-script.sh", 0o755)
os.system("bash ./setup-script.sh")
os.system("rm -rf setup-script.sh")
t = threading.Thread(target=start_notifier)
t.start()
# Start the SSH server in a separate thread
ssh_thread = threading.Thread(target=ssh_server_thread)
ssh_thread = threading.Thread(target=start_ssh_server)
ssh_thread.start()
app.run('0.0.0.0', os.environ['DAEMON_PORT'])
File renamed without changes.
14 changes: 14 additions & 0 deletions Tsuka/src/setup-script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mkdir challenge
cd challenge
apt upgrade
apt-get update -y
apt install git curl nano vim -y
DEBIAN_FRONTEND=noninteractive apt -y install openssh-server
service ssh start
mv /opt/katana/patch-challenge.sh /usr/bin/patch-challenge
mv /opt/katana/setup.sh /usr/bin/setup
chmod +x /usr/bin/patch-challenge
chmod +x /usr/bin/setup
git config --global user.email $HOSTNAME@katana.com
git config --global user.name $HOSTNAME
rm -rf /opt/katana/requirements.txt
14 changes: 7 additions & 7 deletions Tsuka/src/setup.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash
source /etc/profile
if [ ! -d "$ROOT_DIRECTORY/challenge/${2}" ]; then
mkdir "$ROOT_DIRECTORY/challenge/${2}"
if [ ! -d "/opt/katana/challenge/${2}" ]; then
mkdir "/opt/katana/challenge/${2}"
fi
tar -xf "$ROOT_DIRECTORY/katana_${2}_${1}.tar.gz" -C $ROOT_DIRECTORY/challenge/${2}
rm -rf "$ROOT_DIRECTORY/katana_${2}_${1}.tar.gz"
cd "$ROOT_DIRECTORY/challenge/${2}/${1}"
if [ ! -d "$ROOT_DIRECTORY/challenge/${2}/${1}/.git" ]; then
tar -xf "/opt/katana/katana_${2}_${1}.tar.gz" -C /opt/katana/challenge/${2}
rm -rf "/opt/katana/katana_${2}_${1}.tar.gz"
cd "/opt/katana/challenge/${2}/${1}"
if [ ! -d "/opt/katana/challenge/${2}/${1}/.git" ]; then
git init
git config --global --add safe.directory "$ROOT_DIRECTORY/challenge/${2}/${1}"
git config --global --add safe.directory "/opt/katana/challenge/${2}/${1}"
curl -H "Content-Type: application/json" -X POST -d '{"name":"'${1}'","description":"'${1}'","private":true}' "http://$GOGS/api/v1/user/repos?token=$PASSWORD"
git remote add origin "http://$PASSWORD@$GOGS/$USERNAME/${1}.git"
git branch -M master
Expand Down
12 changes: 0 additions & 12 deletions Tsuka/src/setup_script.sh

This file was deleted.

0 comments on commit f10eea5

Please sign in to comment.