# Online Bash Shell. # Code, Compile, Run and Debug Bash script online. # Write your code in this editor and press "Run" button to execute it. getIP(){ local serverIP= serverIP=$(curl -s -4 http://www.cloudflare.com/cdn-cgi/trace | grep "ip" | awk -F "[=]" '{print $2}') if [[ -z "${serverIP}" ]]; then serverIP=$(curl -s -6 http://www.cloudflare.com/cdn-cgi/trace | grep "ip" | awk -F "[=]" '{print $2}') fi echo "${serverIP}" } getShortId(){ hexchars="0123456789abcdef" str="" for _ in $(seq 1 16); do str="$str${hexchars:RANDOM%16:1}" done echo "$str" } configReality(){ v2uuid=$(/usr/local/bin/xray/xray uuid) reX25519Key=$(/usr/local/bin/xray/xray x25519) rePrivateKey=$(echo "${reX25519Key}" | awk '/PrivateKey:/ {print $2}') rePublicKey=$(echo "${reX25519Key}" | awk '/Password:/ {print $2}') read -t 15 -p "please input port or use drfault 443 port(1-65535):" getPort if [ -z $getPort ];then getPort=443 fi shortId1=$(getShortId) shortId2=$(getShortId) sniName='uedata.amazon.com' export sniName # Step 4: Create the Xray configuration file cat >/usr/local/etc/xray/config.json</usr/local/etc/xray/config.json</etc/hysteria/config.yaml < /etc/init.d/hysteria #!/sbin/openrc-run name="hysteria" description="Hysteria 2 Proxy Service" command="/usr/local/bin/hysteria" command_args="server -c /etc/hysteria/config.yaml" command_background="yes" pidfile="/run/\${RC_SVCNAME}.pid" output_log="/var/log/hysteria.log" error_log="/var/log/hysteria.err" depend() { need net after firewall } start_pre() { if [ ! -f /etc/hysteria/config.yaml ]; then eerror "Configuration file not found: /etc/hysteria/config.yaml" return 1 fi checkpath -f -m 0644 -o root:root "\$output_log" "\$error_log" } EOF chmod +x /etc/init.d/hysteria rc-update add hysteria default # Get server IP serverIP=$(getIP) # Configure firewall (if installed) if command -v ufw >/dev/null 2>&1; then log "Configuring UFW firewall..." ufw allow "$getPort"/udp fi # Start the service log "Starting Hysteria service..." rc-service hysteria restart # Display connection information echo "===============================================" echo "Hysteria 2 Installation Complete!" echo "Connection String:" echo "hysteria2://${hyPasswd}@${serverIP}:${getPort}/?insecure=1&sni=bing.com#Hysteria2-$(date +%Y%m%d)" echo "===============================================" echo "Config file location: /etc/hysteria/config.yaml" echo "Log files: /var/log/hysteria.log and /var/log/hysteria.err" } menu(){ echo "0. Exit" echo "1. install Xray and Config Reality" echo "2. install hystria2" read option if [[ option -eq 0 ]]; then exit 0 elif [[ option -eq 1 ]]; then installXray elif [[ option -eq 2 ]]; then installHy2 else echo "invid option" menu fi } # Ensure this script is run as root if [ "$(id -u)" -ne 0 ]; then echo "This script must be run as root!" exit 1 fi menu #special thanks to administrator of 1024.day