/
zipfind
executable file
·92 lines (75 loc) · 1.89 KB
/
zipfind
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
#!/bin/sh
#searches for a substring of a file name in all of the zip formatted files
#under a given directory: jar, war, ear, sar and zip
#set to 0 to continue after the first match
SHORTCIRCUIT=0
#set to 0 in order to remove the ... during search
VERBOSE=1
CONVERT=0
EXTENSIONS='jar war ear sar zip'
USAGE(){
APPNAME=`basename $0`
echo "$APPNAME: searches for a substring of a file name in all of the jar "
echo " and jar type archives under a given directory "
echo " USAGE: "
echo " $APPNAME [option] <searchroot> <Substring> "
echo "options override default behavior. They are are: "
echo "-q : quiet. By Default, the search prints out a series of dots"
echo " to show it hasn't stalled"
echo "-s : shortcircuit By Default, the search continues after "
echo " the first match"
echo "-j : jars only By Default, the search cylces through $EXTENSIONS"
echo "-l : symlinks only Finds only symlink files"
}
class2path(){
echo $1 | sed 's!\.!\/!g'
}
EXTENSIONS='jar war ear sar zip'
while (( "$#" ))
do
case "$1" in
"-c")
CONVERT=1
shift
;;
"-j")
EXTENSIONS="jar"
shift
;;
"-q")
VERBOSE=0
shift
;;
"-s") SHORTCIRCUIT=1
shift
;;
*)
break
;;
esac
done
SEARCHROOT=$1
SUBSTRING=$2
if [ $CONVERT -gt 0 ]
then
SUBSTRING=`class2path $SUBSTRING`
fi
[ -z $SEARCHROOT ] && USAGE && exit 1
[ -z $SUBSTRING ] && USAGE && exit 1
cd $SEARCHROOT
for EXT in $EXTENSIONS
do
[ $VERBOSE -gt 0 ] && \
echo SEARCHING for $SUBSTRING in ALL $EXT Files in $SEARCHROOT
for ARCHIVE in `find $SEARCHROOT -name \*.$EXT `
do
[ $VERBOSE -gt 0 ] && echo -n .
if [ `file $ARCHIVE | grep -c "Zip archive data"` -gt 0 ]
then
[ `jar -tf $ARCHIVE | grep -c $SUBSTRING` -gt 0 ] && \
/bin/echo -e \\r $ARCHIVE && \
[ $SHORTCIRCUIT -gt 0 ] && exit 0
fi
done
done
echo