-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild_module.sh
executable file
·136 lines (124 loc) · 3.32 KB
/
build_module.sh
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
#!/bin/bash
declare -A modules
program=$0
opt_module=""
opt_dir="./modules"
cache_dir="/tmp/rbrepo_cache"
f_usage() {
echo "$0 [-h] [-p /path/to/modules] -m module"
echo " -m module : name of module to build (mandatory)"
echo " -p path : Path to directory containing the modules (optional)"
echo " -h : Print this help"
}
f_build() {
local module=$1
local ret=0
# check if this module has been built
if [ ${modules[$module]} -eq 0 ]; then
# need to build the module
# check for module dependencies and build them first
if [ -f ${opt_dir}/$module/modules.dep ]; then
for moduledep in $(cat ${opt_dir}/$module/modules.dep); do
# check if the module has been built
if [ ${modules[$moduledep]} -eq 1 ]; then
continue
else
f_build $moduledep
if [ $? -ne 0 ]; then
echo "Something was wrong ... exiting"
ret=1
else
# module built successfuly
modules[${moduledep}]=1
fi
fi
done
fi
if [ $ret -eq 0 ]; then
# now, build the module
if [ -x ${opt_dir}/$module/build.sh ]; then
pushd ${opt_dir}/$module &>/dev/null
echo "Building module: $module"
./build.sh
if [ $? -ne 0 ]; then
echo "Something was wrong ... exiting"
ret=1
fi
modules[$module]=1
popd &>/dev/null
else
echo "Error: no script to build the module ${module}"
ret=1
fi
fi
fi
return $ret
}
while getopts "hm:p:" opt; do
case $opt in
h)
f_usage
exit 0
;;
m)
opt_module=${OPTARG}
;;
p)
opt_dir=${OPTARG}
;;
\?)
f_usage
exit 1
;;
:)
f_usage
exit 1
;;
esac
done
if [ "x${opt_module}" == "x" ]; then
echo "Error: it is mandatory to indicate module"
f_usage
exit 1
fi
if [ ! -d ${opt_dir} ]; then
echo "Error: ${opt_dir} is not a directory"
f_usage
exit 1
fi
pushd ${opt_dir} &>/dev/null
f_empty_dir=1
for module in $(ls -d * 2>/dev/null); do
f_empty_dir=0
modules[$module]=0
done
popd &>/dev/null
if [ $f_empty_dir -eq 1 ]; then
echo "Error: there is no module in path ${opt_dir}"
f_usage
exit 1
fi
if [ "${opt_module}" == "all" ]; then
# need to build all modules in directory
for module in ${!modules[@]}; do
# check if the module has been built
if [ ${modules[$module]} -eq 1 ]; then
# has been built
continue
else
f_build $module
if [ $? -ne 0 ]; then
echo "Something was wrong ... exiting"
exit 1
fi
fi
done
else
# need to build only one module
f_build ${opt_module}
if [ $? -ne 0 ]; then
echo "Something was wrong ... exiting"
exit 1
fi
fi
## vim:ts=4:sw=4:expandtab:ai:nowrap:formatoptions=croqln: