-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·62 lines (49 loc) · 1.9 KB
/
init.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
#!/bin/sh
echo "Project name: $1"
if [ $# -ne 1 ]
then
echo "You call this script wtth wrong arguments."
echo "Example for start script:"
echo "./init.sh MyCmakeProject"
echo "Usage: $0 <replacement_string>"
exit 1
fi
replacement="$1"
rename_files_and_folders() {
local dir="$1"
local old_str="$2"
local new_str="$3"
for item in "$dir"/*; do
if [ -d "$item" ]; then
new_name=$(echo "$item" | sed "s/$old_str/$new_str/g")
if [ "$item" != "$new_name" ]; then
mv "$item" "$new_name"
echo "Renamed directory: $item -> $new_name"
fi
rename_files_and_folders "$new_name" "$old_str" "$new_str"
elif [ -f "$item" ]; then
sed -i "s/$old_str/$new_str/g" "$item"
new_name=$(echo "$item" | sed "s/$old_str/$new_str/g")
if [ "$item" != "$new_name" ]; then
mv "$item" "$new_name"
echo "Renamed file: $item -> $new_name"
fi
fi
done
}
uppercase_string=$(echo "$replacement" | tr '[:lower:]' '[:upper:]')
rename_files_and_folders "." "RENAME_ME_EXPORT" "${uppercase_string}_EXPORT"
rename_files_and_folders "." "RENAME_ME_VERSION" "${uppercase_string}_VERSION"
rename_files_and_folders "." "RENAME_ME_LIBRARY" "${uppercase_string}_LIBRARY"
rename_files_and_folders "." "RENAME_ME_EXAMPLE" "${uppercase_string}_EXAMPLE"
rename_files_and_folders "." "RENAME_ME_TESTS" "${uppercase_string}_TESTS"
rename_files_and_folders "." "RENAME_ME_PACKAGE_ID" "${uppercase_string}_PACKAGE_ID"
rename_files_and_folders "." "RENAME_ME" "$replacement"
echo "Replacement complete."
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
git submodule add $url $path
done