Skip to content

Instantly share code, notes, and snippets.

@VendettaReborn
Last active November 27, 2024 04:52
Show Gist options
  • Save VendettaReborn/d8f8b546241e259f1cb18ce7b36b4106 to your computer and use it in GitHub Desktop.
Save VendettaReborn/d8f8b546241e259f1cb18ce7b36b4106 to your computer and use it in GitHub Desktop.
shadow-tls install script(ubuntu/centos/arch)
#! /bin/bash
red='\033[0;31m'
yellow='\033[1;33m'
blue='\033[0;34m'
green='\033[0;32m'
NC='\033[0m' # No Color
function echo_color()
{
for ((i=1; i<=$#; i+=2)); do
color=${!i}
content=$(($i + 1))
echo -e -n "${!color}${!content}${NC} "
done
echo;
}
# Function to install Docker
install_docker() {
if [[ $1 =~ Ubuntu ]]; then
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
if ! grep -q -R "download.docker.com" /etc/apt/sources.list.d > /dev/null 2>&1; then
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
fi
sudo apt-get update
sudo apt-get install -y docker-ce
elif [[ $1 =~ CentOS ]]; then
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
if ! yum repolist | grep -q docker-ce-stable; then
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
fi
sudo yum install -y docker-ce
sudo systemctl start docker
sudo systemctl enable docker
elif [[ $1 =~ (Arch|Manjaro) ]]; then
sudo pacman -Syu
sudo pacman -S --noconfirm docker
sudo systemctl start docker.service
sudo systemctl enable docker.service
else
echo "Unsupported operating system for this script."
exit 1
fi
}
# Function to install Docker-Compose
install_docker_compose() {
sudo curl -L "https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
}
# Function to check and install Docker and Docker-Compose
check_and_install() {
if command -v docker >/dev/null 2>&1 && command -v docker-compose >/dev/null 2>&1; then
echo_color yellow "Docker and Docker-Compose are already installed."
return
fi
read -p "Do you want to install Docker and Docker-Compose? (y/n): " answer
if [[ "$answer" != "y" ]]; then
echo_color red "Installation aborted."
exit 0
fi
# Install Docker
echo_color yellow "Installing Docker..."
install_docker "$OS"
# Install Docker-Compose
echo_color yellow "Installing Docker-Compose..."
install_docker_compose
}
# Detect Operating System
OS=""
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
fi
## 0. install docker or quit, or continue(if they have already been installed)
check_and_install
## 1. configs
# default values for shadowsocks
SHADOWSOCKS_PORT=24000
SHADOWSOCKS_DEFAULT_PASSWORD=$(openssl rand -base64 24)
# Default values for shadow-tls
SHADOWTLS_DEFAULT_PASSWORD=$(openssl rand -base64 24)
DEFAULT_SITE="www.feishu.cn"
DEFAULT_VPS_IP=$(curl ifconfig.me)
DEFAULT_VPS_PORT="12345"
echo_color yellow "preparing shadowsocks & shadow-tls configs..."
# Prompt for user input with default values
read -p "Enter Shadowsocks password [default generated by openssl:${SHADOWSOCKS_DEFAULT_PASSWORD}]: " SHADOWSOCKS_PASSWORD
SHADOWSOCKS_PASSWORD=${SHADOWSOCKS_PASSWORD:-$SHADOWSOCKS_DEFAULT_PASSWORD}
read -p "Enter Shadow-TLS password [default generated by openssl:${SHADOWTLS_DEFAULT_PASSWORD}]: " SHADOWTLS_PASSWORD
SHADOWTLS_PASSWORD=${SHADOWTLS_PASSWORD:-$SHADOWTLS_DEFAULT_PASSWORD}
# Prompt for user input with default values
read -p "Enter hijack site [default:${DEFAULT_SITE}]: " SITE
SITE=${SITE:-$DEFAULT_SITE}
read -p "Enter VPS IP [default:${DEFAULT_VPS_IP}]: " VPS_IP
VPS_IP=${VPS_IP:-$DEFAULT_VPS_IP}
read -p "Enter VPS port [default:${DEFAULT_VPS_PORT}]: " VPS_PORT
VPS_PORT=${VPS_PORT:-$DEFAULT_VPS_PORT}
## 2. docker-compose
mkdir -p $HOME/.shadow-tls &&
cat << EOF > "${HOME}/.shadow-tls/docker-compose.yml"
version: '2.4'
services:
shadowsocks:
image: shadowsocks/shadowsocks-libev
container_name: shadowsocks-raw
restart: always
network_mode: "host"
environment:
- SERVER_PORT=${SHADOWSOCKS_PORT}
- SERVER_ADDR=127.0.0.1
- METHOD=chacha20-ietf-poly1305
- "PASSWORD=${SHADOWSOCKS_PASSWORD}"
shadow-tls:
image: ghcr.io/ihciah/shadow-tls:latest
restart: always
network_mode: "host"
environment:
- MODE=server
- LISTEN=0.0.0.0:${VPS_PORT}
- SERVER=127.0.0.1:${SHADOWSOCKS_PORT}
- TLS=${SITE}:443
- "PASSWORD=${SHADOWTLS_PASSWORD}"
- V3=1
EOF
cd "${HOME}/.shadow-tls"
/usr/local/bin/docker-compose up -d
## 3. print the params and auto-generated clash config
echo_color yellow "Installed!"
echo_color yellow "vps ip : ${VPS_IP}"
echo_color yellow "vps port : ${VPS_PORT}"
echo_color yellow "shadowsocks password : ${SHADOWSOCKS_PASSWORD}"
echo_color yellow "shadow-tls hijack site : ${SITE}"
echo_color yellow "shadow-tls password : ${SHADOWTLS_PASSWORD}"
if [ -f "${HOME}/shadow-tls/saved.yaml" ]; then
mv "${HOME}/shadow-tls/saved.yaml" "${HOME}/shadow-tls/saved-$(date +%Y-%m-%d-%H-%M-%S).yaml"
fi
echo "# auto generated by shadow-tls-startup.sh
proxies:
- name: SHADOW_TLS_PROXY
type: ss
server: ${VPS_IP}
port: ${VPS_PORT}
cipher: chacha20-ietf-poly1305
password: "${SHADOWSOCKS_PASSWORD}"
plugin: shadow-tls
plugin-opts:
host: ${SITE}
password: "${SHADOWTLS_PASSWORD}"
version: 3
" > ${HOME}/.shadow-tls/saved.yaml
CLASH_RESULT=`cat ${HOME}/.shadow-tls/saved.yaml`
echo ""
echo_color red "${CLASH_RESULT}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment