Files
helm-charts/paperless-ngx/templates/pre-post-consumption-scripts.config-map.yaml
T

53 lines
1.3 KiB
YAML

{{- if false }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .Release.Name }}-{{ .Chart.Name }}-pre-post-consumption-scripts
data:
pre-consume-script: |-
#!/bin/sh
set -x
# Pre-Consumption Scripts:
{{- range $key, $value := .Values.paperless.scripts.preConsumptionScripts }}
/scripts/{{ $value }}
{{- end }}
post-consume-script: |-
#!/bin/sh
set -x
# Post-Consumption Scripts:
{{- range $key, $value := .Values.paperless.scripts.postConsumptionScripts }}
/scripts/{{ $value }}
{{- end }}
remove-blank-lines: |-
#!/bin/bash
set -e -o pipefail
export LC_ALL=C
#IN="$1"
IN="$DOCUMENT_WORKING_PATH"
PAGES=$(pdfinfo "$IN" | grep ^Pages: | tr -dc '0-9')
THRESHOLD=0.002
non_blank() {
for i in $(seq 1 $PAGES) ; do
PERCENT=$(gs -o - -dFirstPage=${i} -dLastPage=${i} -sDEVICE=inkcov "${IN}" | grep CMYK | nawk 'BEGIN { sum=0; } {sum += $1 + $2 + $3 + $4;} END { printf "%.5f\n", sum } ')
if awk "BEGIN { exit !($PERCENT > $THRESHOLD) }"; then
echo $i
else
>&2 echo Color-sum is $PERCENT: will remove blank page $i of $IN
fi
done
}
NON_BLANK=$(non_blank)
if [ -n "$NON_BLANK" ]; then
NON_BLANK=$(echo $NON_BLANK | tr ' ' ",")
qpdf "$IN" --replace-input --pages . $NON_BLANK --
fi
{{- end }}