Skip to content

Commit

Permalink
Merge pull request #13 from cytopia/release-0.7
Browse files Browse the repository at this point in the history
Release 0.7
  • Loading branch information
cytopia authored Nov 3, 2018
2 parents 75ab4c6 + 22c612d commit 5c3b0dc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ help:
@printf "%s\n" "make help Show help"

test:
./linkcheck -r 10 -t 30 tests/
./linkcheck -r 10 -t 30 tests/urls_valid_4.txt
./linkcheck -r 10 -t 30 tests/urls_valid_4.txt | grep -c '[ok]'

lint:
shellcheck --shell=bash linkcheck
26 changes: 22 additions & 4 deletions linkcheck
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ RETRIES=3
STATUS_CODES=200


###
### Allow insecure SSL connections if chosen
### This is exactly: curl -k
###
INSECURE_SSL=""


############################################################
# Fixed global variables
############################################################
Expand All @@ -57,7 +64,7 @@ STATUS_CODES=200
###
URL_REGEX="http(s)?:\\/\\/[-+%=?&():,._/#0-9a-zA-Z]+"

MY_VERSION="v0.6"
MY_VERSION="v0.7"


############################################################
Expand All @@ -68,7 +75,7 @@ MY_VERSION="v0.6"
### Usage
###
print_usage() {
echo "Usage: linkcheck [-e -i -t -r -c] [<path>]"
echo "Usage: linkcheck [-e -i -t -r -c -k] [<path>]"
echo " linkcheck --version"
echo " linkcheck --help"
echo
Expand Down Expand Up @@ -107,6 +114,9 @@ print_usage() {
echo " -c '200,301'"
echo " -c '200,301,302'"
echo
echo "-k Ignore invalid SSL certificates for HTTPS connections."
echo " Defaults to error on invalid SSL certificates."
echo " This is just a single flag with no other arguments."
echo
echo "--version Show version and exit."
echo "--help Show this help screen."
Expand Down Expand Up @@ -144,7 +154,7 @@ setval() {
###
sanitize_url() {
local url="${1}"
local invalid="[,.!\)]$"
local invalid="[,.!\\)]\$"

# Remove any trailing garbage
while [[ ${url} =~ ${invalid} ]]; do
Expand Down Expand Up @@ -198,6 +208,7 @@ probe_urls() {
local timeout="${2}"
local retries="${3}"
local status_codes="${4}"
local insecure_ssl="${5}"
local ret_code=0

status_codes="${status_codes//,/|}" # comma to |
Expand All @@ -216,6 +227,7 @@ probe_urls() {
--retry-delay 2 \
--retry "${retries}" \
--connect-timeout "${timeout}" \
"${insecure_ssl}" \
"${url}" 2> >(setval errval) > >(setval header); <<<"$?" setval retval;
)"

Expand Down Expand Up @@ -306,6 +318,12 @@ while [ $# -gt 0 ]; do
fi
;;

# ----------------------------------------
-k)
shift
INSECURE_SSL="-k"
;;

# ----------------------------------------
--help)
print_usage
Expand Down Expand Up @@ -337,4 +355,4 @@ done

MY_URLS="$( gather_urls "${SEARCH_PATH}" "${EXTENSIONS}" "${URL_REGEX}" "${URL_REGEX_EXCLUDE}" )"

probe_urls "${MY_URLS}" "${TIMEOUT}" "${RETRIES}" "${STATUS_CODES}"
probe_urls "${MY_URLS}" "${TIMEOUT}" "${RETRIES}" "${STATUS_CODES}" "${INSECURE_SSL}"
1 change: 0 additions & 1 deletion tests/urls.txt → tests/urls_valid_4.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Plain URLs
https://nierautomata.wiki.fextralife.com/Locked+Chests
https://www.baka-tsuki.org/project/?title=Ore_no_Im%C5%8Dto_ga_Konna_ni_Kawaii_Wake_ga_Nai
https://www.phoronix.com/scan.php?page=news_item&px=U2-NVMe-PCI-E-SSD-Adapter
https://en.wikipedia.org/w/index.php?title=Erlang_(programming_language)&diff=847224766&oldid=847107459
Expand Down

0 comments on commit 5c3b0dc

Please sign in to comment.