-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix-pmpl-drift.sh
More file actions
executable file
·123 lines (106 loc) · 3.56 KB
/
Copy pathfix-pmpl-drift.sh
File metadata and controls
executable file
·123 lines (106 loc) · 3.56 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# fix-pmpl-drift.sh — Flip legacy PMPL-1.0-or-later SPDX stamps to repo-category target
# Recipe: recipe-fix-pmpl-drift (confidence: 0.95, auto_fixable: true)
#
# Per 2026-06-02 owner directive:
# sole-owner default → MPL-2.0
# son-shared → AGPL-3.0-or-later (confirmed: idaptik, burble, standards, rattlescript, vcl-ut)
# palimpsest carve-out → KEEP PMPL (palimpsest-license, palimpsest-plasma; consent-aware-http special)
# 007 → DO NOT TOUCH (ARR)
# third-party/forks → DO NOT TOUCH
#
# Usage: fix-pmpl-drift.sh <repo-path> [--dry-run] [--file <specific-file>]
set -euo pipefail
REPO_PATH="${1:?Usage: fix-pmpl-drift.sh <repo-path> [--dry-run]}"
DRY_RUN=""
SPECIFIC_FILE=""
shift
while [ $# -gt 0 ]; do
case "$1" in
--dry-run) DRY_RUN=1 ;;
--file) SPECIFIC_FILE="$2"; shift ;;
*) echo "Unknown arg: $1" >&2; exit 1 ;;
esac
shift
done
REPO_NAME=$(basename "$REPO_PATH")
# ─── Carve-out check ───
SKIP_REPOS=(
"007"
"palimpsest-license"
"palimpsest-plasma"
"game-server-admin"
"airborne-submarine-squadron"
"paint-type"
)
for skip in "${SKIP_REPOS[@]}"; do
if [ "$REPO_NAME" = "$skip" ]; then
echo "SKIP: $REPO_NAME is on the exclude_repos list (carve-out or third-party)"
exit 0
fi
done
# ─── Category classification via LICENSE file ───
LICENSE_PATH="$REPO_PATH/LICENSE"
if [ ! -f "$LICENSE_PATH" ]; then
echo "WARN: no LICENSE file at $LICENSE_PATH — skipping (cannot classify)"
exit 0
fi
LIC_HEAD=$(head -1 "$LICENSE_PATH" | tr -d '\n')
if echo "$LIC_HEAD" | grep -q "MPL-2.0"; then
TARGET="MPL-2.0"
CATEGORY="sole-owner"
elif echo "$LIC_HEAD" | grep -q "AGPL-3.0"; then
TARGET="AGPL-3.0-or-later"
CATEGORY="son-shared"
elif echo "$LIC_HEAD" | grep -q "PMPL-1.0-or-later"; then
echo "INFO: $REPO_NAME LICENSE is PMPL-1.0-or-later (carve-out or staging) — skipping"
exit 0
else
echo "WARN: $REPO_NAME LICENSE is unfamiliar (\"$LIC_HEAD\") — skipping (manual review)"
exit 0
fi
# ─── Sub-path exclusions ───
EXCLUDE_PATTERNS=(
"/.git/"
"/LICENSES/"
"/rescript-tea/"
"/rescript-vite/"
"/affinescript-vite/"
"/idaptik-rescript13-staging/"
"/consent-aware-http/"
)
GREP_EXCLUDE=""
for p in "${EXCLUDE_PATTERNS[@]}"; do
GREP_EXCLUDE+="${GREP_EXCLUDE:+|}$p"
done
# ─── Submodule exclusion (skip submodule paths) ───
SUB_PATHS=""
if [ -f "$REPO_PATH/.gitmodules" ]; then
while IFS= read -r submodule_path; do
SUB_PATHS+="${SUB_PATHS:+|}${submodule_path}/"
done < <(grep "path =" "$REPO_PATH/.gitmodules" | awk '{print $3}')
fi
[ -n "$SUB_PATHS" ] && GREP_EXCLUDE="$GREP_EXCLUDE|$SUB_PATHS"
# ─── Find drift files ───
cd "$REPO_PATH"
if [ -n "$SPECIFIC_FILE" ]; then
FILES="$SPECIFIC_FILE"
else
FILES=$(grep -rl "SPDX-License-Identifier: PMPL-1.0-or-later" . 2>/dev/null | grep -vE "$GREP_EXCLUDE" || true)
fi
COUNT=$(echo "$FILES" | grep -c . 2>/dev/null || echo 0)
if [ "$COUNT" -eq 0 ]; then
echo "OK: $REPO_NAME has no PMPL drift in safe scope"
exit 0
fi
echo "$REPO_NAME ($CATEGORY → $TARGET): $COUNT files with PMPL drift"
if [ -n "$DRY_RUN" ]; then
echo "$FILES" | head -20
[ "$COUNT" -gt 20 ] && echo "... and $((COUNT - 20)) more"
exit 0
fi
# ─── Flip ───
echo "$FILES" | xargs sed -i "s|SPDX-License-Identifier: PMPL-1.0-or-later|SPDX-License-Identifier: $TARGET|g"
REMAINING=$(grep -rl "SPDX-License-Identifier: PMPL-1.0-or-later" . 2>/dev/null | grep -vE "$GREP_EXCLUDE" | wc -l)
echo "Flipped $COUNT files. Remaining PMPL in scope: $REMAINING."