Skip to content

Commit

Permalink
Fix the issues reported by the latest shellcheck version
Browse files Browse the repository at this point in the history
  • Loading branch information
na-- committed Nov 16, 2017
1 parent 3e09f59 commit a013456
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
2 changes: 1 addition & 1 deletion convert-to-txt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tesseract_wrapper () {

for arg in "$@"; do
case $arg in
-*|--*) handle_script_arg "$arg" ;;
-*) handle_script_arg "$arg" ;;
*) break ;;
esac
shift # past argument=value or argument with no value
Expand Down
2 changes: 1 addition & 1 deletion find-isbns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set -eEuo pipefail
for arg in "$@"; do
case $arg in
-irs=*|--isbn-return-separator=*) ISBN_RET_SEPARATOR="${arg#*=}" ;;
-*|--*) handle_script_arg "$arg" ;;
-*) handle_script_arg "$arg" ;;
*) break ;;
esac
shift # past argument=value or argument with no value
Expand Down
2 changes: 1 addition & 1 deletion interactive-organizer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ for arg in "$@"; do
-ddm=*|--diacritic-difference-masking=*) DIACRITIC_DIFFERENCE_MASKINGS+=("${arg#*=}") ;;
-mpw|--match-partial-words) MATCH_PARTIAL_WORDS=true ;;
-h|--help) print_help; exit 1 ;;
-*|--*) handle_script_arg "$arg" ;;
-*) handle_script_arg "$arg" ;;
*) break ;;
esac
shift # past argument=value or argument with no value
Expand Down
38 changes: 21 additions & 17 deletions lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ err_trap_handler() {
}
trap err_trap_handler ERR

VERSION="0.4" #shellcheck disable=SC2034

GREEN='\033[0;32m' #shellcheck disable=SC2034
RED='\033[0;31m' #shellcheck disable=SC2034
BOLD='\033[1m' #shellcheck disable=SC2034
NC='\033[0m' #shellcheck disable=SC2034
#shellcheck disable=SC2034
VERSION="0.4"
#shellcheck disable=SC2034
GREEN='\033[0;32m'
#shellcheck disable=SC2034
RED='\033[0;31m'
#shellcheck disable=SC2034
BOLD='\033[1m'
#shellcheck disable=SC2034
NC='\033[0m'

: "${VERBOSE:=false}"
: "${DRY_RUN:=false}"
Expand Down Expand Up @@ -72,14 +76,14 @@ NC='\033[0m' #shellcheck disable=SC2034
: "${RE_YEAR:="(19[0-9]|20[0-$(date '+%Y' | cut -b 3)])[0-9]"}"
: "${WITHOUT_ISBN_IGNORE:=$(echo "
# Perdiodicals with filenames that contain something like 2010-11, 199010, 2015_7, 20110203:
(^|[^0-9])${RE_YEAR}[ _\.-]*(0?[1-9]|10|11|12)([0-9][0-9])?(\$|[^0-9])
(^|[^0-9])${RE_YEAR}[ _\\.-]*(0?[1-9]|10|11|12)([0-9][0-9])?(\$|[^0-9])
# Periodicals with month numbers before the year
|(^|[^0-9])([0-9][0-9])?(0?[1-9]|10|11|12)[ _\.-]*${RE_YEAR}(\$|[^0-9])
|(^|[^0-9])([0-9][0-9])?(0?[1-9]|10|11|12)[ _\\.-]*${RE_YEAR}(\$|[^0-9])
# Periodicals with months or issues
|((^|[^a-z])(jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|june?|july?|aug(ust)?|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?|mag(azine)?|issue|#[ _\.-]*[0-9]+)+(\$|[^a-z]))
|((^|[^a-z])(jan(uary)?|feb(ruary)?|mar(ch)?|apr(il)?|may|june?|july?|aug(ust)?|sep(tember)?|oct(ober)?|nov(ember)?|dec(ember)?|mag(azine)?|issue|#[ _\\.-]*[0-9]+)+(\$|[^a-z]))
# Periodicals with seasons and years
|((spr(ing)?|sum(mer)?|aut(umn)?|win(ter)?|fall)[ _\.-]*${RE_YEAR})
|(${RE_YEAR}[ _\.-]*(spr(ing)?|sum(mer)?|aut(umn)?|win(ter)?|fall))
|((spr(ing)?|sum(mer)?|aut(umn)?|win(ter)?|fall)[ _\\.-]*${RE_YEAR})
|(${RE_YEAR}[ _\\.-]*(spr(ing)?|sum(mer)?|aut(umn)?|win(ter)?|fall))
" | grep -v '^#' | tr -d '\n')}"


Expand Down Expand Up @@ -127,7 +131,7 @@ handle_script_arg() {
-mfo=*|--metadata-fetch-order=*) ISBN_METADATA_FETCH_ORDER="${arg#*=}" ;;
-owis=*|--organize-without-isbn-sources=*) ORGANIZE_WITHOUT_ISBN_SOURCES="${arg#*=}" ;;
-wii=*|--without-isbn-ignore=*) WITHOUT_ISBN_IGNORE="${arg#*=}" ;;
-fsf=*|--file-sort-flags=*) FILE_SORT_FLAGS=(${arg#*=}) ;;
-fsf=*|--file-sort-flags=*) IFS=" " read -r -a FILE_SORT_FLAGS <<< "${arg#*=}" ;;

-oft=*|--output-filename-template=*) OUTPUT_FILENAME_TEMPLATE="${arg#*=}" ;;
-ome=*|--output-metadata-extension=*) OUTPUT_METADATA_EXTENSION="${arg#*=}" ;;
Expand Down Expand Up @@ -219,18 +223,18 @@ is_isbn_valid() {
if [[ "$i" == "9" && "$number" == "X" ]]; then
number=10
fi
let "sum = $sum + ($number * ( 10 - $i ))"
(( sum = sum + (number * ( 10 - i )) ))
done
if [ "$((sum % 11))" == "0" ]; then
return 0
fi
elif [ "${#isbn}" == "13" ]; then
if [[ "${isbn:0:3}" = "978" || "${isbn:0:3}" = "979" ]]; then
for i in {0..12..2}; do
let "sum = $sum + ${isbn:$i:1}"
(( sum = sum + ${isbn:$i:1} ))
done
for i in {1..11..2}; do
let "sum = $sum + (${isbn:$i:1} * 3)"
(( sum = sum + (${isbn:$i:1} * 3) ))
done
if [ "$((sum % 10))" == "0" ]; then
return 0
Expand Down Expand Up @@ -365,7 +369,7 @@ check_file_for_corruption() {
else
decho "pdfinfo returned successfully"
echo "$pdfinfo_output" | debug_prefixer "[pdfinfo] " 0 --width=80 -t
if echo "$pdfinfo_output" | grep --quiet -E "^Page size:\s*0 x 0 pts$"; then
if echo "$pdfinfo_output" | grep --quiet -E '^Page size:\s*0 x 0 pts$'; then
decho "pdf is corrupt anyway, page size property is empty!"
echo "pdf can be parsed, but page size is 0 x 0 pts!"
fi
Expand Down Expand Up @@ -428,7 +432,7 @@ ocr_file() {

case "$mimetype" in
application/pdf)
num_pages=$(pdfinfo "$if" | sed -n -E "s/^Pages:\s+([0-9]+)/\1/p")
num_pages=$(pdfinfo "$if" | sed -n -E 's/^Pages:\s+([0-9]+)/\1/p')
page_convert_cmd=convert_pdf_page
;;
image/vnd.djvu*)
Expand Down
10 changes: 5 additions & 5 deletions organize-ebooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ for arg in "$@"; do
--pamphlet-max-filesize-kb=*) PAMPHLET_MAX_FILESIZE_KB="${arg#*=}" ;;

-h|--help) print_help; exit 1 ;;
-*|--*) handle_script_arg "$arg" ;;
-*) handle_script_arg "$arg" ;;
*) break ;;
esac
shift # past argument=value or argument with no value
Expand All @@ -52,15 +52,15 @@ if [[ "$#" == "0" ]]; then print_help; exit 2; fi


fail_file() {
echo -e "${RED}ERR${NC}:\t$1\nREASON:\t$2\n${3+TO:\t$3\n}"
echo -e "${RED}ERR${NC}:\\t$1\\nREASON:\\t$2\\n${3+TO:\\t$3\\n}"
}

ok_file() {
echo -e "${GREEN}OK${NC}:\t${1}\nTO:\t${2}\n"
echo -e "${GREEN}OK${NC}:\\t${1}\\nTO:\\t${2}\\n"
}

skip_file() {
echo -e "SKIP:\t$1\nREASON:\t$2\n"
echo -e "SKIP:\\t$1\\nREASON:\\t$2\\n"
}

# Arguments: path
Expand All @@ -87,7 +87,7 @@ is_pamphlet() {
filesize_kb=$(( $(stat -c '%s' "$file_path") / 1024 ))
if [[ "$mimetype" == "application/pdf" ]]; then
decho "The file looks like a pdf, checking if the number of pages is larger than $PAMPHLET_MAX_PDF_PAGES ..."
pages=$(pdfinfo "$file_path" | sed -n -E "s/^Pages:\s+([0-9]+)/\1/p")
pages=$(pdfinfo "$file_path" | sed -n -E 's/^Pages:\s+([0-9]+)/\1/p')

if (( pages > PAMPHLET_MAX_PDF_PAGES )); then
decho "The file has $pages pages, too many for a pamphlet"
Expand Down
2 changes: 1 addition & 1 deletion rename-calibre-library.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ for arg in "$@"; do
case $arg in
-o=*|--output-folder=*) OUTPUT_FOLDER="${arg#*=}" ;;
-sm=*|--save-metadata=*) SAVE_METADATA="${arg#*=}" ;;
-*|--*) handle_script_arg "$arg" ;;
-*) handle_script_arg "$arg" ;;
*) break ;;
esac
shift # past argument=value or argument with no value
Expand Down
2 changes: 1 addition & 1 deletion split-into-folders.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ for arg in "$@"; do
-sn=*|--start-number=*) START_NUMBER="${arg#*=}" ;;
-fp=*|--folder-pattern=*) FOLDER_PATTERN="${arg#*=}" ;;
-fpf=*|--files-per-folder=*) FILES_PER_FOLDER="${arg#*=}" ;;
-*|--*) handle_script_arg "$arg" ;;
-*) handle_script_arg "$arg" ;;
*) break ;;
esac
shift # past argument=value or argument with no value
Expand Down

0 comments on commit a013456

Please sign in to comment.