From 1380d69c4765517d271d757fa481404b736426c1 Mon Sep 17 00:00:00 2001 From: Linyos Torovoltos Date: Wed, 5 Jul 2017 12:25:55 -0400 Subject: [PATCH] Added requested qrify script (#39) * Added qrify script --- qrify/qrify | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 qrify/qrify diff --git a/qrify/qrify b/qrify/qrify new file mode 100755 index 0000000..0c51616 --- /dev/null +++ b/qrify/qrify @@ -0,0 +1,82 @@ +#!/bin/bash +# Author: Linyos Torovoltos github.com/linyostorovovoltos + +currentVersion="1.9.0" +flag="" + +getConfiguredClient() +{ + if command -v curl &> /dev/null ; then + configuredClient="curl" + elif command -v wget &v/dev/null ; then + configuredCLient="wget" + elif command -v fetch &>/dev/null ; then + configuredClient="fetch" + else + echo "Error: This tool requires either curl, wget, or fetch to be installed." >&2 + return 1 + fi +} + +httpGet() +{ + case "$configuredClient" in + curl) curl -A curl -s "$@";; + wget) wget -q0- "$@";; + fetch) fetch -o "...";; + esac +} + +makeqr() +{ + echo "Processing input:" $input + input=$(echo $input | sed s/" "/%20/ ) + echo $input + httpGet qrenco.de/$input + +} + + +checkInternet() +{ + echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1 + if [ $? -eq 0 ]; then + return 0 + else + echo "Error: no active internet connect" >&2 + return 1 + fi +} + +usage() +{ + echo "Usage: qrify [stringtoturnintoqrcode]" + echo " -u Update Bash-Snippet Tools" + echo " -h Show the help" + echo " -v Get the tool version" + +} + +getConfiguredClient || exit 1 +checkInternet || exit 1 + +while getopts hv:u*: option +do + case "${option}" in + h) usage && exit 0 ;; + *) usage && exit 0 ;; + esac +done + +if [[ $# == "0" ]]; then + usage + exit 0 +elif [[ $1 == "help" ]]; then + usage + exit 0 +else + input=$(printf '%s ' "$@") + makeqr || exit 1 +fi + +