Skip to content

Instantly share code, notes, and snippets.

@Lemon2ee
Last active August 18, 2024 01:29
Show Gist options
  • Save Lemon2ee/f51acc99e48052e735cb3abead305f05 to your computer and use it in GitHub Desktop.
Save Lemon2ee/f51acc99e48052e735cb3abead305f05 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Function to hide or show output based on -v flag
log() {
if [ "$VERBOSE" = true ]; then
"$@"
else
"$@" > /dev/null 2>&1
fi
}
# Function to generate a random password
generate_password() {
< /dev/urandom tr -dc 'A-Za-z0-9-_!@#%&*+=?' | head -c 32
}
# Check for -v flag and capture email and domain
VERBOSE=false
while getopts "v" flag; do
case "${flag}" in
v) VERBOSE=true ;;
esac
done
shift $((OPTIND - 1))
# Check for domain and email in arguments
domain="$1"
email="$2"
# If domain or email not provided, prompt the user
if [ -z "$domain" ]; then
read -p "Enter your domain: " domain
fi
if [ -z "$email" ]; then
read -p "Enter your email: " email
fi
# Step 1: Update package list
echo "Step 1: Running apt update"
log apt update -y
# Step 2: Upgrade packages and install necessary tools
echo "Step 2: Running apt upgrade and installing necessary tools"
log apt upgrade -y
log apt install curl wget iperf3 neofetch htop iptables -y
# Step 3: Install Hysteria
echo "Step 3: Installing Hysteria"
log bash <(curl -fsSL https://get.hy2.sh/) --version v2.5.0
# Step 4: Enable Hysteria service
echo "Step 4: Enabling Hysteria service"
log systemctl enable hysteria-server.service
# Step 5: Create directory for custom systemd configuration
echo "Step 5: Creating directory for custom systemd configuration"
log mkdir /etc/systemd/system/hysteria-server.service.d
# Step 6: Write custom CPU scheduling configuration
echo "Step 6: Writing custom CPU scheduling configuration"
cat <<EOT | log tee /etc/systemd/system/hysteria-server.service.d/priority.conf
[Service]
CPUSchedulingPolicy=rr
CPUSchedulingPriority=99
EOT
# Step 7: Apply sysctl settings
echo "Step 7: Applying sysctl settings"
log sysctl -w net.core.rmem_max=16777216
log sysctl -w net.core.wmem_max=16777216
# Generate a random password
password=$(generate_password)
# Step 8: Write Hysteria configuration
echo "Step 8: Writing Hysteria configuration"
cat <<EOT | log tee /etc/hysteria/config.yaml
acme:
domains:
- $domain
email: $email
auth:
type: password
password: $password
masquerade:
type: proxy
proxy:
url: https://news.ycombinator.com/
rewriteHost: true
EOT
# Step 9: Set up iptables rule
echo "Step 9: Setting up iptables rule"
log iptables -t nat -A PREROUTING -i eth0 -p udp --dport 20000:50000 -j REDIRECT --to-ports 443
# Step 10: Reload systemd daemon
echo "Step 10: Reloading systemd daemon"
log systemctl daemon-reload
# Step 11: Start Hysteria service
echo "Step 11: Starting Hysteria service"
log systemctl start hysteria-server.service
echo "Setup complete!"
echo "Generated password: $password"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment