From 68441c1cae7389eb7bcbf0bf074b5468c3e227ca Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Sun, 27 Apr 2025 18:20:46 +0330 Subject: [PATCH] Fix config.json permission issues by preserving original file permissions - Replace mv commands with cat to maintain original file permissions when updating config with jq --- core/scripts/hysteria2/restore.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/core/scripts/hysteria2/restore.sh b/core/scripts/hysteria2/restore.sh index a293234..19163f8 100644 --- a/core/scripts/hysteria2/restore.sh +++ b/core/scripts/hysteria2/restore.sh @@ -97,6 +97,7 @@ if [ -f "$CONFIG_FILE" ]; then if [ "$current_v4_device" != "$networkdef" ]; then echo "Updating v4 outbound bindDevice from '$current_v4_device' to '$networkdef'..." + tmpfile=$(mktemp) jq --arg newdev "$networkdef" ' .outbounds = (.outbounds | map( @@ -106,7 +107,10 @@ if [ -f "$CONFIG_FILE" ]; then . end )) - ' "$CONFIG_FILE" > "$tmpfile" && mv "$tmpfile" "$CONFIG_FILE" + ' "$CONFIG_FILE" > "$tmpfile" + + cat "$tmpfile" > "$CONFIG_FILE" + rm -f "$tmpfile" fi fi @@ -114,7 +118,6 @@ if [ -f "$CONFIG_FILE" ]; then echo "wgcf service is NOT active. Removing warps outbound and fixing ACL rules..." tmpfile=$(mktemp) - jq ' .outbounds = (.outbounds | map(select(.name != "warps"))) | .acl.inline = (.acl.inline | map( @@ -124,14 +127,17 @@ if [ -f "$CONFIG_FILE" ]; then . end )) - ' "$CONFIG_FILE" > "$tmpfile" && mv "$tmpfile" "$CONFIG_FILE" + ' "$CONFIG_FILE" > "$tmpfile" + + cat "$tmpfile" > "$CONFIG_FILE" + rm -f "$tmpfile" fi fi rm -rf "$RESTORE_DIR" echo "Hysteria configuration restored and updated successfully." -chown hysteria:hysteria /etc/hysteria/ca.key /etc/hysteria/ca.crt /etc/hysteria/config.json +chown hysteria:hysteria /etc/hysteria/ca.key /etc/hysteria/ca.crt chmod 640 /etc/hysteria/ca.key /etc/hysteria/ca.crt python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1 if [ $? -ne 0 ]; then @@ -144,4 +150,4 @@ if [[ "$existing_backup_dir" != "" ]]; then rm -rf "$existing_backup_dir" fi -exit 0 +exit 0 \ No newline at end of file