-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathakutils_dependency_check.sh
executable file
·120 lines (100 loc) · 4.39 KB
/
akutils_dependency_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
#!/usr/bin/env bash
#
# akutils_dependency_check.sh - Test if your system will run akutils workflows
#
# Version 1.1.0 (June 16, 2015)
#
# Copyright (c) 2014-2015 Andrew Krohn
#
# This software is provided 'as-is', without any express or implied
# warranty. In no event will the authors be held liable for any damages
# arising from the use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it
# freely, subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not
# claim that you wrote the original software. If you use this software
# in a product, an acknowledgment in the product documentation would be
# appreciated but is not required.
# 2. Altered source versions must be plainly marked as such, and must not be
# misrepresented as being the original software.
# 3. This notice may not be removed or altered from any source distribution.
#
set -e
## Check whether user had supplied -h or --help. If yes display help
if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]]; then
scriptdir="$( cd "$( dirname "$0" )" && pwd )"
less $scriptdir/docs/akutils_dependency_check.help
exit 0
fi
## Check whether user had supplied result. If yes display result
if [[ "$1" == "--result" ]]; then
scriptdir="$( cd "$( dirname "$0" )" && pwd )"
resultcount=`ls $scriptdir/akutils_resources/akutils.dependencies.result 2>/dev/null | wc -l`
if [[ $resultcount == 0 ]]; then
echo "
Dependency check has not been run previously. Execute
akutils_dependency_check.sh to generate results.
"
elif [[ $resultcount == 1 ]]; then
less $scriptdir/akutils_resources/akutils.dependencies.result
fi
exit 0
fi
## Find scripts location
scriptdir="$( cd "$( dirname "$0" )" && pwd )"
## Loop through full dependency list
echo "
Checking for required dependencies...
"
if [[ -f $scriptdir/akutils_resources/akutils.dependencies.result ]]; then
rm $scriptdir/akutils_resources/akutils.dependencies.result
fi
for line in `cat $scriptdir/akutils_resources/akutils.dependencies.list | cut -f1`; do
# scriptuse=`grep "$line" $scriptdir/akutils_resources/akutils.dependencies.list | cut -f2`
titlecount=`echo $line | grep "#" | wc -l`
if [[ $titlecount == 1 ]]; then
echo "" >> $scriptdir/akutils_resources/akutils.dependencies.result
grep "$line" $scriptdir/akutils_resources/akutils.dependencies.list >> $scriptdir/akutils_resources/akutils.dependencies.result
elif [[ $titlecount == 0 ]]; then
dependcount=`command -v $line 2>/dev/null | wc -w`
if [[ $dependcount == 0 ]]; then
echo "$line FAIL" >> $scriptdir/akutils_resources/akutils.dependencies.result
else
if [[ $dependcount -ge 1 ]]; then
echo "$line pass" >> $scriptdir/akutils_resources/akutils.dependencies.result
fi
fi
fi
done
echo "" >> $scriptdir/akutils_resources/akutils.dependencies.result
#sed -i "1i \t" $scriptdir/akutils_resources/akutils.dependencies.result
## Count results
dependencycount=`grep -v "#" $scriptdir/akutils_resources/akutils.dependencies.list | sed '/^$/d' | wc -l`
passcount=`grep "pass" $scriptdir/akutils_resources/akutils.dependencies.result | wc -l`
failcount=`grep "FAIL" $scriptdir/akutils_resources/akutils.dependencies.result | wc -l`
if [[ $failcount == 0 ]]; then
sed -i "1i No failures! All akutils workflows should run OK." $scriptdir/akutils_resources/akutils.dependencies.result
elif [[ $failcount -ge 1 ]]; then
sed -i "1i Some dependencies are not in your path. Correct failures and rerun\ndependency check." $scriptdir/akutils_resources/akutils.dependencies.result
fi
sed -i "1i Dependency check results for akutils:\n\nTested $dependencycount dependencies\nPassed: $passcount/$dependencycount\nFailed: $failcount/$dependencycount" $scriptdir/akutils_resources/akutils.dependencies.result
echo "Test complete.
Dependency check results for akutils:
Tested $dependencycount dependencies
Passed: $passcount/$dependencycount
Failed: $failcount/$dependencycount"
if [[ $failcount == 0 ]]; then
echo "No failures! All akutils workflows should run OK."
elif [[ $failcount -ge 1 ]]; then
echo "Some dependencies are not in your path. Correct failures and rerun dependency check.
Missing dependencies:"
grep "FAIL" $scriptdir/akutils_resources/akutils.dependencies.result | cut -f1
fi
echo "
For detailed results, execute:
akutils_dependency_check.sh --result
"
exit 0