feat: Add function to edit Normalsub subpath

This commit introduces a new 'edit_subpath' command to the
normalsub.sh script. This allows users to change the SUBPATH
variable in the .env file and automatically restarts the
hysteria-normal-sub service to apply the changes.
This commit is contained in:
Whispering Wind
2025-05-17 23:20:04 +03:30
committed by GitHub
parent ad8faae3aa
commit 6c5486eafc

View File

@ -70,7 +70,6 @@ start_service() {
systemctl daemon-reload systemctl daemon-reload
systemctl enable hysteria-normal-sub.service > /dev/null 2>&1 systemctl enable hysteria-normal-sub.service > /dev/null 2>&1
systemctl start hysteria-normal-sub.service > /dev/null 2>&1 systemctl start hysteria-normal-sub.service > /dev/null 2>&1
# systemctl restart caddy.service > /dev/null 2>&1 # We stopped caddy service just after its installation
systemctl daemon-reload > /dev/null 2>&1 systemctl daemon-reload > /dev/null 2>&1
if systemctl is-active --quiet hysteria-normal-sub.service; then if systemctl is-active --quiet hysteria-normal-sub.service; then
@ -85,12 +84,12 @@ stop_service() {
source /etc/hysteria/core/scripts/normalsub/.env source /etc/hysteria/core/scripts/normalsub/.env
fi fi
# if [ -n "$HYSTERIA_DOMAIN" ]; then if [ -n "$HYSTERIA_DOMAIN" ]; then
# echo -e "${yellow}Deleting SSL certificate for domain: $HYSTERIA_DOMAIN...${NC}" echo -e "${yellow}Deleting SSL certificate for domain: $HYSTERIA_DOMAIN...${NC}"
# certbot delete --cert-name "$HYSTERIA_DOMAIN" --non-interactive > /dev/null 2>&1 certbot delete --cert-name "$HYSTERIA_DOMAIN" --non-interactive > /dev/null 2>&1
# else else
# echo -e "${red}HYSTERIA_DOMAIN not found in .env. Skipping certificate deletion.${NC}" echo -e "${red}HYSTERIA_DOMAIN not found in .env. Skipping certificate deletion.${NC}"
# fi fi
systemctl stop hysteria-normal-sub.service > /dev/null 2>&1 systemctl stop hysteria-normal-sub.service > /dev/null 2>&1
systemctl disable hysteria-normal-sub.service > /dev/null 2>&1 systemctl disable hysteria-normal-sub.service > /dev/null 2>&1
@ -101,6 +100,38 @@ stop_service() {
echo -e "${yellow}normalsub service stopped and disabled. .env file removed.${NC}" echo -e "${yellow}normalsub service stopped and disabled. .env file removed.${NC}"
} }
edit_subpath() {
local new_path="$1"
local env_file="/etc/hysteria/core/scripts/normalsub/.env"
if [[ ! "$new_path" =~ ^[a-zA-Z0-9]+$ ]]; then
echo -e "${red}Error: New subpath must contain only alphanumeric characters (a-z, A-Z, 0-9) and cannot be empty.${NC}"
exit 1
fi
if [ ! -f "$env_file" ]; then
echo -e "${red}Error: .env file ($env_file) not found. Please run the start command first.${NC}"
exit 1
fi
if grep -q "^SUBPATH=" "$env_file"; then
sed -i "s|^SUBPATH=.*|SUBPATH=$new_path|" "$env_file"
else
echo "SUBPATH=$new_path" >> "$env_file"
fi
echo -e "${green}SUBPATH updated to $new_path in $env_file.${NC}"
echo -e "${yellow}Restarting hysteria-normal-sub service...${NC}"
systemctl daemon-reload
systemctl restart hysteria-normal-sub.service
if systemctl is-active --quiet hysteria-normal-sub.service; then
echo -e "${green}hysteria-normal-sub service restarted successfully.${NC}"
else
echo -e "${red}Error: hysteria-normal-sub service failed to restart. Please check logs.${NC}"
fi
}
case "$1" in case "$1" in
start) start)
if [ -z "$2" ] || [ -z "$3" ]; then if [ -z "$2" ] || [ -z "$3" ]; then
@ -112,10 +143,15 @@ case "$1" in
stop) stop)
stop_service stop_service
;; ;;
edit_subpath)
if [ -z "$2" ]; then
echo -e "${red}Usage: $0 edit_subpath <NEW_SUBPATH> ${NC}"
exit 1
fi
edit_subpath "$2"
;;
*) *)
echo -e "${red}Usage: $0 {start|stop} <DOMAIN> <PORT> ${NC}" echo -e "${red}Usage: $0 {start <DOMAIN> <PORT> | stop | edit_subpath <NEW_SUBPATH>} ${NC}"
exit 1 exit 1
;; ;;
esac esac
define_colors