-
Notifications
You must be signed in to change notification settings - Fork 1
/
libexec.sh
53 lines (48 loc) · 1.06 KB
/
libexec.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
#!/bin/bash
# reads dependencies from the given file into an array "dependencies"
function read_file_header {
local input_file="$1"
local pattern1='^ *## *dependency: *(.*)$'
local pattern2='^[^ ^#].*$'
local line
if [ -f "${input_file}" ]; then
while read -r line; do
if [[ "$line" =~ $pattern1 ]]; then
add_dependency "${BASH_REMATCH[1]}"
elif [[ "$line" =~ $pattern2 ]]; then
break
fi
done < "$input_file"
else
errcho "Cannot find file $input_file"
exit 1
fi
}
function add_dependency {
local new_entry="$1"
local ee
for ee in "${dependencies[@]}"; do
if [[ "$ee" == "$new_entry" ]]; then
return
fi
done
dependencies+=("$new_entry")
}
function collect_dependencies {
local input_file="$1"
dependencies=("$input_file")
read_file_header $input_file
local dep_len=${#dependencies[@]}
local old_dep_len=0
while true; do
if [[ "${dep_len}" != "${old_dep_len}" ]]; then
for ee in "${dependencies[@]}"; do
read_file_header $ee
done
old_dep_len=$dep_len
dep_len=${#dependencies[@]}
else
break
fi
done
}