From 04769a174f026dca2dc4c40df5ef14b1f0650b30 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Fri, 19 Feb 2021 01:02:25 +0100 Subject: [PATCH 1/8] Add ShellCheck linter --- .drone.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .drone.yml diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..cd7ffcc --- /dev/null +++ b/.drone.yml @@ -0,0 +1,10 @@ +--- +kind: pipeline +type: docker +name: lint + +steps: + - name: ShellCheck + image: koalaman/shellcheck-alpine:0.7.1 + commands: shellcheck pdf-optimize +... -- 2.45.2 From 3cce1bd1ac8b7d5ddbec61f47bfddf0449dbef74 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Fri, 19 Feb 2021 01:04:21 +0100 Subject: [PATCH 2/8] Add linter badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 97e72f5..8f7754a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # pdf-optimize +[![Build Status](https://drone.auro.re/api/badges/otthorn/pdf-optimize/status.svg)](https://drone.auro.re/otthorn/pdf-optimize) pdf-optimize is a simple script to optimize pdf using ghostscript. You need to have ghoscript installed on your machine. -- 2.45.2 From 915ccd5a0a5da35a435bab0dafe3a26f54f26d7d Mon Sep 17 00:00:00 2001 From: Otthorn Date: Fri, 19 Feb 2021 01:06:02 +0100 Subject: [PATCH 3/8] fix drone --- .drone.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index cd7ffcc..8f38e53 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,5 +6,6 @@ name: lint steps: - name: ShellCheck image: koalaman/shellcheck-alpine:0.7.1 - commands: shellcheck pdf-optimize + commands: + - shellcheck pdf-optimize ... -- 2.45.2 From 8630959003553c46ad1eb1cfd6f418667b0598b4 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Fri, 19 Feb 2021 01:07:31 +0100 Subject: [PATCH 4/8] Correct the version number --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 8f38e53..797c3d2 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ name: lint steps: - name: ShellCheck - image: koalaman/shellcheck-alpine:0.7.1 + image: koalaman/shellcheck-alpine:v0.7.1 commands: - shellcheck pdf-optimize ... -- 2.45.2 From 9a33c847a0e81058530fa4f1c4b93c6c4de662cb Mon Sep 17 00:00:00 2001 From: Otthorn Date: Fri, 19 Feb 2021 01:10:45 +0100 Subject: [PATCH 5/8] [lint] FIX SC162: use read -r --- pdf-optimize | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdf-optimize b/pdf-optimize index d2bd9b5..ad9df3b 100755 --- a/pdf-optimize +++ b/pdf-optimize @@ -78,7 +78,7 @@ function arg_parse function yes_or_no { - read -p "$* [y/N]: " ans + read -pr "$* [y/N]: " ans case "$ans" in [yY] | [yY]es ) return 0;; * ) echo "Aborting"; return 1;; -- 2.45.2 From e6f5a587e472615a57fd7d8efeffee5aecfba4c0 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Fri, 19 Feb 2021 01:11:48 +0100 Subject: [PATCH 6/8] [lint] FIX SC2006: use --- pdf-optimize | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pdf-optimize b/pdf-optimize index ad9df3b..0d72042 100755 --- a/pdf-optimize +++ b/pdf-optimize @@ -136,11 +136,11 @@ ${bold}$output_path${normal}." function compute_compression { - input_size=`du "$input_path" | cut -f1` - output_size=`du "$output_path" | cut -f1` - percentage=`echo "scale=1;$output_size / $input_size * 100" | bc -l` - input_size_h=`du -h "$input_path" | cut -f1` - output_size_h=`du -h "$output_path" | cut -f1` + input_size=$(du "$input_path" | cut -f1) + output_size=$(du "$output_path" | cut -f1) + percentage=$(echo "scale=1;$output_size / $input_size * 100" | bc -l) + input_size_h=$(du -h "$input_path" | cut -f1) + output_size_h=$(du -h "$output_path" | cut -f1) echo "Size reduced from ${bold}$input_size_h${normal} to \ ${bold}$output_size_h${normal} [$percentage %]" -- 2.45.2 From f6bc246ff288c1c5243920d4f27c4ff84118e12d Mon Sep 17 00:00:00 2001 From: Otthorn Date: Fri, 19 Feb 2021 01:13:20 +0100 Subject: [PATCH 7/8] [lint] FIX SC2086: use double quotes on vars --- pdf-optimize | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pdf-optimize b/pdf-optimize index 0d72042..ee94899 100755 --- a/pdf-optimize +++ b/pdf-optimize @@ -103,8 +103,8 @@ ${bold}$output_path${normal}." -dNOPAUSE \ -dQUIET \ -dBATCH \ - -sOutputFile=$output_path \ - $input_path + -sOutputFile="$output_path" \ + "$input_path" else echo "input_path=$input_path"; echo "output_path=$output_path"; @@ -117,8 +117,8 @@ ${bold}$output_path${normal}." -dPDFSETTINGS=/prepress \ -dNOPAUSE \ -dBATCH \ - -sOutputFile=$output_path \ - $input_path + -sOutputFile="$output_path" \ + "$input_path" fi # catching errors -- 2.45.2 From f5b6f44f798a1e829d0ebffffb6e55a87d2d3f11 Mon Sep 17 00:00:00 2001 From: Otthorn Date: Fri, 19 Feb 2021 01:19:26 +0100 Subject: [PATCH 8/8] [lint] skip error SC2181 --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 797c3d2..d95d49d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,5 +7,5 @@ steps: - name: ShellCheck image: koalaman/shellcheck-alpine:v0.7.1 commands: - - shellcheck pdf-optimize + - shellcheck -e SC2181 pdf-optimize ... -- 2.45.2