0bf1b2f7
Peter M. Groen
Fixed script.
|
1
|
#!/bin/bash
|
bbca8c1a
Peter M. Groen
Added comments to...
|
2
3
4
5
|
# ===============================================
# == Setting some environment variables
# ===============================================
|
e8b2b36e
Peter M. Groen
Added logger as s...
|
6
7
8
|
GIT_URL_OPEN="http://gitlab.osdev.nl/open_source"
GIT_URL_CLOSED="git@gitlab.osdev.nl:closed_source"
|
bbca8c1a
Peter M. Groen
Added comments to...
|
9
|
FUNC_RESULT="-1"
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
10
|
|
bbca8c1a
Peter M. Groen
Added comments to...
|
11
12
13
14
15
|
# Name : print_usage_exit()
# Description : Print the way this script is intended to be used and exit.
# Parameters : None.
# Returns : err_code 1 to the Operating System
# --------------------------------------------------------------------------------------
|
e0b1fe64
Peter M. Groen
Fixed script.
|
16
17
|
function print_usage_exit()
{
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
18
19
20
21
22
23
24
|
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
}
|
bbca8c1a
Peter M. Groen
Added comments to...
|
25
26
27
28
29
30
31
32
33
|
# Name : check_top_or_sub
# Description : Determine if we're running in a "single" lib-build or part of a
# "meta"-repository ( submodule ).
# Parameters : None
# Returns : Updates the value FUNC_RESULT.
# -1 - We're neither a git-repo or submodule.
# 0 - We're a submodule
# 1 - We're a top-repo ( Single library )
# --------------------------------------------------------------------------------------
|
e0b1fe64
Peter M. Groen
Fixed script.
|
34
35
|
function check_top_or_sub()
{
|
59367614
Peter M. Groen
Install script..
|
36
37
38
|
# 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
|
e0b1fe64
Peter M. Groen
Fixed script.
|
39
40
41
42
43
|
if [ -e ./.git ]; then
FUNC_RESULT="1"
return
elif [ -e ../.git ]; then
if [ -e ../.submodules ]; then
|
59367614
Peter M. Groen
Install script..
|
44
|
echo "Seems like we're already a submodule. Nothing to do here."
|
e0b1fe64
Peter M. Groen
Fixed script.
|
45
46
|
FUNC_RESULT="0"
return
|
59367614
Peter M. Groen
Install script..
|
47
48
|
fi
fi
|
bbca8c1a
Peter M. Groen
Added comments to...
|
49
|
FUNC_RESULT="-1"
|
e0b1fe64
Peter M. Groen
Fixed script.
|
50
|
return
|
59367614
Peter M. Groen
Install script..
|
51
52
|
}
|
bbca8c1a
Peter M. Groen
Added comments to...
|
53
54
55
56
57
58
59
60
|
# Name : check_working_dir
# Description : If we're in the top of our repo, we can run this script further.
# Parameters : None.
# Returns : Updates the value FUNC_RESULT.
# -1 - Not used.
# 0 - We're not on the top-level
# 1 - We're at the top-level. Good to go.
# --------------------------------------------------------------------------------------
|
e0b1fe64
Peter M. Groen
Fixed script.
|
61
62
|
function check_working_dir()
{
|
bbca8c1a
Peter M. Groen
Added comments to...
|
63
|
FUNC_RESULT="-1"
|
59367614
Peter M. Groen
Install script..
|
64
65
66
|
# Check if we're in the top-level directory of our repository.
if [ -f ./scripts/submodules.list ]; then
# We're good to go
|
e0b1fe64
Peter M. Groen
Fixed script.
|
67
68
|
FUNC_RESULT="1"
return
|
59367614
Peter M. Groen
Install script..
|
69
|
fi
|
e0b1fe64
Peter M. Groen
Fixed script.
|
70
71
|
FUNC_RESULT="0"
return
|
59367614
Peter M. Groen
Install script..
|
72
73
|
}
|
bbca8c1a
Peter M. Groen
Added comments to...
|
74
75
76
77
78
79
80
|
# Name : read_submodules
# Description : Read the list of submodules needed for this project
# Parameters : None
# Returns : Updates the value FUNC_RESULT
# 0 - Module list was not found
# 1 - Module list was found and read.
# --------------------------------------------------------------------------------------
|
e0b1fe64
Peter M. Groen
Fixed script.
|
81
82
|
function read_submodules()
{
|
bbca8c1a
Peter M. Groen
Added comments to...
|
83
|
FUNC_RESULT="-1"
|
59367614
Peter M. Groen
Install script..
|
84
85
|
if [ -e ./scripts/submodules.list ]; then
source ./scripts/submodules.list
|
bbca8c1a
Peter M. Groen
Added comments to...
|
86
87
|
FUNC_RESULT="1"
return
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
88
|
fi
|
bbca8c1a
Peter M. Groen
Added comments to...
|
89
90
91
92
|
echo "Submodules list not found...."
FUNC_RESULT="0"
return
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
93
94
|
}
|
bbca8c1a
Peter M. Groen
Added comments to...
|
95
96
97
98
99
|
# Name : add_submodules
# Description : Configure the repo to add the submodules.
# Parameters : None.
# Returns : None.
# --------------------------------------------------------------------------------------
|
e0b1fe64
Peter M. Groen
Fixed script.
|
100
101
|
function add_submodules()
{
|
bbca8c1a
Peter M. Groen
Added comments to...
|
102
|
echo -e "Adding SubModule(s)."
|
e8b2b36e
Peter M. Groen
Added logger as s...
|
103
|
for SUB_MODULE in ${SUB_MODULES_OPEN}
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
104
|
do
|
e8b2b36e
Peter M. Groen
Added logger as s...
|
105
106
107
108
109
110
111
112
113
|
git submodule add -f ${GIT_URL_OPEN}/${SUB_MODULE}.git submodules/${SUB_MODULE}
git config submodule.${SUB_MODULE}.url ${GIT_URL_OPEN}/${SUB_MODULE}.git
done
for SUB_MODULE in ${SUB_MODULES_CLOSED}
do
echo {GIT_URL_CLOSED}/${SUB_MODULE}.git
git submodule add -f ${GIT_URL_CLOSED}/${SUB_MODULE}.git submodules/${SUB_MODULE}
git config submodule.${SUB_MODULE}.url ${GIT_URL_CLOSED}/${SUB_MODULE}.git
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
114
|
done
|
e8b2b36e
Peter M. Groen
Added logger as s...
|
115
|
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
116
117
|
}
|
bbca8c1a
Peter M. Groen
Added comments to...
|
118
119
120
121
122
|
# Name : get_submodules
# Description : Actually get the submodules from gitlab and add them.
# Parameters : None
# Returns : None
# --------------------------------------------------------------------------------------
|
e0b1fe64
Peter M. Groen
Fixed script.
|
123
124
|
function get_submodules()
{
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
125
126
127
|
git submodule update --init --recursive
}
|
bbca8c1a
Peter M. Groen
Added comments to...
|
128
129
130
131
132
|
# Name : update_submodules
# Description : Update the submodules already added.
# Parameters : None
# Returns : None
# --------------------------------------------------------------------------------------
|
0bf1b2f7
Peter M. Groen
Fixed script.
|
133
134
|
function update_submodules()
{
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
135
136
137
138
139
140
|
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 ==
# =============================================================================
|
e0b1fe64
Peter M. Groen
Fixed script.
|
141
142
|
check_top_or_sub
if [ "${FUNC_RESULT}" == "0" ]; then
|
59367614
Peter M. Groen
Install script..
|
143
144
145
146
|
echo "Seems like we're a submodule already or not part of a repository."
exit 0
fi
|
e0b1fe64
Peter M. Groen
Fixed script.
|
147
148
|
check_working_dir
if [ "${FUNC_RESULT}" == "0" ]; then
|
59367614
Peter M. Groen
Install script..
|
149
150
151
152
|
echo "Go to the top of this repository and type : scripts/setup_submodules [-i|--install]"
exit 0
fi
|
b5d9e433
Peter M. Groen
Fixed License Hea...
|
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
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
|