1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
#!/bin/bash
# Programmable bash completion for hashcat
# this script was tested under ubuntu, please verify if on your
# distro /etc/bash_completion.d/ exists (otherwise it won't work)
COMPGENSCRIPT=/etc/bash_completion
COMPGENFOLDER=${COMPGENSCRIPT}.d
COMPGENTARGET=${COMPGENFOLDER}/hashcat.sh
BASHRC=~/.bashrc
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
#############################################################################
is_sourced ()
{
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
SOURCED=0
else
SOURCED=1
fi
return ${SOURCED}
}
source_completion ()
{
# load the completion into current shell
if [ "${is_child}" -eq 1 ]; then
if [ "${parent_sourced}" -eq 0 ]; then
return 1
fi
fi
if [ "${was_sourced}" -eq 0 ]; then
source "${COMPGENTARGET}"
# or
#source ${BASHRC}
return 1
fi
return 0
}
my_exit ()
{
if [ "${was_sourced}" -eq 0 ]; then
return $1
else
exit $1
fi
}
is_root ()
{
if [ "$(id -g)" -eq 0 ]; then
return 0
else
return 1
fi
}
#############################################################################
is_sourced
was_sourced=${?}
ROOT_PARENT="$(cd ${ROOT}/.. && pwd)"
# Check (install) permissions
parent_sourced=0
is_child=0
if ! is_root; then
echo "Warning: root permissions are required to install the tab completion script into the protected '${COMPGENFOLDER}' folder"
sudo ${BASH_SOURCE[0]} ${was_sourced}
ret=${?}
if [ "${ret}" -eq 0 ]; then
source_completion
fi
my_exit ${ret}
return ${?}
fi
if [ -n "${1}" ]
then
parent_sourced=${1}
is_child=1
fi
if [ -f "${COMPGENFOLDER}" ]
then
echo "The bash completion script file (${COMPGENSCRIPT}) could not be found"
echo "Please make sure that the distro 'bash-completion' package is installed (apt-get install it otherwise). EXIT"
my_exit 1
return ${?}
fi
if [ -d "${COMPGENFOLDER}" ]; then
# remove the old version of hashcat64.sh (was renamed to just hashcat.sh)
rm -f "${COMPGENTARGET}"/hashcat64.sh
# copy the script to target folder
cp ${ROOT}/hashcat.sh "${COMPGENTARGET}"
# adjust paths to the main binaries of hashcat
sed -ri 's!^(HASHCAT_ROOT=).*!\1\"${ROOT_PARENT}\"!' "${COMPGENTARGET}"
# add the compgen to bashrc if not already there
if ! egrep -q "^[^#]*\. *${COMPGENSCRIPT}" "${BASHRC}"; then
cat >> "${BASHRC}" << EOF
if [ -f "${COMPGENSCRIPT}" ]; then
. ${COMPGENSCRIPT}
fi
EOF
fi
if source_completion; then
echo "Bash completion scripts for hashcat were successfully installed, but since you didn't 'source' this file, you need to run:"
echo "source ${COMPGENTARGET} # or source ${BASHRC}"
echo
echo "in order to be able to use the tab completion within the current shell."
fi
else
echo "The compgen script folder (${COMPGENFOLDER}) could NOT be found. EXIT"
my_exit 1
return ${?}
fi
my_exit 0
return ${?}
|