diff --git a/searchsploit b/searchsploit index ffe0ffc55..6ca7ea34a 100755 --- a/searchsploit +++ b/searchsploit @@ -1,11 +1,12 @@ #!/bin/bash # 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 # Homepage: https://github.com/offensive-security/exploit-database ## NOTE: # Exit code '0' means finished normally +# Exit code '1' means finished help screen # Exit code '6' means updated from GitHub @@ -20,7 +21,6 @@ progname="$( basename "$0" )" ## Default options TAGS="" SCASE="tolower" -UPDATE=0 VERBOSE=0 WEBLINK=0 EDBID=0 @@ -67,6 +67,39 @@ function usage() 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 function drawline() @@ -74,7 +107,7 @@ function drawline() printf "%0.s-" $( eval echo {1..$(( COL1 + 1 ))} ) echo -n " " printf "%0.s-" $( eval echo {1..$(( COL2 - 1 ))} ) - echo + echo "" } @@ -94,7 +127,7 @@ for param in "$@"; do elif [[ "${param}" == "--title" ]]; then FILEPATH=0 elif [[ "${param}" == "--update" ]]; then - UPDATE=1 + update elif [[ "${param}" == "--www" ]]; then WEBLINK=1 elif [[ "${param}" == "--verbose" ]]; then @@ -115,7 +148,7 @@ done ## Parse short arguments -while getopts "uchvwf" arg "${ARGS}"; do +while getopts "chtuvw" arg "${ARGS}"; do if [[ "${arg}" = "?" ]]; then usage >&2; fi @@ -123,47 +156,14 @@ while getopts "uchvwf" arg "${ARGS}"; do c) SCASE='';; h) usage >&2;; t) FILEPATH=0;; - u) UPDATE=1;; + u) update;; v) VERBOSE=1;; - w) WEBLINK=1;;y + w) WEBLINK=1;; esac shift $(( OPTIND - 1 )) 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 if [[ "${WEBLINK}" -eq '1' ]]; then COL2=45 @@ -262,4 +262,3 @@ drawline ## Done exit 0 -