at main 2.1 kB view raw
1#!/bin/bash 2# verify-bundle.sh <bundle_number> 3 4BUNDLE_NUM=$1 5PLC_DIRECTORIES=("plc.directory" "plc.wtf") 6 7# Fetch bundle hash from local server 8if [ "$BUNDLE_NUM" -eq 1 ]; then 9 # Bundle 1 - no after parameter 10 BUNDLE_HASH=$(curl -s "http://localhost:8080/api/v1/plc/bundles/$BUNDLE_NUM" | jq -r '.hash') 11 12 echo "Bundle $BUNDLE_NUM hash: $BUNDLE_HASH" 13 echo "" 14 15 # Compare with each PLC directory 16 ALL_MATCH=true 17 for PLC_DIR in "${PLC_DIRECTORIES[@]}"; do 18 echo "Checking $PLC_DIR..." 19 REMOTE_HASH=$(curl -s "https://$PLC_DIR/export?count=1000" | shasum -a 256 | cut -d' ' -f1) 20 echo " Remote hash: $REMOTE_HASH" 21 22 if [ "$BUNDLE_HASH" = "$REMOTE_HASH" ]; then 23 echo " ✅ Verified!" 24 else 25 echo " ❌ Hash mismatch!" 26 ALL_MATCH=false 27 fi 28 echo "" 29 done 30else 31 # Bundle N - need previous bundle's end_time 32 PREV_NUM=$((BUNDLE_NUM - 1)) 33 AFTER=$(curl -s "http://localhost:8080/api/v1/plc/bundles/$PREV_NUM" | jq -r '.end_time') 34 BUNDLE_HASH=$(curl -s "http://localhost:8080/api/v1/plc/bundles/$BUNDLE_NUM" | jq -r '.hash') 35 36 echo "Bundle $BUNDLE_NUM hash: $BUNDLE_HASH" 37 echo "Using after parameter: $AFTER" 38 echo "" 39 40 # Compare with each PLC directory 41 ALL_MATCH=true 42 for PLC_DIR in "${PLC_DIRECTORIES[@]}"; do 43 echo "Checking $PLC_DIR..." 44 echo " curl -s \"https://$PLC_DIR/export?count=1000&after=$AFTER\" | shasum -a 256 | cut -d' ' -f1" 45 REMOTE_HASH=$(curl -s "https://$PLC_DIR/export?count=1000&after=$AFTER" | shasum -a 256 | cut -d' ' -f1) 46 echo " Remote hash: $REMOTE_HASH" 47 48 if [ "$BUNDLE_HASH" = "$REMOTE_HASH" ]; then 49 echo " ✅ Verified!" 50 else 51 echo " ❌ Hash mismatch!" 52 ALL_MATCH=false 53 fi 54 echo "" 55 done 56fi 57 58# Final result 59if [ "$ALL_MATCH" = true ]; then 60 echo "✅ All sources verified successfully!" 61 exit 0 62else 63 echo "❌ One or more sources failed verification" 64 exit 1 65fi 66