-
Notifications
You must be signed in to change notification settings - Fork 3
/
gitall
121 lines (102 loc) · 3 KB
/
gitall
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
#!/bin/bash
#This script helps to clone all repositories
#set -x
#
# import common bash scripts
#
SCRIPT_DIR=$(realpath $(dirname $0))
. $SCRIPT_DIR/include/bash/common.sh
# Default values
config_file="$SCRIPT_DIR/config/repositories/repositories.conf"
ARG="$(printf " %q " "${@}")"
CMD=
# Parse command-line options
while [[ "$#" -gt 0 ]]; do
case $1 in
--config-file=*)
config_file="${1#*=}"
shift
;;
*)
ARG+=("$1")
shift
;;
esac
done
# The first elemen is empty and should be remove from ARG
unset ARG[0]
# # Because $@ is an array, if we assign it to a variables, the space can be break.
# # Therefore, we can't just assigned it to a variable and pass to the function
# # Below is the trick that we store variables and their space character
# # Then pass to git via bash -c command
CMD="$(printf "%q " "${ARG[@]}")"
function git_command(){
repo_dir=$1
# if script is called without commandline paramteters,
# then print "git status", else handover command line parameters
# to git call
if [ ${#ARG[@]} -eq 0 ]; then
echo "no argument"
git -C "$repo_dir" status
else
bash -c "git -C \"$repo_dir\" ${CMD}"
fi
}
function get_server_url(){
conf_file=$1
echo $(git config -f $conf_file --get supported-server.$2)
return
}
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
errormsg "not supported repo type '$repo_type'"
fi
echo -e "$COL_BLUE$BG_WHITE---- $repo$COL_RESET$COL_BLUE$BG_WHITE -----------------------------------------$COL_RESET"
git_command "$SCRIPT_DIR/../$repo_name"
done
}
function parse_config () {
conf_section=($(git config -f $1 --list --name-only | sed "s/.[^.]*$//" | uniq))
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
git_command "$sec_path"
fi
done
}
function myini() {
git config -f $config_file --get $1;
}
using_proxy=$(myini Proxy.enable)
if [ "$using_proxy" != "yes" ]; then
echo " WARNING: ./repositories.conf proxy.enable not enabled"
else
proxy_url=$(myini Proxy.proxy)
shopt -s extglob
proxy_url="http://${proxy_url#http?(s)://}"
git config --global http.proxy $proxy_url
goodmsg "Proxy enabled"
fi
parse_config $config_file