-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-license.sh
executable file
·164 lines (144 loc) · 5.47 KB
/
add-license.sh
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Nautilus Trusted Compute
# Copyright (C) 2025 Nautilus
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#!/bin/bash
# License File
LICENSE_FILE="license-template.txt"
LICENSE_TEXT="""# Nautilus Trusted Compute
# Copyright (C) 2025 Nautilus
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
LICENSE_TEXT_MD="<!-- Nautilus Trusted Compute
Copyright (C) 2025 Nautilus
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. -->"
# Files and patterns to exclude
EXCLUDE_PATTERNS=("*.env*" ".DS_Store" "package-lock.json" "yarn.lock" "Cargo.lock")
# Directories to exclude
EXCLUDE_DIRS=(
"ntc-web/node_modules"
"sgx-mvp/target"
"drt-manager/node_modules"
"drt-manager/target"
"dist"
"build"
"out"
"vendor"
".git"
".idea"
"test-ledger"
"ntc-web/.next"
"drt-manager/.anchor"
)
# Ensure addlicense is installed
if ! command -v addlicense &> /dev/null; then
echo "❌ addlicense not found! Install it using: go install github.com/google/addlicense@latest"
exit 1
fi
# Ensure the license template exists
if [ ! -f "$LICENSE_FILE" ]; then
echo "❌ License template file not found! Ensure $LICENSE_FILE exists."
exit 1
fi
echo "🔹 Adding license to source files..."
# Build find command with proper exclusions
FIND_CMD="find . -type f"
for dir in "${EXCLUDE_DIRS[@]}"; do
FIND_CMD+=" -not -path '*/$dir/*'"
done
for pattern in "${EXCLUDE_PATTERNS[@]}"; do
FIND_CMD+=" -not -name '$pattern'"
done
# Process files and add licenses
eval "$FIND_CMD \( \
-name '*.js' -o \
-name '*.jsx' -o \
-name '*.ts' -o \
-name '*.tsx' -o \
-name '*.py' -o \
-name '*.cpp' -o \
-name '*.c' -o \
-name '*.h' -o \
-name '*.rs' -o \
-name '*.sh' -o \
-name '*.prisma' -o \
-name '*.toml' -o \
-name '*.yml' -o \
-name '*.yaml' -o \
-name '*.css' -o \
-name '*.scss' -o \
-name '*.sass' -o \
-name '*.less' -o \
-name '*.html' -o \
-name 'Dockerfile' -o \
-name '*.lock' -o \
-name '*.cargo' \
\) -print0" | while IFS= read -r -d '' file; do
if head -n 10 "$file" | grep -q "Nautilus"; then
echo "✔️ License already present in $file"
else
echo "✅ Adding license to $file"
if [[ "$file" == *.toml || "$file" == *.gitignore || "$file" == *.prettierignore ]]; then
printf "# %s\n\n" "$(cat $LICENSE_FILE)" | cat - "$file" > "$file.tmp" && mv "$file.tmp" "$file"
else
addlicense -f "$LICENSE_FILE" -y 2025 -c "Nautilus" "$file"
fi
fi
done
echo "🔹 Adding license to .gitignore files..."
eval "$FIND_CMD -name '.gitignore' -print0" | while IFS= read -r -d '' file; do
if head -n 10 "$file" | grep -q "Nautilus"; then
echo "✔️ License already present in $file"
else
echo "✅ Adding license to $file"
printf "%s\n\n" "$LICENSE_TEXT" | cat - "$file" > "$file.tmp" && mv "$file.tmp" "$file"
fi
done
echo "🔹 Adding license to .prettierignore files..."
eval "$FIND_CMD -name '.prettierignore' -print0" | while IFS= read -r -d '' file; do
if head -n 10 "$file" | grep -q "Nautilus"; then
echo "✔️ License already present in $file"
else
echo "✅ Adding license to $file"
printf "%s\n\n" "$LICENSE_TEXT" | cat - "$file" > "$file.tmp" && mv "$file.tmp" "$file"
fi
done
echo "🔹 Adding license to Markdown files..."
eval "$FIND_CMD -name '*.md' -print0" | while IFS= read -r -d '' file; do
if head -n 10 "$file" | grep -q "Nautilus"; then
echo "✔️ License already present in $file"
else
echo "✅ Adding license to $file"
printf "%s\n\n" "$LICENSE_TEXT_MD" | cat - "$file" > "$file.tmp" && mv "$file.tmp" "$file"
fi
done
echo "🎉 License update complete!"