Isolate change_port
This commit is contained in:
16
core/scripts/hysteria2/change_port.sh
Normal file
16
core/scripts/hysteria2/change_port.sh
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
while true; do
|
||||||
|
read -p "Enter the new port number you want to use: " port
|
||||||
|
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
||||||
|
echo "Invalid port number. Please enter a number between 1 and 65535."
|
||||||
|
else
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -f "/etc/hysteria/config.json" ]; then
|
||||||
|
jq --arg port "$port" '.listen = ":" + $port' /etc/hysteria/config.json > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json /etc/hysteria/config.json
|
||||||
|
restart_hysteria_service >/dev/null 2>&1
|
||||||
|
echo "Port changed successfully to $port."
|
||||||
|
else
|
||||||
|
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
||||||
|
fi
|
||||||
@ -1,4 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
define_colors() {
|
define_colors() {
|
||||||
green='\033[0;32m'
|
green='\033[0;32m'
|
||||||
cyan='\033[0;36m'
|
cyan='\033[0;36m'
|
||||||
@ -7,6 +8,8 @@ define_colors() {
|
|||||||
LPurple='\033[1;35m'
|
LPurple='\033[1;35m'
|
||||||
NC='\033[0m'
|
NC='\033[0m'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_hysteria() {
|
||||||
# Step 1: Install Hysteria2
|
# Step 1: Install Hysteria2
|
||||||
echo "Installing Hysteria2..."
|
echo "Installing Hysteria2..."
|
||||||
bash <(curl -fsSL https://get.hy2.sh/) >/dev/null 2>&1
|
bash <(curl -fsSL https://get.hy2.sh/) >/dev/null 2>&1
|
||||||
@ -124,3 +127,28 @@ chmod +x /etc/hysteria/users/kick.sh
|
|||||||
# Add the commands to the crontab
|
# Add the commands to the crontab
|
||||||
(crontab -l ; echo "*/1 * * * * python3 /etc/hysteria/traffic.py >/dev/null 2>&1") | crontab -
|
(crontab -l ; echo "*/1 * * * * python3 /etc/hysteria/traffic.py >/dev/null 2>&1") | crontab -
|
||||||
(crontab -l ; echo "*/1 * * * * /etc/hysteria/users/kick.sh >/dev/null 2>&1") | crontab -
|
(crontab -l ; echo "*/1 * * * * /etc/hysteria/users/kick.sh >/dev/null 2>&1") | crontab -
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
|
echo -e "${red}Error:${NC} Hysteria2 is already installed and running."
|
||||||
|
echo
|
||||||
|
echo "If you need to update the core, please use the 'Update Core' option."
|
||||||
|
else
|
||||||
|
echo "Installing and configuring Hysteria2..."
|
||||||
|
install_hysteria
|
||||||
|
echo -e "\n"
|
||||||
|
|
||||||
|
if systemctl is-active --quiet hysteria-server.service; then
|
||||||
|
echo "Installation and configuration complete."
|
||||||
|
else
|
||||||
|
echo -e "${red}Error:${NC} Hysteria2 service is not active. Please check the logs for more details."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|||||||
86
menu.sh
86
menu.sh
@ -37,92 +37,6 @@ get_system_info() {
|
|||||||
RAM=$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }')
|
RAM=$(free -m | awk 'NR==2{printf "%.2f%%", $3*100/$2 }')
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to install and configure Hysteria2
|
|
||||||
install_and_configure() {
|
|
||||||
if systemctl is-active --quiet hysteria-server.service; then
|
|
||||||
echo -e "${red}Error:${NC} Hysteria2 is already installed and running."
|
|
||||||
echo
|
|
||||||
echo "If you need to update the core, please use the 'Update Core' option."
|
|
||||||
else
|
|
||||||
echo "Installing and configuring Hysteria2..."
|
|
||||||
bash <(curl -s https://raw.githubusercontent.com/ReturnFI/Hysteria2/main/install.sh)
|
|
||||||
echo -e "\n"
|
|
||||||
|
|
||||||
if systemctl is-active --quiet hysteria-server.service; then
|
|
||||||
echo "Installation and configuration complete."
|
|
||||||
else
|
|
||||||
echo -e "${red}Error:${NC} Hysteria2 service is not active. Please check the logs for more details."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# TODO: remove
|
|
||||||
# Function to update Hysteria2
|
|
||||||
update_core() {
|
|
||||||
echo "Starting the update process for Hysteria2..."
|
|
||||||
echo "Backing up the current configuration..."
|
|
||||||
cp /etc/hysteria/config.json /etc/hysteria/config_backup.json
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "${red}Error:${NC} Failed to back up configuration. Aborting update."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Downloading and installing the latest version of Hysteria2..."
|
|
||||||
bash <(curl -fsSL https://get.hy2.sh/) >/dev/null 2>&1
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "${red}Error:${NC} Failed to download or install the latest version. Restoring backup configuration."
|
|
||||||
mv /etc/hysteria/config_backup.json /etc/hysteria/config.json
|
|
||||||
restart_hysteria_service >/dev/null 2>&1
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Restoring configuration from backup..."
|
|
||||||
mv /etc/hysteria/config_backup.json /etc/hysteria/config.json
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "${red}Error:${NC} Failed to restore configuration from backup."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Modifying systemd service to use config.json..."
|
|
||||||
sed -i 's|/etc/hysteria/config.yaml|/etc/hysteria/config.json|' /etc/systemd/system/hysteria-server.service
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "${red}Error:${NC} Failed to modify systemd service."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
rm /etc/hysteria/config.yaml
|
|
||||||
systemctl daemon-reload >/dev/null 2>&1
|
|
||||||
restart_hysteria_service >/dev/null 2>&1
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "${red}Error:${NC} Failed to restart Hysteria2 service."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Hysteria2 has been successfully updated."
|
|
||||||
echo ""
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to change port
|
|
||||||
change_port() {
|
|
||||||
while true; do
|
|
||||||
read -p "Enter the new port number you want to use: " port
|
|
||||||
if ! [[ "$port" =~ ^[0-9]+$ ]] || [ "$port" -lt 1 ] || [ "$port" -gt 65535 ]; then
|
|
||||||
echo "Invalid port number. Please enter a number between 1 and 65535."
|
|
||||||
else
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -f "/etc/hysteria/config.json" ]; then
|
|
||||||
jq --arg port "$port" '.listen = ":" + $port' /etc/hysteria/config.json > /etc/hysteria/config_temp.json && mv /etc/hysteria/config_temp.json /etc/hysteria/config.json
|
|
||||||
restart_hysteria_service >/dev/null 2>&1
|
|
||||||
echo "Port changed successfully to $port."
|
|
||||||
else
|
|
||||||
echo "${red}Error:${NC} Config file /etc/hysteria/config.json not found."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to show URI if Hysteria2 is installed and active
|
# Function to show URI if Hysteria2 is installed and active
|
||||||
show_uri() {
|
show_uri() {
|
||||||
if [ -f "/etc/hysteria/users/users.json" ]; then
|
if [ -f "/etc/hysteria/users/users.json" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user