Make menu
This commit is contained in:
283
install.sh
283
install.sh
@ -1,98 +1,225 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Ensure jq and qrencode are installed
|
# Function to install and configure Hysteria2
|
||||||
if ! command -v jq &> /dev/null || ! command -v qrencode &> /dev/null; then
|
install_and_configure() {
|
||||||
echo "Necessary packages are not installed. Please wait while they are being installed..."
|
|
||||||
apt-get update -qq && apt-get install jq qrencode -y >/dev/null 2>&1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Step 1: Install Hysteria2
|
# Ensure jq and qrencode are installed
|
||||||
echo "Installing Hysteria2..."
|
if ! command -v jq &> /dev/null || ! command -v qrencode &> /dev/null; then
|
||||||
bash <(curl -fsSL https://get.hy2.sh/) >/dev/null 2>&1
|
echo "Necessary packages are not installed. Please wait while they are being installed..."
|
||||||
|
apt-get update -qq && apt-get install jq qrencode -y >/dev/null 2>&1
|
||||||
|
fi
|
||||||
|
|
||||||
# Step 2: Create hysteria directory and navigate into it
|
# Step 1: Install Hysteria2
|
||||||
mkdir -p /etc/hysteria && cd /etc/hysteria/
|
echo "Installing Hysteria2..."
|
||||||
|
bash <(curl -fsSL https://get.hy2.sh/) >/dev/null 2>&1
|
||||||
|
|
||||||
# Step 3: Generate CA key and certificate
|
# Step 2: Create hysteria directory and navigate into it
|
||||||
echo "Generating CA key and certificate..."
|
mkdir -p /etc/hysteria && cd /etc/hysteria/
|
||||||
openssl ecparam -genkey -name prime256v1 -out ca.key >/dev/null 2>&1
|
|
||||||
openssl req -new -x509 -days 36500 -key ca.key -out ca.crt -subj "/CN=bing.com" >/dev/null 2>&1
|
|
||||||
|
|
||||||
# Step 4: Extract the SHA-256 fingerprint
|
# Step 3: Generate CA key and certificate
|
||||||
fingerprint=$(openssl x509 -noout -fingerprint -sha256 -inform pem -in ca.crt | sed 's/.*=//;s/://g')
|
echo "Generating CA key and certificate..."
|
||||||
|
openssl ecparam -genkey -name prime256v1 -out ca.key >/dev/null 2>&1
|
||||||
|
openssl req -new -x509 -days 36500 -key ca.key -out ca.crt -subj "/CN=bing.com" >/dev/null 2>&1
|
||||||
|
|
||||||
# Step 5: Generate the base64 encoded SHA-256 fingerprint
|
# Step 4: Extract the SHA-256 fingerprint
|
||||||
echo "Generating base64 encoded SHA-256 fingerprint..."
|
fingerprint=$(openssl x509 -noout -fingerprint -sha256 -inform pem -in ca.crt | sed 's/.*=//;s/://g')
|
||||||
echo "import re, base64, binascii
|
|
||||||
|
|
||||||
hex_string = \"$fingerprint\"
|
# Step 5: Generate the base64 encoded SHA-256 fingerprint
|
||||||
binary_data = binascii.unhexlify(hex_string)
|
echo "Generating base64 encoded SHA-256 fingerprint..."
|
||||||
base64_encoded = base64.b64encode(binary_data).decode('utf-8')
|
echo "import re, base64, binascii
|
||||||
|
|
||||||
print(\"sha256/\" + base64_encoded)" > generate.py
|
hex_string = \"$fingerprint\"
|
||||||
|
binary_data = binascii.unhexlify(hex_string)
|
||||||
|
base64_encoded = base64.b64encode(binary_data).decode('utf-8')
|
||||||
|
|
||||||
sha256=$(python3 generate.py)
|
print(\"sha256/\" + base64_encoded)" > generate.py
|
||||||
|
|
||||||
# Step 6: Download the config.yaml file
|
sha256=$(python3 generate.py)
|
||||||
echo "Downloading config.yaml..."
|
|
||||||
wget https://raw.githubusercontent.com/H-Return/Hysteria2/main/config.yaml -O /etc/hysteria/config.yaml >/dev/null 2>&1
|
|
||||||
sleep 5
|
|
||||||
clear
|
|
||||||
# Ask for the port number
|
|
||||||
read -p "Enter the port number you want to use: " port
|
|
||||||
|
|
||||||
# Step 7: Generate required passwords and UUID
|
# Step 6: Download the config.yaml file
|
||||||
echo "Generating passwords and UUID..."
|
echo "Downloading config.yaml..."
|
||||||
obfspassword=$(curl -s "https://api.genratr.com/?length=32&uppercase&lowercase&numbers" | jq -r '.password')
|
wget https://raw.githubusercontent.com/H-Return/Hysteria2/main/config.yaml -O /etc/hysteria/config.yaml >/dev/null 2>&1
|
||||||
authpassword=$(curl -s "https://api.genratr.com/?length=32&uppercase&lowercase&numbers" | jq -r '.password')
|
|
||||||
UUID=$(curl -s https://www.uuidgenerator.net/api/version4)
|
|
||||||
|
|
||||||
# Step 8: Adjust file permissions for Hysteria service
|
# Ask for the port number
|
||||||
chown hysteria:hysteria /etc/hysteria/ca.key /etc/hysteria/ca.crt
|
read -p "Enter the port number you want to use: " port
|
||||||
chmod 640 /etc/hysteria/ca.key /etc/hysteria/ca.crt
|
|
||||||
|
|
||||||
# Create hysteria user without login permissions
|
# Step 7: Generate required passwords and UUID
|
||||||
if ! id -u hysteria &> /dev/null; then
|
echo "Generating passwords and UUID..."
|
||||||
useradd -r -s /usr/sbin/nologin hysteria
|
obfspassword=$(curl -s "https://api.genratr.com/?length=32&uppercase&lowercase&numbers" | jq -r '.password')
|
||||||
fi
|
authpassword=$(curl -s "https://api.genratr.com/?length=32&uppercase&lowercase&numbers" | jq -r '.password')
|
||||||
|
UUID=$(curl -s https://www.uuidgenerator.net/api/version4)
|
||||||
|
|
||||||
# Step 9: Customize the config.yaml file
|
# Step 8: Adjust file permissions for Hysteria service
|
||||||
echo "Customizing config.yaml..."
|
chown hysteria:hysteria /etc/hysteria/ca.key /etc/hysteria/ca.crt
|
||||||
sed -i "s/\$port/$port/" /etc/hysteria/config.yaml
|
chmod 640 /etc/hysteria/ca.key /etc/hysteria/ca.crt
|
||||||
sed -i "s|\$sha256|$sha256|" /etc/hysteria/config.yaml
|
|
||||||
sed -i "s|\$obfspassword|$obfspassword|" /etc/hysteria/config.yaml
|
|
||||||
sed -i "s|\$authpassword|$authpassword|" /etc/hysteria/config.yaml
|
|
||||||
sed -i "s|\$UUID|$UUID|" /etc/hysteria/config.yaml
|
|
||||||
sed -i "s|/path/to/ca.crt|/etc/hysteria/ca.crt|" /etc/hysteria/config.yaml
|
|
||||||
sed -i "s|/path/to/ca.key|/etc/hysteria/ca.key|" /etc/hysteria/config.yaml
|
|
||||||
|
|
||||||
# Step 10: Start and enable the Hysteria service
|
# Create hysteria user without login permissions
|
||||||
echo "Starting and enabling Hysteria service..."
|
if ! id -u hysteria &> /dev/null; then
|
||||||
systemctl daemon-reload >/dev/null 2>&1
|
useradd -r -s /usr/sbin/nologin hysteria
|
||||||
systemctl start hysteria-server.service >/dev/null 2>&1
|
fi
|
||||||
systemctl enable hysteria-server.service >/dev/null 2>&1
|
|
||||||
systemctl restart hysteria-server.service >/dev/null 2>&1
|
|
||||||
|
|
||||||
# Step 11: Check if the hysteria-server.service is active
|
# Step 9: Customize the config.yaml file
|
||||||
if systemctl is-active --quiet hysteria-server.service; then
|
echo "Customizing config.yaml..."
|
||||||
# Step 12: Generate URI Scheme
|
sed -i "s/\$port/$port/" /etc/hysteria/config.yaml
|
||||||
echo "Generating URI Scheme..."
|
sed -i "s|\$sha256|$sha256|" /etc/hysteria/config.yaml
|
||||||
IP=$(curl -4 ip.sb)
|
sed -i "s|\$obfspassword|$obfspassword|" /etc/hysteria/config.yaml
|
||||||
URI="hy2://$authpassword@$IP:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bing.com#Hysteria2"
|
sed -i "s|\$authpassword|$authpassword|" /etc/hysteria/config.yaml
|
||||||
|
sed -i "s|\$UUID|$UUID|" /etc/hysteria/config.yaml
|
||||||
|
sed -i "s|/path/to/ca.crt|/etc/hysteria/ca.crt|" /etc/hysteria/config.yaml
|
||||||
|
sed -i "s|/path/to/ca.key|/etc/hysteria/ca.key|" /etc/hysteria/config.yaml
|
||||||
|
|
||||||
# Step 13: Generate and display QR Code in the center of the terminal
|
# Step 10: Start and enable the Hysteria service
|
||||||
cols=$(tput cols)
|
echo "Starting and enabling Hysteria service..."
|
||||||
rows=$(tput lines)
|
systemctl daemon-reload >/dev/null 2>&1
|
||||||
qr=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
systemctl start hysteria-server.service >/dev/null 2>&1
|
||||||
|
systemctl enable hysteria-server.service >/dev/null 2>&1
|
||||||
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
|
|
||||||
echo -e "\n\n\n"
|
# Step 11: Check if the hysteria-server.service is active
|
||||||
echo "$qr" | while IFS= read -r line; do
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
# Step 12: Generate URI Scheme
|
||||||
done
|
echo "Generating URI Scheme..."
|
||||||
echo -e "\n\n\n"
|
IP=$(curl -4 ip.sb)
|
||||||
|
URI="hy2://$authpassword@$IP:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bing.com#Hysteria2"
|
||||||
|
|
||||||
# Output the URI scheme
|
# Step 13: Generate and display QR Code in the center of the terminal
|
||||||
echo $URI
|
cols=$(tput cols)
|
||||||
else
|
rows=$(tput lines)
|
||||||
echo "Error: hysteria-server.service is not active."
|
qr=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
||||||
fi
|
|
||||||
|
echo -e "\n\n\n"
|
||||||
|
echo "$qr" | while IFS= read -r line; do
|
||||||
|
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
||||||
|
done
|
||||||
|
echo -e "\n\n\n"
|
||||||
|
|
||||||
|
# Output the URI scheme
|
||||||
|
echo $URI
|
||||||
|
else
|
||||||
|
echo "Error: hysteria-server.service is not active."
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to change port
|
||||||
|
change_port() {
|
||||||
|
read -p "Enter the new port number you want to use: " port
|
||||||
|
# Check if the config.yaml file exists
|
||||||
|
if [ -f "/etc/hysteria/config.yaml" ]; then
|
||||||
|
# Update the port in the config.yaml file
|
||||||
|
sed -i "s/listen: :[0-9]*/listen: :$port/" /etc/hysteria/config.yaml
|
||||||
|
# Restart the Hysteria2 service
|
||||||
|
systemctl restart hysteria-server.service >/dev/null 2>&1
|
||||||
|
echo "Port changed successfully to $port"
|
||||||
|
else
|
||||||
|
echo "Error: Config file /etc/hysteria/config.yaml not found."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to show URI if Hysteria2 is installed and active
|
||||||
|
show_uri() {
|
||||||
|
# Check if the config.yaml file exists
|
||||||
|
if [ -f "/etc/hysteria/config.yaml" ]; then
|
||||||
|
# Retrieve values from config.yaml
|
||||||
|
port=$(grep -oP '(?<=listen: :)\d+' /etc/hysteria/config.yaml)
|
||||||
|
sha256=$(grep -oP '(?<=pinSHA256: ").*(?=")' /etc/hysteria/config.yaml)
|
||||||
|
obfspassword=$(grep -oP '(?<=password: ).*' /etc/hysteria/config.yaml | head -1)
|
||||||
|
authpassword=$(grep -oP '(?<=password: ).*' /etc/hysteria/config.yaml | tail -1)
|
||||||
|
|
||||||
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
|
# Generate URI Scheme
|
||||||
|
echo "Generating URI Scheme..."
|
||||||
|
IP=$(curl -4 ip.sb)
|
||||||
|
URI="hy2://$authpassword@$IP:$port?obfs=salamander&obfs-password=$obfspassword&pinSHA256=$sha256&insecure=1&sni=bing.com#Hysteria2"
|
||||||
|
|
||||||
|
# Generate and display QR Code in the center of the terminal
|
||||||
|
cols=$(tput cols)
|
||||||
|
rows=$(tput lines)
|
||||||
|
qr=$(echo -n "$URI" | qrencode -t UTF8 -s 3 -m 2)
|
||||||
|
|
||||||
|
echo -e "\n\n\n"
|
||||||
|
echo "$qr" | while IFS= read -r line; do
|
||||||
|
printf "%*s\n" $(( (${#line} + cols) / 2)) "$line"
|
||||||
|
done
|
||||||
|
echo -e "\n"
|
||||||
|
|
||||||
|
# Output the URI scheme
|
||||||
|
echo "$URI"
|
||||||
|
else
|
||||||
|
echo "Error: Hysteria2 is not active."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Error: Config file /etc/hysteria/config.yaml not found."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Function to Check Traffic Status
|
||||||
|
traffic_status() {
|
||||||
|
|
||||||
|
green='\033[0;32m'
|
||||||
|
cyan='\033[0;36m'
|
||||||
|
NC='\033[0m'
|
||||||
|
|
||||||
|
# Extract secret from config.yaml
|
||||||
|
secret=$(grep -Po '(?<=secret: ).*' /etc/hysteria/config.yaml | awk '{$1=$1};1')
|
||||||
|
|
||||||
|
# If secret is empty, exit with error
|
||||||
|
if [ -z "$secret" ]; then
|
||||||
|
echo "Error: Secret not found in config.yaml"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
response=$(curl -s -H "Authorization: $secret" http://127.0.0.1:25413/traffic)
|
||||||
|
if [ -z "$response" ] || [ "$response" = "{}" ]; then
|
||||||
|
echo -e "Upload (TX): ${green}0B${NC}"
|
||||||
|
echo -e "Download (RX): ${cyan}0B${NC}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
tx_bytes=$(echo "$response" | jq -r '.user.tx // 0')
|
||||||
|
rx_bytes=$(echo "$response" | jq -r '.user.rx // 0')
|
||||||
|
|
||||||
|
format_bytes() {
|
||||||
|
bytes=$1
|
||||||
|
|
||||||
|
if [ "$bytes" -lt 1024 ]; then
|
||||||
|
echo "${bytes}B"
|
||||||
|
elif [ "$bytes" -lt 1048576 ]; then
|
||||||
|
echo "$(bc <<< "scale=2; $bytes / 1024")KB"
|
||||||
|
elif [ "$bytes" -lt 1073741824 ]; then
|
||||||
|
echo "$(bc <<< "scale=2; $bytes / 1048576")MB"
|
||||||
|
elif [ "$bytes" -lt 1099511627776 ]; then
|
||||||
|
echo "$(bc <<< "scale=2; $bytes / 1073741824")GB"
|
||||||
|
else
|
||||||
|
echo "$(bc <<< "scale=2; $bytes / 1099511627776")TB"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo -e "Upload (TX): ${green}$(format_bytes "$tx_bytes")${NC}"
|
||||||
|
echo -e "Download (RX): ${cyan}$(format_bytes "$rx_bytes")${NC}"
|
||||||
|
|
||||||
|
}
|
||||||
|
# Main menu
|
||||||
|
main_menu() {
|
||||||
|
echo "===== Hysteria2 Setup Menu ====="
|
||||||
|
echo "1. Install and Configure"
|
||||||
|
echo "2. Change Port"
|
||||||
|
echo "3. Show URI"
|
||||||
|
echo "4. Check Traffic Status"
|
||||||
|
echo "5. Exit"
|
||||||
|
|
||||||
|
read -p "Enter your choice: " choice
|
||||||
|
case $choice in
|
||||||
|
1) install_and_configure ;;
|
||||||
|
2) change_port ;;
|
||||||
|
3) show_uri ;;
|
||||||
|
4) traffic_status ;;
|
||||||
|
5) exit ;;
|
||||||
|
*) echo "Invalid option. Please try again." ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# Loop to display the menu repeatedly
|
||||||
|
while true; do
|
||||||
|
main_menu
|
||||||
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user