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