-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgather_cpp_files_and_replace.sh
executable file
·39 lines (36 loc) · 1.24 KB
/
gather_cpp_files_and_replace.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
#!/bin/bash
list_of_private_repos=()
Gather_Private_Repos () {
cwd= pwd
cd $1
for repo in $(find . -maxdepth 1 -type d -printf '%f\n')
do
repo="$1/$repo"
cd $repo
if [ -d ".git" ]
then
git config --global --add safe.directory $repo
repo_https_url=$(git remote -v | awk '{print $2}' | sed 's/[email protected]:/https:\/\/github.com\//g' | head -n 1 | sed 's/\.git//g')
return_code=$(curl -o /dev/null --silent --head --write-out '%{http_code}\n' $repo_https_url)
if [ $return_code -ne 200 ]
then
list_of_private_repos+=($repo)
fi
fi
done
cd $cwd
}
Find_And_Replace_Licence_Var () {
directories=( $(find $1 -type f -name "*.cpp") )
for dir in ${directories[@]}
do
# Find the licence block which is between // Licence block start and // Licence block end
# and replace 'int licence = 0;' with 'int licence = licence_check();'
sed -i '/\/\/ Licence block start/,/\/\/ Licence block end/{/int licence = 0;/s/int licence = 0;/int licence = licence_check();/}' $dir
done
}
Gather_Private_Repos $1
for repo in ${list_of_private_repos[@]}
do
Find_And_Replace_Licence_Var $repo
done