I think using functions and embedding them in .bash_profile
puts a lot of pressure on the environment space. Why not to use plain shell scripts? It would be as easy to install and be made globally available as:
$ find ./ -type f -name 'bh_*' -exec cp "{}" /usr/local/bin/ \;
Due to bh_
prefix, this cannot give us any problems with colliding filenames (since 'bh_' can be seen as a namespace). And I would get rid of .sh
filename extension as well...
Take a look at a modified version of bh_hashcrack
, for instance (of course, there is a minor problem here if wget fails).
#!/bin/bash
# vim: set ts=2 sw=2 et:
# NOTICE: I'm using ANSI to colorize some messages.
# We need a single parameter for this script. Ignore the rest, if any.
if [ -z "${1}" ]
then
echo -e "\e[33;1mUsage\e[0m: bh_hashcrack <hash>\n"
exit 1
fi
# If it isn't an hexadecimal string...
if [ ! -z "$(sed -n '/[^0-9A-Fa-f]/p' <<< "${1}")" ]
then
echo -e "\e[31;1mERROR\e[0m: Invalid hash format."
exit 1
fi
BH_SITE="http://hashtoolkit.com/reverse-hash/?hash=${1}"
# FIXME: Is this the best method?
BH_DATA="$(wget -qO - "${BH_SITE}")"
# if wget didn't fail, this substring is present on the result string!
if grep -qF 'No hashes found' <<< "${BH_DATA}"
then
echo -e "\e[31;1mERROR\e[0m: No hashes found."
exit 1
fi
BH_RES=$(echo "${BH_DATA}" \
| grep -FA1 'res-text' \
| sed -n 's/^.*<span>\(.*\)<\/span>.*$/\1/p')
if [ "${BH_RES}" != "${1}" ]
then
echo -e "\e[33;1mFound\e[0m:"
echo "${BH_RES}" | sort -u
fi
Notice the renaming of 'local' vars, now uppercase and prefixed with BH_. "Local" because they are not exported.
PS: Of course, if multiple hashes could be used as arguments, we can, always, use a loop with $@ var.
PS2: It should be clear that I don't like some bash/shell scripts shortcuts as well... :)
[]s
Fred