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
This commit is contained in:
Whispering Wind
2025-04-27 18:20:46 +03:30
committed by GitHub
parent 1255fc7e58
commit 68441c1cae

View File

@ -97,6 +97,7 @@ if [ -f "$CONFIG_FILE" ]; then
if [ "$current_v4_device" != "$networkdef" ]; then if [ "$current_v4_device" != "$networkdef" ]; then
echo "Updating v4 outbound bindDevice from '$current_v4_device' to '$networkdef'..." echo "Updating v4 outbound bindDevice from '$current_v4_device' to '$networkdef'..."
tmpfile=$(mktemp) tmpfile=$(mktemp)
jq --arg newdev "$networkdef" ' jq --arg newdev "$networkdef" '
.outbounds = (.outbounds | map( .outbounds = (.outbounds | map(
@ -106,7 +107,10 @@ if [ -f "$CONFIG_FILE" ]; then
. .
end end
)) ))
' "$CONFIG_FILE" > "$tmpfile" && mv "$tmpfile" "$CONFIG_FILE" ' "$CONFIG_FILE" > "$tmpfile"
cat "$tmpfile" > "$CONFIG_FILE"
rm -f "$tmpfile"
fi fi
fi fi
@ -114,7 +118,6 @@ if [ -f "$CONFIG_FILE" ]; then
echo "wgcf service is NOT active. Removing warps outbound and fixing ACL rules..." echo "wgcf service is NOT active. Removing warps outbound and fixing ACL rules..."
tmpfile=$(mktemp) tmpfile=$(mktemp)
jq ' jq '
.outbounds = (.outbounds | map(select(.name != "warps"))) | .outbounds = (.outbounds | map(select(.name != "warps"))) |
.acl.inline = (.acl.inline | map( .acl.inline = (.acl.inline | map(
@ -124,14 +127,17 @@ if [ -f "$CONFIG_FILE" ]; then
. .
end end
)) ))
' "$CONFIG_FILE" > "$tmpfile" && mv "$tmpfile" "$CONFIG_FILE" ' "$CONFIG_FILE" > "$tmpfile"
cat "$tmpfile" > "$CONFIG_FILE"
rm -f "$tmpfile"
fi fi
fi fi
rm -rf "$RESTORE_DIR" rm -rf "$RESTORE_DIR"
echo "Hysteria configuration restored and updated successfully." 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 chmod 640 /etc/hysteria/ca.key /etc/hysteria/ca.crt
python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1 python3 "$CLI_PATH" restart-hysteria2 > /dev/null 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then