-
Notifications
You must be signed in to change notification settings - Fork 0
/
thyme.stats
76 lines (65 loc) · 1.73 KB
/
thyme.stats
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
#!/bin/bash
# Stored paths and filenames to avoid typo errors...
live_capture_file_path=live_capture
output_file_path=reports/today
backup_file_path=reports/backups
output_file=$(date +%Y-%m-%d--%H:%M:%S)_applications_track_daily_report.html
live_capture_file=live_capture.json
# How to dirty retain which option is set or not... ^^
set_option_b=false
set_option_r=false
# Quick help display function
usage()
{
echo -e "Usage: $0 [-br] -p <base directory>"
echo -e "\t-b\tbackup old HTML reports."
echo -e "\t-p\tapplication base directory."
echo -e "\t-r\tremove live tracking JSON file."
}
# Arguments number verification.
if [[ $# -lt 1 || $# -gt 4 ]]; then
usage
exit 1
fi
# Reading arguments.
while [[ $# ]]; do
if [[ $# -eq 0 ]]; then
break
fi
case $1 in
-p)
path=$2
shift 2;;
-b)
set_option_b=true
shift;;
-r)
set_option_r=true
shift;;
*)
usage
exit 1;;
esac
done
# Checking directories existence.
if [[ ! -d $path ]]; then
mkdir $path
elif [[ ! -d $path/$live_capture_file_path ]]; then
mkdir $path/$live_capture_file_path
elif [[ ! -d $path/$output_file_path ]]; then
mkdir $path/$output_file_path
elif [[ ! -d $path/$backup_file_path ]]; then
mkdir $path/$backup_file_path
fi
# Checking of HTML report status.
if [[ ! $set_option_b ]]; then
rm -f $path/$output_file_path/*
fi
# Backup current HTML report.
mv $path/$output_file_path/* $path/$backup_file_path
# Generating HTML report.
thyme show -i $path/$live_capture_file_path/$live_capture_file -w stats > $path/$output_file_path/$output_file
# Checking files existence and actions which must be taken.
if [[ -f $path/$live_capture_file_path/$live_capture_file && $set_option_r ]]; then
rm -f $path/$live_capture_file_path/$live_capture_file
fi