-
Notifications
You must be signed in to change notification settings - Fork 3
/
cloneall
executable file
·158 lines (133 loc) · 4.93 KB
/
cloneall
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
#!/bin/bash
#This script helps to clone all repositories
#
# import common bash scripts
#
SCRIPT_DIR=$(dirname $0)
. $SCRIPT_DIR/include/bash/common.sh
config_file="$SCRIPT_DIR/config/repositories/repositories.conf"
# return github url bases on provided authentication or not
function get_url () {
repo_type=$1
repo_name=$3
if [[ $2 == http://* || $2 == https://* ]]; then
PROJECT_URL=`echo "$2" | sed 's~http[s]*://~~g'`
var_usr=$(echo ${repo_type^^}_BOT_USERNAME)
var_pw=$(echo ${repo_type^^}_BOT_PASSWORD)
bot_usr=${!var_usr}
bot_pw=${!var_pw}
repo_url="https://${PROJECT_URL}/${repo_name}.git"
if [ -n "${bot_usr}" ] && [ -n "${bot_pw}" ]; then
repo_url="https://${bot_usr}:${bot_pw}@${PROJECT_URL}/${repo_name}.git"
fi
else
repo_url="$2/${repo_name}.git"
fi
echo $repo_url
}
function get_server_url()
{
conf_file=$1
echo $(git config -f $conf_file --get supported-server.$2)
return
}
# Parse repo information for cloning/updating
# Arguments:
# $conf_file : repo configuration file
# $repo_type : repo type
function parse_repo () {
conf_file=$1
repo_type=$2
greenmsg "processing section $repo_type"
list_repos=($(git config -f $conf_file --list --name-only | grep $repo_type.))
for repo in "${list_repos[@]}"
do
repo_name=${repo#${repo_type}.}
server_url=$(get_server_url "${conf_file}" "${repo_type}")
if [[ "$server_url" != "" ]]; then
repo_url=$(get_url ${repo_type} ${server_url} ${repo_name})
else
errormsg "not supported repo type '$repo_type'"
fi
echo -e "$COL_BLUE$BG_WHITE---- $repo$COL_RESET$COL_BLUE$BG_WHITE -----------------------------------------$COL_RESET"
# switch repo to given released tag $TAG_NAME
if [[ "$TRIGGER_BY" =~ $TAG_REGEX || "$TRIGGER_BY" == "tag" ]] && [[ "$TAG_NAME" =~ $TAG_REGEX ]]; then
clone_update_repo "$SCRIPT_DIR/../$repo_name" "$repo_url" "$TAG_NAME"
else
# Allow to specify commit/branch of repos to be built
commit_branch=$(git config -f $conf_file --get $repo)
clone_update_repo "$SCRIPT_DIR/../$repo_name" "$repo_url" "$commit_branch"
fi
done
if [ "$?" -ne 0 ]; then
exit 1
fi
}
function parse_config () {
#echo "git config -f $1 --list --name-only | sed "s/.[^.]*$//" | uniq"
conf_section=($(git config -f $1 --list --name-only | sed "s/.[^.]*$//" | uniq))
#echo $conf_section
for section in "${conf_section[@]}"
do
section_server=$(get_server_url "$1" "$section")
if [ "$section_server" != "" ]; then
parse_repo $1 $section
elif [ "$section" != "supported-server" ]; then
sec_name=$(git config -f "$1" --get ${section}.name)
if [ "$sec_name" == "" ]; then
sec_name=${section}
fi
echo
greenmsg "processing section $sec_name"
echo -e "$COL_BLUE$BG_WHITE---- $sec_name$COL_RESET$COL_BLUE$BG_WHITE -----------------------------------------$COL_RESET"
sec_path=$(git config -f $1 --get ${section}.path)
if [ "$sec_path" == "" ]; then
sec_path="$SCRIPT_DIR/../${sec_name}"
fi
sec_url=$(eval echo $(git config -f $1 --get ${section}.url))
if [ "$sec_url" == "" ]; then
sec_url=$(get_url "github" ${sec_name})
fi
clone_update_repo "$sec_path" "$sec_url"
echo
echo
fi
done
}
echo -e "${COL_GREEN}####################################################################################${COL_RESET}"
echo -e "${COL_GREEN}# #${COL_RESET}"
echo -e "${COL_GREEN}# Cloning repositories #${COL_RESET}"
echo -e "${COL_GREEN}# #${COL_RESET}"
echo -e "${COL_GREEN}####################################################################################${COL_RESET}"
#iterate over all repositories and apply now the clone command
for i in "$@"
do
case $i in
--config-file=*)
config_file="${i#*=}"
;;
*)
echo -e $COL_RED"Argument not allowed:"$COL_RESET $i
echo -e $COL_RED"build terminated."$COL_RESET
exit 1
;;
esac
done
if [ -f $config_file ]; then
echo -e "${COL_GREEN}# Cloning repositories with config in $config_file #${COL_RESET}"
else
errormsg "Repo configuration '$config_file' is not existing"
fi
# Receive event from other repos and update repository config file
if [ -n "$REPOSITORY" ] && [ -n "$PULL_REQUEST_BRANCH" ]; then
echo -e "${COL_GREEN}# Trigger AIO from repository: $REPOSITORY; branch: $PULL_REQUEST_BRANCH #${COL_RESET}"
grep -q $REPOSITORY $config_file
if [ $? -ne 0 ]; then
errormsg "Repository received from trigger request not found in '$config_file'"
else
sed -i "s,$REPOSITORY=.*,$REPOSITORY=$PULL_REQUEST_BRANCH," $config_file
echo -e "${COL_GREEN}# Updated $REPOSITORY in $config_file with value $PULL_REQUEST_BRANCH"
fi
fi
parse_config $config_file
goodmsg "Cloning repositories successfully done"