Switch update to function

This commit is contained in:
g0tmi1k 2015-07-08 21:38:52 +01:00
parent 32edeb4342
commit 60391041b9

View file

@ -1,11 +1,12 @@
#!/bin/bash #!/bin/bash
# Name: searchsploit - Exploit-DB's CLI search tool # Name: searchsploit - Exploit-DB's CLI search tool
# Version: 3.1 (Release date: 2015-06-11) # Version: 3.1 (Release date: 2015-07-08)
# Written by: Offensive Security, Unix-Ninja & g0tmi1k # Written by: Offensive Security, Unix-Ninja & g0tmi1k
# Homepage: https://github.com/offensive-security/exploit-database # Homepage: https://github.com/offensive-security/exploit-database
## NOTE: ## NOTE:
# Exit code '0' means finished normally # Exit code '0' means finished normally
# Exit code '1' means finished help screen
# Exit code '6' means updated from GitHub # Exit code '6' means updated from GitHub
@ -20,7 +21,6 @@ progname="$( basename "$0" )"
## Default options ## Default options
TAGS="" TAGS=""
SCASE="tolower" SCASE="tolower"
UPDATE=0
VERBOSE=0 VERBOSE=0
WEBLINK=0 WEBLINK=0
EDBID=0 EDBID=0
@ -67,6 +67,39 @@ function usage()
exit 1 exit 1
} }
## Update database (via GIT)
function update()
{
cd "${gitpath}/"
# Make sure a git repo is init before updating
if [[ "$( git rev-parse --is-inside-work-tree )" != "true" ]]; then
if [[ "$( ls )" = "" ]]; then
# If directory is empty, just clone
git clone "${gitremote}" .
else
# If not empty, init and add remote
git init >/dev/null
git remote add origin "${gitremote}"
fi
fi
# Make sure to prep checkout first
git checkout -- .
# Update from git
git pull origin master
# If conflicts, clean and try again
if [[ "$?" -ne 0 ]]; then
git clean -d -fx ""
git pull origin master
fi
echo "[*] Update finished."
exit 6
}
## Printing dotted lines in the correct manner ## Printing dotted lines in the correct manner
function drawline() function drawline()
@ -74,7 +107,7 @@ function drawline()
printf "%0.s-" $( eval echo {1..$(( COL1 + 1 ))} ) printf "%0.s-" $( eval echo {1..$(( COL1 + 1 ))} )
echo -n " " echo -n " "
printf "%0.s-" $( eval echo {1..$(( COL2 - 1 ))} ) printf "%0.s-" $( eval echo {1..$(( COL2 - 1 ))} )
echo echo ""
} }
@ -94,7 +127,7 @@ for param in "$@"; do
elif [[ "${param}" == "--title" ]]; then elif [[ "${param}" == "--title" ]]; then
FILEPATH=0 FILEPATH=0
elif [[ "${param}" == "--update" ]]; then elif [[ "${param}" == "--update" ]]; then
UPDATE=1 update
elif [[ "${param}" == "--www" ]]; then elif [[ "${param}" == "--www" ]]; then
WEBLINK=1 WEBLINK=1
elif [[ "${param}" == "--verbose" ]]; then elif [[ "${param}" == "--verbose" ]]; then
@ -115,7 +148,7 @@ done
## Parse short arguments ## Parse short arguments
while getopts "uchvwf" arg "${ARGS}"; do while getopts "chtuvw" arg "${ARGS}"; do
if [[ "${arg}" = "?" ]]; then if [[ "${arg}" = "?" ]]; then
usage >&2; usage >&2;
fi fi
@ -123,47 +156,14 @@ while getopts "uchvwf" arg "${ARGS}"; do
c) SCASE='';; c) SCASE='';;
h) usage >&2;; h) usage >&2;;
t) FILEPATH=0;; t) FILEPATH=0;;
u) UPDATE=1;; u) update;;
v) VERBOSE=1;; v) VERBOSE=1;;
w) WEBLINK=1;;y w) WEBLINK=1;;
esac esac
shift $(( OPTIND - 1 )) shift $(( OPTIND - 1 ))
done done
## Was an update requested?
if [[ "${UPDATE}" -eq 1 ]]; then
cd "${gitpath}/"
# Make sure a git repo is init before updating
if [[ "$( git rev-parse --is-inside-work-tree )" != "true" ]]; then
if [[ "$( ls )" = "" ]]; then
# If directory is empty, just clone
git clone "${gitremote}" .
else
# If not empty, init and add remote
git init > /dev/null
git remote add origin "${gitremote}"
fi
fi
# Make sure to prep checkout first
git checkout -- .
# Update from git
git pull origin master
# If conflicts, clean and try again
if [[ "$?" -ne 0 ]]; then
git clean -d -fx ""
git pull origin master
fi
echo "[*] Update finished."
exit 6
fi
## Dynamically set column widths ## Dynamically set column widths
if [[ "${WEBLINK}" -eq '1' ]]; then if [[ "${WEBLINK}" -eq '1' ]]; then
COL2=45 COL2=45
@ -262,4 +262,3 @@ drawline
## Done ## Done
exit 0 exit 0