Skip to content

Commit

Permalink
Merge pull request #59 from DEVROOM-OFFICIAL/feature/wetty
Browse files Browse the repository at this point in the history
✨ wetty 기반 web ssh 추가
  • Loading branch information
Yanghyeondong authored Aug 26, 2024
2 parents 0922051 + 374b129 commit b20bdab
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ private void createService(String className, String studentId, String port, Map<
labels.put("connection", "ssh");
}

// web ssh (wetty) 용 포트개방
if (options.containsKey("web_ssh") && options.get("web_ssh").equals("yes")){
inPort = "3000";
labels.put("connection", "web_ssh");
}

if (!labels.containsKey("connection")){
labels.put("connection", "none");
}
Expand Down Expand Up @@ -173,6 +179,13 @@ private void createConfingMap(String className, String studentId, Map<String, St
if (options.containsKey("ssh") && options.get("ssh").equals("yes"))
data.put("01_install_ssh.sh",FreemarkerTemplate.convert("/scripts/", "01_install_ssh.sh", template).replaceAll("\\r", ""));

// wetty 설치용 스크립트
if (options.containsKey("web_ssh") && options.get("web_ssh").equals("yes")) {
data.put("01_install_ssh.sh",FreemarkerTemplate.convert("/scripts/", "01_install_ssh.sh", template).replaceAll("\\r", ""));
data.put("03_install_wetty.sh",FreemarkerTemplate.convert("/scripts/", "03_install_wetty.sh", template).replaceAll("\\r", ""));
}


// vscode 설치용 스크립트
if (options.containsKey("vscode") && options.get("vscode").equals("yes"))
data.put("02_install_vscode.sh",FreemarkerTemplate.convert("/scripts/", "02_install_vscode.sh", template).replaceAll("\\r", ""));
Expand Down
68 changes: 68 additions & 0 deletions backend/src/main/resources/scripts/03_install_wetty.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

student_id=${student}
class_id=${class}
username="$student_id"-"$class_id"

sudo apt update -qq
sudo apt install -qq -y build-essential curl software-properties-common openssh-client

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update -qq
sudo apt install -qq -y python3.11 python3.11-venv python3.11-distutils

echo "Configuring Python 3.11 alternatives..."
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1

# Check if Python 3.11 is available and set it as default
PYTHON_PATH=$(which python3.11)
if [ -n "$PYTHON_PATH" ]; then
echo "Setting Python 3.11 as the default Python 3...=============================================="
sudo update-alternatives --set python3 /usr/bin/python3.11
else
echo "Python 3.11 not found in alternatives. Please check installation.==========================="
exit 1
fi

echo "Exporting Python environment variable..."
echo 'export PYTHON=/usr/bin/python3.11' >> ~/.bashrc
source ~/.bashrc

# WeTTY 설치 및 실행
su - $username <<EOF
python3 --version
# 필수 패키지 및 WeTTY 설치
curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash && source ~/.profile
source ~/.nvm/nvm.sh
nvm install 20
node -v
# SSL 설정
#mkdir -p ~/.ssl
#openssl req -x509 -nodes -days 1095 -newkey ec:<(openssl ecparam -name secp384r1) -subj "/C=GB/ST=None/L=None/O=None/OU=None/CN=None" -out ~/.ssl/wetty.crt -keyout ~/.ssl/wetty.key
#chmod 700 ~/.ssl
#chmod 644 ~/.ssl/wetty.crt
#chmod 600 ~/.ssl/wetty.key
# SSH 키 설정
#mkdir -p ~/.ssh
#ssh-keygen -q -C "wetty-keyfile" -t ed25519 -N '' -f ~/.ssh/wetty 2>/dev/null <<< y >/dev/null
#cat ~/.ssh/wetty.pub >> ~/.ssh/authorized_keys
#chmod 700 ~/.ssh
#chmod 644 ~/.ssh/authorized_keys
#chmod 600 ~/.ssh/wetty
# WeTTY 설치 및 실행
mkdir -p ~/bin && source ~/.profile
npm -g i wetty@2.5.0
wetty -h
# 접속 URL 출력
echo https://$(curl -s4 icanhazip.com):3000
# WeTTY 시작
wetty --host 0.0.0.0 --port 3000 --title $username --base / --ssh-host localhost --ssh-user $username --ssh-port 22 --ssh-auth password
EOF
2 changes: 1 addition & 1 deletion backend/src/main/resources/scripts/ubuntu_command.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
echo "init student container"
cp -r /app/config /script
chmod +x /script/ubuntu_init.sh
/script/ubuntu_init.sh >> /script/log
/script/ubuntu_init.sh >> /script/log 2>&1

0 comments on commit b20bdab

Please sign in to comment.