Commit 8e5d7ec0ccdcb37cbef8686bf3600aa3370de7bc
1 parent
fe885bcf
Added submodule script and configuration.
NOTE: config and interfaces are closed_source repo's. this will be changed in a later stadium.
Showing
3 changed files
with
176 additions
and
0 deletions
.gitignore
scripts/setup_submodules
0 → 100755
1 | +#!/bin/bash | ||
2 | + | ||
3 | +# =============================================== | ||
4 | +# == Setting some environment variables | ||
5 | +# =============================================== | ||
6 | +GIT_URL_SUBS="http://gitlab.osdev.nl/open_source" | ||
7 | +FUNC_RESULT="-1" | ||
8 | + | ||
9 | +# Name : print_usage_exit() | ||
10 | +# Description : Print the way this script is intended to be used and exit. | ||
11 | +# Parameters : None. | ||
12 | +# Returns : err_code 1 to the Operating System | ||
13 | +# -------------------------------------------------------------------------------------- | ||
14 | +function print_usage_exit() | ||
15 | +{ | ||
16 | + echo "Usage $0 -i|--install|-u|--update" | ||
17 | + echo " -i or --install Install the submodules mentioned in the submodules.list" | ||
18 | + echo " -u or --update Update the submodules mentioned in the submodules.list" | ||
19 | + echo " " | ||
20 | + exit 1 | ||
21 | +} | ||
22 | + | ||
23 | +# Name : check_top_or_sub | ||
24 | +# Description : Determine if we're running in a "single" lib-build or part of a | ||
25 | +# "meta"-repository ( submodule ). | ||
26 | +# Parameters : None | ||
27 | +# Returns : Updates the value FUNC_RESULT. | ||
28 | +# -1 - We're neither a git-repo or submodule. | ||
29 | +# 0 - We're a submodule | ||
30 | +# 1 - We're a top-repo ( Single library ) | ||
31 | +# -------------------------------------------------------------------------------------- | ||
32 | +function check_top_or_sub() | ||
33 | +{ | ||
34 | + # This function checks if we're the top-repository. | ||
35 | + # In that case we need the submodules.. If we're already a submodule, | ||
36 | + # we simply exit this script with a message | ||
37 | + if [ -e ./.git ]; then | ||
38 | + FUNC_RESULT="1" | ||
39 | + return | ||
40 | + elif [ -e ../.git ]; then | ||
41 | + if [ -e ../.submodules ]; then | ||
42 | + echo "Seems like we're already a submodule. Nothing to do here." | ||
43 | + FUNC_RESULT="0" | ||
44 | + return | ||
45 | + fi | ||
46 | + fi | ||
47 | + FUNC_RESULT="-1" | ||
48 | + return | ||
49 | +} | ||
50 | + | ||
51 | +# Name : check_working_dir | ||
52 | +# Description : If we're in the top of our repo, we can run this script further. | ||
53 | +# Parameters : None. | ||
54 | +# Returns : Updates the value FUNC_RESULT. | ||
55 | +# -1 - Not used. | ||
56 | +# 0 - We're not on the top-level | ||
57 | +# 1 - We're at the top-level. Good to go. | ||
58 | +# -------------------------------------------------------------------------------------- | ||
59 | +function check_working_dir() | ||
60 | +{ | ||
61 | + FUNC_RESULT="-1" | ||
62 | + # Check if we're in the top-level directory of our repository. | ||
63 | + if [ -f ./scripts/submodules.list ]; then | ||
64 | + # We're good to go | ||
65 | + FUNC_RESULT="1" | ||
66 | + return | ||
67 | + fi | ||
68 | + FUNC_RESULT="0" | ||
69 | + return | ||
70 | +} | ||
71 | + | ||
72 | +# Name : read_submodules | ||
73 | +# Description : Read the list of submodules needed for this project | ||
74 | +# Parameters : None | ||
75 | +# Returns : Updates the value FUNC_RESULT | ||
76 | +# 0 - Module list was not found | ||
77 | +# 1 - Module list was found and read. | ||
78 | +# -------------------------------------------------------------------------------------- | ||
79 | +function read_submodules() | ||
80 | +{ | ||
81 | + FUNC_RESULT="-1" | ||
82 | + if [ -e ./scripts/submodules.list ]; then | ||
83 | + source ./scripts/submodules.list | ||
84 | + FUNC_RESULT="1" | ||
85 | + return | ||
86 | + fi | ||
87 | + | ||
88 | + echo "Submodules list not found...." | ||
89 | + FUNC_RESULT="0" | ||
90 | + return | ||
91 | +} | ||
92 | + | ||
93 | +# Name : add_submodules | ||
94 | +# Description : Configure the repo to add the submodules. | ||
95 | +# Parameters : None. | ||
96 | +# Returns : None. | ||
97 | +# -------------------------------------------------------------------------------------- | ||
98 | +function add_submodules() | ||
99 | +{ | ||
100 | + echo -e "Adding SubModule(s)." | ||
101 | + for SUB_MODULE in ${SUB_MODULES} | ||
102 | + do | ||
103 | + echo -e "< ${SUB_MODULE} >" | ||
104 | + git submodule add -f ${GIT_URL_SUBS}/${SUB_MODULE}.git ${SUB_MODULE} | ||
105 | + git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS}/${SUB_MODULE}.git | ||
106 | + done | ||
107 | +} | ||
108 | + | ||
109 | +# Name : get_submodules | ||
110 | +# Description : Actually get the submodules from gitlab and add them. | ||
111 | +# Parameters : None | ||
112 | +# Returns : None | ||
113 | +# -------------------------------------------------------------------------------------- | ||
114 | +function get_submodules() | ||
115 | +{ | ||
116 | + git submodule update --init --recursive | ||
117 | +} | ||
118 | + | ||
119 | +# Name : update_submodules | ||
120 | +# Description : Update the submodules already added. | ||
121 | +# Parameters : None | ||
122 | +# Returns : None | ||
123 | +# -------------------------------------------------------------------------------------- | ||
124 | +function update_submodules() | ||
125 | +{ | ||
126 | + git submodule update --recursive | ||
127 | +} | ||
128 | + | ||
129 | +# ============================================================================= | ||
130 | +# == T H E M A I N E N T R Y O F T H I S S C R I P T == | ||
131 | +# ============================================================================= | ||
132 | +check_top_or_sub | ||
133 | +if [ "${FUNC_RESULT}" == "0" ]; then | ||
134 | + echo "Seems like we're a submodule already or not part of a repository." | ||
135 | + exit 0 | ||
136 | +fi | ||
137 | + | ||
138 | +check_working_dir | ||
139 | +if [ "${FUNC_RESULT}" == "0" ]; then | ||
140 | + echo "Go to the top of this repository and type : scripts/setup_submodules [-i|--install]" | ||
141 | + exit 0 | ||
142 | +fi | ||
143 | + | ||
144 | +read_submodules | ||
145 | + | ||
146 | +case "$1" in | ||
147 | + -i*|--install*) | ||
148 | + echo "Installing submodules for this repository ( ${PWD} )" | ||
149 | + add_submodules | ||
150 | + get_submodules | ||
151 | + ;; | ||
152 | + -u*|--update*) | ||
153 | + echo "Update submodules : ${SUB_MODULES}" | ||
154 | + update_submodules | ||
155 | + ;; | ||
156 | + *) | ||
157 | + echo "No parameters found..." | ||
158 | + print_usage_exit | ||
159 | + ;; | ||
160 | +esac | ||
161 | + |