-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-checksums.sh
More file actions
executable file
·69 lines (56 loc) · 2 KB
/
generate-checksums.sh
File metadata and controls
executable file
·69 lines (56 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# Generates BundledWidgets.g.cs from widgets/*.sh and widgets/*.py before build
# This file contains hardcoded SHA256 checksums for bundled widgets
set -e
cd "$(dirname "$0")"
WIDGETS_DIR="widgets"
OUTPUT_FILE="src/Config/BundledWidgets.g.cs"
echo "Generating BundledWidgets.g.cs..."
# Create output directory if needed
mkdir -p "$(dirname "$OUTPUT_FILE")"
# Start generating the file
cat > "$OUTPUT_FILE" << 'HEADER'
// Auto-generated file - do not edit manually
// Generated from widgets/ directory during build
// Copyright (c) Nikolaos Protopapas. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
namespace ServerHub.Config;
/// <summary>
/// Bundled widgets with hardcoded checksums for tamper detection
/// Auto-generated during build from widgets/ directory
/// </summary>
public static class BundledWidgets
{
/// <summary>
/// SHA256 checksums for bundled widgets
/// Key: widget filename (e.g., "cpu.sh")
/// Value: SHA256 checksum (lowercase hex)
/// </summary>
public static readonly Dictionary<string, string> Checksums = new()
{
HEADER
# Generate checksum entries for each widget (both .sh and .py)
WIDGET_COUNT=0
for file in "$WIDGETS_DIR"/*.sh "$WIDGETS_DIR"/*.py; do
if [ -f "$file" ]; then
filename=$(basename "$file")
# Compute SHA256 checksum
if command -v sha256sum >/dev/null 2>&1; then
checksum=$(sha256sum "$file" | awk '{print $1}')
elif command -v shasum >/dev/null 2>&1; then
checksum=$(shasum -a 256 "$file" | awk '{print $1}')
else
echo "Error: Neither sha256sum nor shasum found"
exit 1
fi
echo " [\"$filename\"] = \"$checksum\"," >> "$OUTPUT_FILE"
WIDGET_COUNT=$((WIDGET_COUNT + 1))
fi
done
# Close the dictionary and class
cat >> "$OUTPUT_FILE" << 'FOOTER'
};
}
FOOTER
echo " Generated checksums for $WIDGET_COUNT bundled widgets"
echo " Output: $OUTPUT_FILE"