#!/bin/bash # 获取参数 ACTION=$1 OS_ID=$(grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') # 根据参数执行不同命令 case $ACTION in "start") echo "Starting service..." # 启动服务的命令 echo "$DevstarHost host.docker.internal" | tee -a /etc/hosts; case $OS_ID in ubuntu|debian) apt-get update -y apt-get install ssh git -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 echo -e "PubkeyAuthentication yes\nPermitRootLogin yes\n" | tee -a /etc/ssh/sshd_config; rm -f /etc/ssh/ssh_host_*; ssh-keygen -A; mkdir -p ~/.ssh; chmod 700 ~/.ssh; case $OS_ID in ubuntu|debian) service ssh restart; ;; centos) ;; fedora) ;; *) failure "Unsupported OS: $OS_ID" exit 1 ;; esac echo "$PublicKeyList" > ~/.ssh/authorized_keys; chmod 600 ~/.ssh/authorized_keys git clone $RepoLink $WorkSpace ;; "stop") echo "Stopping service..." # 停止服务的命令 ;; "restart") echo "Restarting service..." # 重启服务的命令 ;; *) echo "Usage: $0 {start|stop|restart}" exit 1 ;; esac