-
Notifications
You must be signed in to change notification settings - Fork 7
/
afterglow.sh
executable file
·119 lines (103 loc) · 2.64 KB
/
afterglow.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
#!/bin/sh
###
# This shell script invokes AfterGlow [1] with the settings given as arguments
# and generates a GIF graph image of the resulting output from Afterglow; using
# neato, dot or sfdp [2].
#
# Usage:
# afterglow.sh "path_to_csv_file" "path_to_colour_property_file"
# "path_to_resulting_output_file"
# "path_to_afterglow.pl" "filter name" "arguments"
#
# Note: Paths can be absolute or relative.
# For a list of 'arguments' please see [1].
#
# Example usage: ./afterglow.sh data/firewall.csv sample.properties images/firewall.gif afterglow/src/afterglow.pl neato -d -e 1.5
#
# Exit status:
# 0: On successful image creation.
# 1: Error creating an output image.
# 2: No valid data file supplied.
# 3: No valid property file supplied.
# 4: Perl is not installed $PATH.
# 5: Neato/Sfdp/Dot [2] is not installed $PATH.
# 6: Afterglow.pl [1] is not present.
#
# References:
# [1] http://afterglow.sourceforge.net/
# [2] http://www.graphviz.org/Documentation.php
###
#Path to a CSV data file.
dataFile="$1"
shift
#Path to a colour property file (if any).
propertyFile="$1"
shift
#Path to create the output file, including its name and extension.
outputFile="$1"
shift
#Complete path to afterglow.pl, including its name and extension.
afPath="$1"
shift
#Filter to be used with GraphViz
filter="$1"
shift
#Additional parameters (if any) to be passed to AfterGlow.
args="$@"
#Sanitize inputs -- Check if datafile is present.
if [ ! -e "$dataFile" ]
then
echo "No valid data file." >&2
exit 2
fi
#Check if property file is valid.
if [ ! -e "$propertyFile" ]
then
echo "No valid property file." >&2
exit 3
fi
#Check if perl is installed anywhere on $PATH.
out=`which perl`
if [ $? -eq 1 ]
then
echo "Perl seems to be missing." >&2
exit 4
fi
#Check if neato is installed anywhere on $PATH.
out=`which neato`
if [ $? -eq 1 ]
then
echo "Neato seems to be missing." >&2
exit 5
fi
#Check if dot is installed anywhere on $PATH.
out=`which dot`
if [ $? -eq 1 ]
then
echo "Dot seems to be missing." >&2
exit 5
fi
#Check if sfdp is installed anywhere on $PATH.
out=`which sfdp`
if [ $? -eq 1 ]
then
echo "Sfdp seems to be missing." >&2
exit 5
fi
#Check if afterglow.pl is present.
if [ ! -e "$afPath" ]
then
echo "Afterglow.pl is not present in the directory given." >&2
exit 6
fi
#Everything looks good for now; render the graph.
perl "$afPath" -i "$dataFile" -c "$propertyFile" $args | "$filter" -Tgif -o "$outputFile"
#Check if the output was successfuly rendered and that the output file is
#more than 0 bytes in size.
if [ -s "$outputFile" ]
then
exit 0
else
echo "Error creating an output image." >&2
exit 1
fi