This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck.sh
executable file
·171 lines (158 loc) · 3.54 KB
/
check.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/bash
# written by Albert Gnandt (http://www.gnandt.com/)
# $Id$
print_ok()
{
sh output.sh --green -n "echo ok."
}
print_failed()
{
sh output.sh --red -n "echo FAILED."
exit 1
}
check_cmd()
{
echo -n "Looking for command $2 ... "
CMD=`which $2`
if [ "$CMD" = "" ]; then
print_failed
fi
case "$1" in
--exists|-e)
if [ -f $CMD ]; then
print_ok
else
print_failed
fi
;;
--not-exists|-n)
if [ ! -f $CMD ]; then
print_ok
else
print_failed
fi
;;
*)
print_usage
;;
esac
}
check_dir()
{
echo -n "Looking for directory $2 ... "
case "$1" in
--exists|-e)
if [ -d $2 ]; then
print_ok
else
print_failed
fi
;;
--not-exists|-n)
if [ ! -d $2 ]; then
print_ok
else
print_failed
fi
;;
*)
print_usage
;;
esac
}
check_lib()
{
RETURN=""
case "$1" in
--exists|-e)
echo -n "Looking for library $2 ... "
RETURN=`pkg-config --exists $2 && echo "TRUE"`
;;
--not-exists|-n)
echo -n "Looking for library $2 ... "
RETURN=`pkg-config --exists $2 || echo "TRUE"`
;;
esac
if [ "$RETURN" = "TRUE" ]; then
print_ok
else
print_failed
fi
}
check_lib_version()
{
RETURN=""
case "$1" in
--greater-equals|-ge)
echo -n "Looking for at least version $2 of library $3 ... "
RETURN=`pkg-config --atleast-version=$2 $3 && echo "TRUE"`
;;
--equals|-eq)
echo -n "Looking for version $2 of library $3 ... "
RETURN=`pkg-config --exact-version=$2 $3 && echo "TRUE"`
;;
--less-equals|-le)
echo -n "Looking for maximal version $2 of library $3 ... "
RETURN=`pkg-config --max-version=$2 $3 && echo "TRUE"`
;;
*)
print_usage
;;
esac
if [ "$RETURN" = "TRUE" ]; then
print_ok
else
print_failed
fi
}
print_usage()
{
echo "Environment variable OPENDICOM_COLOR_OUTPUT=1 has to be set. Otherwise, colorization is ignored."
echo
echo "usage: bash check.sh {{--cmd,-c|--dir,-d|--lib,-l} {--exists,-e|--not-exists,-n} <name1> <name2> ... <nameN> | {--lib-version,-lv} {--greater-equals,-ge|--equals,-eq|--less-equals,-le} <version> <name>}"
exit 1
}
ARG_LIST=""
for ARG in $@; do
if [ "$ARG" != "$1" ] && [ "$ARG" != "$2" ]; then
ARG_LIST="$ARG_LIST $ARG"
fi
done
case "$1" in
--cmd|-c)
if [ $# -lt 3 ]; then
print_usage
fi
for ARG in $ARG_LIST; do
check_cmd $2 $ARG
done
;;
--dir|-d)
if [ $# -lt 3 ]; then
print_usage
fi
for ARG in $ARG_LIST; do
check_dir $2 $ARG
done
;;
--lib|-l)
if [ $# -lt 3 ]; then
print_usage
fi
check_cmd --exists pkg-config
for ARG in $ARG_LIST; do
check_lib $2 $ARG
done
;;
--lib-version|-lv)
if [ $# -lt 4 ]; then
print_usage
fi
check_cmd --exists pkg-config
check_lib_version $2 $3 $4
;;
*)
print_usage
;;
esac
exit 0