-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathah-tb.sh
executable file
·105 lines (87 loc) · 2.91 KB
/
ah-tb.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
#!/bin/bash
# Copyright (C) 2018 Stephen Farrell, [email protected]
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#set -x
# Create a diretory with content specific to an asset-holder
# idea is we have a string/regexp that allows us to extract
# the set of collision info that we might wanna send to an
# asset-holder
# Note that manual examination is needed before makging a
# tarball and sending - the string/regexp might select too
# many clusters
function whenisitagain()
{
date -u +%Y%m%d-%H%M%S
}
NOW=$(whenisitagain)
outdir="ah-"$NOW
function howmany() {
case $- in *f*) set -- $1;; *) set -f; set -- $1; set +f;; esac
echo $#
}
function copyif()
{
# copy $1 if it exists to $2
if [ -f $1 ]
then
cp $1 $2
fi
}
usage()
{
echo "Extract a set of clusters that match a search string/regexp to sending to asset-holder"
echo "usage: $0 string/regexp"
echo " be careful with using quotes correctly to get the effects you want!"
echo " results will be in a directory named with a timestamp, e.g. $outdir"
echo " you might want to give that a more meaningful name"
echo "Run this in the directory that contains the cluster*.json files"
exit 99
}
if (( $# != 1 ))
then
usage
fi
needle=$1
matchingfiles=`grep -l "$needle" cluster*.json`
matchingcount=$(howmany "$matchingfiles")
if (( matchingcount==0))
then
echo "There are $matchingcount clusters matching '$needle' - exiting"
exit 0
fi
echo "There are $matchingcount clusters matching '$needle'"
mkdir -p $outdir
if [ ! -d $outdir ]
then
echo "Can't make $outdir - exiting"
exit 1
fi
for cluster in $matchingfiles
do
cnum=`basename $cluster .json | sed -e 's/cluster//'`
cp cluster$cnum.json $outdir
copyif cluster$cnum.words $outdir
copyif graph$cnum.dot $outdir
copyif graph$cnum.dot.svg $outdir
copyif graph$cnum.dot.png $outdir
copyif cluster$cnum-wordle.png $outdir
copyif cluster$cnum-wordle.svg $outdir
done
echo "Done - Results are in $outdir"