-
Notifications
You must be signed in to change notification settings - Fork 32
/
common
executable file
·93 lines (79 loc) · 2.03 KB
/
common
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
#!/bin/zsh
var_keys=(
INSTALLS
INSTALL
INSTALL_STR
APP
APP_ROOT
APP_MARK_EXEC_LOC
APP_MARK_EXEC
)
declare -A var_types=(
[INSTALLS]="file"
[INSTALL]="file"
[INSTALL_STR]="eval"
[APP]="eval"
[APP_ROOT]="eval"
[APP_MARK_EXEC_LOC]="eval"
[APP_MARK_EXEC]="file"
)
declare -A vars=(
[INSTALLS]=$'"./.installs"'
[INSTALL]=$'"./.install"'
[INSTALL_STR]=$'"$(echo "$INSTALLS" | head -n"$(( $INSTALL + 0 ))" | tail -n1)"'
[APP]=$'"$(echo "$INSTALL_STR" | cut -d" " -f1)"'
[APP_ROOT]=$'"$(echo "$INSTALL_STR" | cut -d" " -f2-)"'
[APP_MARK_EXEC_LOC]=$'"$(pwd)/apps/${APP}/executables"'
[APP_MARK_EXEC]=$'"$APP_MARK_EXEC_LOC"'
)
declare -A var_deps=(
[INSTALLS]=$'()'
[INSTALL]=$'()'
[INSTALL_STR]=$'(INSTALLS INSTALL)'
[APP]=$'(INSTALL_STR)'
[APP_ROOT]=$'(INSTALL_STR)'
[APP_MARK_EXEC_LOC]=$'(APP)'
[APP_MARK_EXEC]=$'(APP_MARK_EXEC_LOC)'
)
declare -A vars_done=()
populate() {
for key in "${var_keys[@]}"; do
eval "local this_deps=${var_deps[$key]}"
for dep in "${this_deps[@]}"; do
[[ "${vars_done[$dep]}" != "1" ]] \
&& continue 2
done
local var_type="${var_types[$key]}"
local var="${vars[$key]}"
if [[ "$var_type" == "file" ]]; then
eval "local file=$var"
if [[ -f "$file" ]]; then
export $key="$(cat "$file")"
vars_done[$key]=1
else
export $key=
fi
elif [[ "$var_type" == "eval" ]]; then
eval "export $key=$var"
vars_done[$key]=1
fi
done
}
populate
if [[ "$APP" != "" ]]; then
if [[ ! -d "./apps/${APP}" ]]; then
echo "invalid app name"
exit 1
fi
source "./apps/${APP}/common"
populate
fi
echo "Populated ${(k)vars_done}"
fail_if_not_populated() {
for var in "$@"; do
if [[ "${vars_done[$var]}" != "1" ]]; then
echo "Did not have $var"
exit 1
fi
done
}