setup_submodules
2.57 KB
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
#!/bin/bash -x
# =================
# = Do not chenge.
# =================
GIT_URL_SUBS="http://gitlab.osdev.nl/open_source"
FUNC_RESULT=""
function print_usage_exit()
{
echo "Usage $0 -i|--install|-u|--update"
echo " -i or --install Install the submodules mentioned in the submodules.list"
echo " -u or --update Update the submodules mentioned in the submodules.list"
echo " "
exit 1
}
function check_top_or_sub()
{
# This function checks if we're the top-repository.
# In that case we need the submodules.. If we're already a submodule,
# we simply exit this script with a message
if [ -e ./.git ]; then
FUNC_RESULT="1"
return
elif [ -e ../.git ]; then
if [ -e ../.submodules ]; then
echo "Seems like we're already a submodule. Nothing to do here."
FUNC_RESULT="0"
return
fi
fi
FUNC_RESULT="0"
return
}
function check_working_dir()
{
# Check if we're in the top-level directory of our repository.
if [ -f ./scripts/submodules.list ]; then
# We're good to go
FUNC_RESULT="1"
return
fi
FUNC_RESULT="0"
return
}
function read_submodules()
{
if [ -e ./scripts/submodules.list ]; then
source ./scripts/submodules.list
fi
}
function add_submodules()
{
for SUB_MODULE in ${SUB_MODULES}
do
git submodule add -f ${GIT_URL_SUBS}/${SUB_MODULE}.git ${SUB_MODULE}
git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS}/${SUB_MODULE}.git
done
}
function get_submodules()
{
git submodule update --init --recursive
}
function update_submodules() {
git submodule update --recursive
}
# =============================================================================
# == T H E M A I N E N T R Y O F T H I S S C R I P T ==
# =============================================================================
check_top_or_sub
if [ "${FUNC_RESULT}" == "0" ]; then
echo "Seems like we're a submodule already or not part of a repository."
exit 0
fi
check_working_dir
if [ "${FUNC_RESULT}" == "0" ]; then
echo "Go to the top of this repository and type : scripts/setup_submodules [-i|--install]"
exit 0
fi
read_submodules
case "$1" in
-i*|--install*)
echo "Installing submodules for this repository ( ${PWD} )"
add_submodules
get_submodules
;;
-u*|--update*)
echo "Update submodules : ${SUB_MODULES}"
update_submodules
;;
*)
echo "No parameters found..."
print_usage_exit
;;
esac