X-Git-Url: https://git.rmz.io/dotfiles.git/blobdiff_plain/04fed8e4657d28df3ca947ea34c2a5d8f9ccc02f..61d7dd11d4a450a64f2817ee4db0ec7fa5880b42:/bin/crack_pdf diff --git a/bin/crack_pdf b/bin/crack_pdf new file mode 100755 index 0000000..21be931 --- /dev/null +++ b/bin/crack_pdf @@ -0,0 +1,62 @@ +#! /bin/bash +usage() +{ +cat << EOF +usage $0 options + +This script will decrypt any pdf given to it. The correct password has to be passed. + +REQUIRES qpdf + +OPTIONS: + -h Shows this message + -p The password to be used + -v Verbose output +EOF +} + +# checks if 'qpdf' is installed +type -P qpdf &>/dev/null || { echo "I require qpdf but it's not installed. Aborting." >&2; exit 1; } + +PWD= + +while getopts "hp:v" OPT; do + case $OPT in + h) + usage + exit EXIT_SUCCESS + ;; + p) + PWD=$OPTARG + ;; + v) + VERBOSE=1 + ;; + ?) + usage + exit + ;; + esac + shift $((OPTIND-1)) +done + +ARGS=$@ +if [[ -z $ARGS ]] || [[ -z $PWD ]] || ! type -P qpdf &> /dev/null; then + usage + exit +fi + +shopt -s nullglob # w/o this '*.pdf' will return the string if no pdfs are in the folder +for DST in $ARGS; do + if [[ -d $DST ]]; then + for F in $DST/*.pdf; do + [[ $VERBOSE ]] && echo $F + mv $F tmp.pdf + qpdf --password=$PWD --decrypt $F ${F%.pdf}_.pdf || echo "error" + + done + elif [[ ${DST##*.} = "pdf" ]] && [[ -f $DST ]]; then + [[ $VERBOSE ]] && echo $DST + qpdf --password=$PWD --decrypt $DST ${DST%.pdf}_.pdf + fi +done