-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_license_header.sh
117 lines (106 loc) · 4.19 KB
/
add_license_header.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
#!/bin/bash
# Define the license header for non-XML files
LICENSE_HEADER_NON_XML="/*************************************************************************
* This file is part of CodeOps Studio.
* CodeOps Studio - Code anywhere anytime
* https://github.com/euptron/CodeOps-Studio
* Copyright (C) 2024 EUP
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see https://www.gnu.org/licenses/
*
* If you have more questions, feel free to message EUP if you have any
* questions or need additional information. Email: [email protected]
*************************************************************************/
"
# Define the license header for XML files
LICENSE_HEADER_XML="<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ This file is part of CodeOps Studio.
~ CodeOps Studio - Code anywhere anytime
~ https://github.com/euptron/CodeOps-Studio
~ Copyright (C) 2024 EUP
~
~ This program is free software: you can redistribute it and/or modify
~ it under the terms of the GNU 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 General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see https://www.gnu.org/licenses/
~
~ If you have more questions, feel free to message EUP if you have any
~ questions or need additional information. Email: [email protected]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
"
# Function to add the license header to a file
add_license_header() {
local file="$1"
local manual_add="$2"
if [[ "$manual_add" == "true" ]]; then
# Add header to a specific file
if [[ "$file" == *.xml ]]; then
echo "$LICENSE_HEADER_XML$(cat "$file")" > "$file"
else
echo "$LICENSE_HEADER_NON_XML$(cat "$file")" > "$file"
fi
else
# Add header to files found by find command
if [[ "$file" == *.xml ]]; then
if ! grep -q "This file is part of CodeOps Studio" "$file"; then
echo "$LICENSE_HEADER_XML$(cat "$file")" > "$file"
fi
else
if ! grep -q "This file is part of CodeOps Studio" "$file"; then
echo "$LICENSE_HEADER_NON_XML$(cat "$file")" > "$file"
fi
fi
fi
}
# Function to show progress
show_progress() {
local file="$1"
echo "Adding license header to: $file"
}
# Export the functions to be used with find
export -f add_license_header
export -f show_progress
export LICENSE_HEADER_NON_XML
export LICENSE_HEADER_XML
# Directory to search for files (current directory)
SEARCH_DIR=$(pwd)
# Check if manual mode is enabled
if [[ "$1" == "--manual" ]]; then
# Check if second argument (file path) is provided
if [[ -n "$2" ]]; then
add_license_header "$2" "true"
echo "License header added to $2."
else
echo "Please provide a file path."
exit 1
fi
else
# Find and process files with specific extensions, excluding 'Build' and 'Compile' directories
find "$SEARCH_DIR" -type d \( -path "$SEARCH_DIR/build" -o -path "$SEARCH_DIR/compile" \) -prune -o \
-type f \( -name "*.java" -o -name "*.py" -o -name "*.cpp" -o -name "*.xml" -o -name "*.gradle" -o -name "*.kts" -o -name "*.kt" \) -print0 |
while IFS= read -r -d $'\0' file; do
add_license_header "$file"
show_progress "$file"
done
echo "License headers added successfully to all applicable files."
fi