35 lines
1.2 KiB
Bash
Executable File
35 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Ask user for the JSON file location
|
|
echo "Enter the path to summaries.json:"
|
|
read JSON_FILE
|
|
|
|
# Check if file exists
|
|
if [ ! -f "$JSON_FILE" ]; then
|
|
echo "File not found!"
|
|
exit 1
|
|
fi
|
|
|
|
# Ask user for the output file location
|
|
echo "Enter the path where the output should be written:"
|
|
read OUTPUT_FILE
|
|
|
|
TMP_JSON="$JSON_FILE.tmp"
|
|
cp "$JSON_FILE" "$TMP_JSON"
|
|
|
|
# Process each report and update in TMP_JSON
|
|
jq --raw-output '.[] | select(.room? and .room.room_id) | .room.room_id' "$JSON_FILE" | while read -r room_id; do
|
|
# Double hash the room_id
|
|
HASHED_ID=$(echo -n "$room_id" | sha256sum -b | cut -d ' ' -f1 | xxd -r -p | sha256sum | cut -d ' ' -f1)
|
|
|
|
# Update hashed id in TMP_JSON inside 'room'
|
|
jq --arg room_id "$room_id" --arg hashed_id "$HASHED_ID" 'map(if .room? and .room.room_id == $room_id then .room += {"room_id_hash": $hashed_id} else . end)' "$TMP_JSON" > "$TMP_JSON.tmp" && mv "$TMP_JSON.tmp" "$TMP_JSON"
|
|
done
|
|
|
|
# For compact output
|
|
jq -c '.' "$TMP_JSON" > "$OUTPUT_FILE"
|
|
|
|
rm "$TMP_JSON"
|
|
|
|
echo "Processing complete. Modified JSON saved to $OUTPUT_FILE. The summaries.json file now has double hashes of the room_id in every report!"
|