74 lines
1.9 KiB
Bash
74 lines
1.9 KiB
Bash
#!/bin/bash
|
|
# Copyright 2025 Mengning Software All rights reserved.
|
|
|
|
# Exit immediately if a command exits with a non-zero status
|
|
set -e
|
|
|
|
# Colors for output
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to display success message
|
|
function success {
|
|
echo -e "${GREEN}$1${NC}"
|
|
}
|
|
|
|
# Function to display failure message
|
|
function failure {
|
|
echo -e "${RED}$1${NC}"
|
|
}
|
|
|
|
# Detect the OS type and install dependencies
|
|
function install_dependencies {
|
|
# Install dependencies based on the OS type
|
|
success "dependencies install begin: "
|
|
OS_ID=$(grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"')
|
|
|
|
case $OS_ID in
|
|
ubuntu|debian)
|
|
sudo apt-get update -y
|
|
sudo apt-get install ssh -y
|
|
;;
|
|
centos)
|
|
# sudo yum update -y
|
|
# sudo yum install -y epel-release
|
|
# sudo yum groupinstall -y "Development Tools"
|
|
# sudo yum install -y yaml-cpp yaml-cpp-devel
|
|
;;
|
|
fedora)
|
|
# sudo dnf update -y
|
|
# sudo dnf group install -y "Development Tools"
|
|
# sudo dnf install -y yaml-cpp yaml-cpp-devel
|
|
;;
|
|
*)
|
|
failure "Unsupported OS: $OS_ID"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
install_dependencies
|
|
|
|
echo -e "PubkeyAuthentication yes\nPermitRootLogin yes\n" | tee -a /etc/ssh/sshd_config
|
|
rm -f /etc/ssh/ssh_host_*; ssh-keygen -A; service ssh restart
|
|
|
|
if [ -z "${host_docker_internal+x}" ]; then
|
|
echo "$HOST_DOCKER_INTERNAL host.docker.internal" | tee -a /etc/hosts;
|
|
fi
|
|
|
|
if [ ! -d "$WORKDIR" ]; then
|
|
git clone $REPO_URL $WORKDIR && echo "Git Repository cloned.";
|
|
else
|
|
echo "Folder already exists.";
|
|
fi
|
|
|
|
mkdir -p ~/test
|
|
mkdir -p ~/.ssh
|
|
chmod 700 ~/.ssh
|
|
echo "$AUTHORIZED_KEYS" > ~/.ssh/authorized_keys
|
|
chmod 600 ~/.ssh/authorized_keys
|
|
|
|
git clone "https://devstar.cn/init/ttyd.git" "/usr/bin/ttyd"
|
|
apt-get install -y build-essential cmake git libjson-c-dev libwebsockets-dev
|
|
/usr/bin/ttyd/ttyd/ttyd -W -w $WORKDIR bash & |