-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-missing-spdx.sh
More file actions
executable file
·80 lines (67 loc) · 2.35 KB
/
Copy pathfix-missing-spdx.sh
File metadata and controls
executable file
·80 lines (67 loc) · 2.35 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
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
# SPDX-License-Identifier: MPL-2.0
# Add SPDX license identifier to files missing it
#
# DISABLED 2026-06-02 per owner directive on licence policy.
# See `feedback_no_automated_licence_edits.md` and
# `feedback_estate_license_policy_umbrella.md`. Licence remediation is
# manual, file-by-file, owner-only. Triggered by neurophone#99 (auto-PR
# reverting PMPL → MPL-2.0 across ~140 files, closed by owner).
set -euo pipefail
echo "REFUSED: fix-missing-spdx.sh is disabled per estate policy 2026-06-02." >&2
echo " Licence/SPDX edits MUST be manual, per-file, owner-approved." >&2
echo " SPDX choice depends on the five-way owner classification" >&2
echo " (sole-repo / 007 / son-shared / fork / palimpsest carve-out)." >&2
echo " See feedback_estate_license_policy_umbrella.md." >&2
exit 1
REPO_PATH="$1"
FINDING_FILE="$2"
echo "Fixing missing SPDX header in $REPO_PATH..."
# Extract file path and license from finding
FILE_PATH=$(jq -r '.location.file' "$FINDING_FILE")
FULL_PATH="$REPO_PATH/$FILE_PATH"
# Default license for hyperpolymath repos
DEFAULT_LICENSE="MPL-2.0"
if [[ ! -f "$FULL_PATH" ]]; then
echo "ERROR: File not found: $FULL_PATH"
exit 1
fi
# Detect file type and comment syntax
case "$FILE_PATH" in
*.yml|*.yaml)
COMMENT_PREFIX="#"
;;
*.sh|*.bash|*.py)
COMMENT_PREFIX="#"
;;
*.js|*.ts|*.jsx|*.tsx|*.res)
COMMENT_PREFIX="//"
;;
*.rs|*.go|*.java)
COMMENT_PREFIX="//"
;;
*)
echo "WARN: Unknown file type, using # as comment"
COMMENT_PREFIX="#"
;;
esac
# Check if file already has SPDX header
if head -3 "$FULL_PATH" | grep -q "SPDX-License-Identifier"; then
echo " File already has SPDX header"
exit 0
fi
# Create temp file with SPDX header
TEMP_FILE=$(mktemp)
# Check if line 1 is a shebang — if so, preserve it before the SPDX header
FIRST_LINE=$(head -1 "$FULL_PATH")
if [[ "$FIRST_LINE" == "#!"* ]]; then
echo "$FIRST_LINE" > "$TEMP_FILE"
echo "${COMMENT_PREFIX} SPDX-License-Identifier: ${DEFAULT_LICENSE}" >> "$TEMP_FILE"
tail -n +2 "$FULL_PATH" >> "$TEMP_FILE"
else
echo "${COMMENT_PREFIX} SPDX-License-Identifier: ${DEFAULT_LICENSE}" > "$TEMP_FILE"
cat "$FULL_PATH" >> "$TEMP_FILE"
fi
# Replace original file
mv "$TEMP_FILE" "$FULL_PATH"
echo "✅ Added SPDX header to $FILE_PATH"