-
Notifications
You must be signed in to change notification settings - Fork 21
/
hy2.sh
118 lines (103 loc) · 3.07 KB
/
hy2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/bash
###
# @Author: Vincent Young
# @Date: 2023-10-12 23:21:35
# @LastEditors: Vincent Young
# @LastEditTime: 2023-10-14 00:00:17
# @FilePath: /Hysteria2/hy2.sh
# @Telegram: https://t.me/missuo
#
# Copyright © 2023 by Vincent, All Rights Reserved.
###
#!/bin/bash
show_menu() {
echo "Hysteria 2 Installation by Vincent."
echo "https://github.com/missuo/Hysteria2"
echo "-----------------------------------"
echo "Choose an option:"
echo "1. Install Hysteria 2"
echo "2. Uninstall Hysteria 2"
echo "3. Stop Hysteria 2"
echo "4. Start Hysteria 2"
echo "5. Restart Hysteria 2"
echo "6. Enable auto-start at boot"
echo "7. Disable auto-start at boot"
echo "8. Update Hysteria 2"
echo "9. Exit"
read -p "Enter your choice: " CHOICE
}
install_hysteria() {
if netstat -tuln | grep -q ":80 "; then
echo "Port 80 is already in use. Exiting..."
exit 1
fi
# Install Hysteria 2
bash <(curl -fsSL https://get.hy2.sh/)
# Prompt the user for inputs with default values
read -p "Enter the port (default: 8443): " PORT
read -p "Enter the domain: " DOMAIN
read -p "Enter the password (default: Hy2Best2024@): " PASSWORD
# Set default values if not provided by the user
PORT=${PORT:-8443}
PASSWORD=${PASSWORD:-Hy2Best2024@}
# Create the config file
cat << EOF > /etc/hysteria/config.yaml
listen: :$PORT
acme:
domains:
- $DOMAIN
email: [email protected]
auth:
type: password
password: $PASSWORD
masquerade:
type: proxy
proxy:
url: https://bing.com
rewriteHost: true
EOF
echo "Config file created!"
# Start Hysteria 2
systemctl start hysteria-server.service
systemctl enable hysteria-server.service
# Wait for 10 seconds
sleep 10
# Check service status
STATUS=$(systemctl is-active hysteria-server.service)
if [ "$STATUS" == "active" ]; then
clear
echo "Hysteria 2 started successfully!"
echo "Configuration details:"
echo "Domain: $DOMAIN"
echo "Port: $PORT"
echo "Password: $PASSWORD"
else
echo "Failed to start Hysteria 2. Please check service status manually."
fi
echo ""
}
uninstall_hysteria() {
bash <(curl -fsSL https://get.hy2.sh/) --remove
rm -rf /etc/hysteria
userdel -r hysteria
rm -f /etc/systemd/system/multi-user.target.wants/hysteria-server.service
rm -f /etc/systemd/system/multi-user.target.wants/hysteria-server@*.service
systemctl daemon-reload
echo "Hysteria 2 uninstalled!"
echo ""
}
while true; do
show_menu
case $CHOICE in
1) install_hysteria ;;
2) uninstall_hysteria ;;
3) systemctl stop hysteria-server.service ;;
4) systemctl start hysteria-server.service ;;
5) systemctl restart hysteria-server.service ;;
6) systemctl enable hysteria-server.service ;;
7) systemctl disable hysteria-server.service ;;
8) bash <(curl -fsSL https://get.hy2.sh/) ;;
9) echo "Exiting..."; exit 0 ;;
*) echo "Invalid choice!";;
esac
done