-
Notifications
You must be signed in to change notification settings - Fork 0
/
docu-search.sh
executable file
·129 lines (122 loc) · 6.5 KB
/
docu-search.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
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# declare variables and set parameters
RED='\033[0;31m' # Red color
NC='\033[0m' # No Color
DATE=$(date +"%d-%m-%Y-%H-%M-%S")
CASE=
WIZARD=
while [ "$1" != "" ]; do
case $1 in
-p | --product ) shift
WIZARD= ; PRODUCT=$1 ; FILE=html
shift
;;
-s | --search ) shift
WIZARD= ; SEARCH=$1 ; FILE=html
shift
;;
-w | --wizard ) shift
WIZARD=yes
;;
-i | --case-insensitive ) shift
WIZARD= ; CASE=-i ; FINDCASE=i
;;
-I | --image ) shift
WIZARD= ; FILE=png
;;
-l | --list ) shift
WIZARD= ; LIST=yes
;;
-h | --help ) shift
WIZARD= ; HELP=yes
;;
* ) shift
HELP=yes
;;
esac
done
## WIZARD START ##
# get product and search variables
if [ "$WIZARD" = "yes" ]; then
echo " "
printf "${RED}What is the product you want to search? Possible values are listed bellow:${NC}\n"
printf "${RED}NOTE: You can also use "*" character as a wildcard (example: "sles*" will perform a search on all sles products). The search is case insensitive${NC}\n"
echo " "
ls $HOME/Documents/www.suse.com/documentation
echo " "
echo "Product:" ; read PRODUCT
echo " "
printf "${RED}What are you searching for?${NC}\n"
echo "Search:" ; read SEARCH
echo " "
printf "${RED}RESULTS:${NC}\n"
# save url list
grep -rc $CASE --include \*.$FILE "$SEARCH" $HOME/Documents/www.suse.com/documentation/$PRODUCT/singlehtml/ |grep -v \:0 |sed -e 's/html\:/html \:/ g' > $HOME/Documents/www.suse.com/docu-search-urls-match
grep -rl $CASE --include \*.$FILE "$SEARCH" $HOME/Documents/www.suse.com/documentation/$PRODUCT/singlehtml/ > $HOME/Documents/www.suse.com/docu-search-urls
# URLNUMBER=$(cat $HOME/Documents/www.suse.com/docu-search-urls |wc -l)
# perform search and pipe it to less
grep --color=always -r $CASE --include \*.$FILE "$SEARCH" $HOME/Documents/www.suse.com/documentation/$PRODUCT/singlehtml/ |grep -v '<.*>\|^--.*' |sed "s|$HOME\/Documents\/||g" |tee $HOME/Documents/www.suse.com/docu-search-results-$DATE |less -R -F -X -I
# show report
echo " "
printf "${RED}REPORT:${NC}\n"
echo "The term '"$SEARCH"' was found on $URLNUMBER file(s):"
cat $HOME/Documents/www.suse.com/docu-search-urls-match
echo " "
echo "The search results were saved to $(ls -t $HOME/Documents/www.suse.com/docu-search-results*| head -1)"
fi
## WIZARD END ##
## HTML SEARCH START ##
# save url list
if [ "$WIZARD" = "" ] && [ "$FILE" = "html" ]; then
grep -rc $CASE --include \*.$FILE "$SEARCH" $HOME/Documents/www.suse.com/documentation/$PRODUCT/singlehtml/ |grep -v \:0 |sed -e 's/html\:/html \: /g' > $HOME/Documents/www.suse.com/docu-search-urls-match
grep -rl $CASE --include \*.$FILE "$SEARCH" $HOME/Documents/www.suse.com/documentation/$PRODUCT/singlehtml/ > $HOME/Documents/www.suse.com/docu-search-urls
URLNUMBER=$(cat $HOME/Documents/www.suse.com/docu-search-urls |wc -l)
#TEXTCONVERT=$(cat $HOME/Documents/www.suse.com/docu-search-urls |xargs -L 1 w3m -dump "$1" 2> /dev/null >> $HOME/Documents/www.suse.com/docu-search-urls-text.txt)
# perform search and pipe it to less
#grep --color=always $CASE "$SEARCH" $HOME/Documents/www.suse.com/docu-search-urls-text.txt |tee $HOME/Documents/www.suse.com/docu-search-results-$DATE |less -R -F -X -I
grep --color=always -r $CASE --include \*.$FILE "$SEARCH" $HOME/Documents/www.suse.com/documentation/$PRODUCT/singlehtml/ |grep -v '<.*>\|^--.*' |sed "s|$HOME\/Documents\/||g" |tee $HOME/Documents/www.suse.com/docu-search-results-$DATE |less -R -F -X -I
# show report
echo " "
printf "${RED}REPORT:${NC}\n"
echo "The term '"$SEARCH"' was found on $URLNUMBER file(s):"
cat $HOME/Documents/www.suse.com/docu-search-urls-match
echo " "
echo "The search results were saved to $(ls -t $HOME/Documents/www.suse.com/docu-search-results*| head -1)"
fi
## HTML SEARCH END ##
## PNG SEARCH START ##
if [ "$WIZARD" = "" ] && [ "$FILE" = "png" ]; then
# save url list
grep -rc $CASE --include \*.$FILE "$SEARCH" $HOME/Documents/www.suse.com/documentation/$PRODUCT/singlehtml/ |grep -v \:0 |sed -e 's/html\:/html \: /g' > $HOME/Documents/www.suse.com/docu-search-urls-match
find $HOME/Documents/www.suse.com/documentation/$PRODUCT/singlehtml/ -type f -"$FINDCASE"name *"$SEARCH"*.png > $HOME/Documents/www.suse.com/docu-search-urls
URLNUMBER=$(cat $HOME/Documents/www.suse.com/docu-search-urls |wc -l)
# perform search and pipe it to les
find $HOME/Documents/www.suse.com/documentation/$PRODUCT/singlehtml/ -type f -"$FINDCASE"name *"$SEARCH"*.png |sed "s|$HOME\/Documents\/||g" |tee $HOME/Documents/www.suse.com/docu-search-results-$DATE |less -R -F -X -I
# show report
echo " "
printf "${RED}REPORT:${NC}\n"
echo "The term '"$SEARCH"' was found on $URLNUMBER file(s):"
cat $HOME/Documents/www.suse.com/docu-search-urls
echo " "
echo "The search results were saved to $(ls -t $HOME/Documents/www.suse.com/docu-search-results*| head -1)"
fi
## PNG SEARCH STOP ##
## HELP START ##
if [ "$HELP" = "yes" ]; then
printf "Usage: docu-search -h or -l OR docu-search -p <product> -s <search string> (options: -i -I)"
echo "-w, --wizard = Run docu-search in interactive mode. You will be prompted to select the product and search string"
echo "-p, --product = Product that you want to search"
echo "-s, --search = Search string. If you are searching for more then one word, put all into quotes ("")"
echo "-i, --case-insensitive = Searches are case insensitive."
echo "-I, --image = Search for png files only"
echo "-l, --list = Display a list of products that you can select"
echo "-h, --help = Display a list of options to chose from"
fi
## HELP STOP ##
## LIST START ##
if [ "$LIST" = "yes" ]; then
printf "${RED}What is the product you want to search? Possible values are listed bellow:${NC}\n"
printf "${RED}NOTE: You can also use "*" character as a wildcard (example: "sles*")${NC}\n"
ls $HOME/Documents/www.suse.com/documentation
fi
## LIST STOP ##