about summary refs log tree commit diff stats
path: root/home-manager/packages/scripts/apps/con2pdf
diff options
context:
space:
mode:
authorene <ene@sils.li>2023-02-25 07:54:37 +0100
committerene <ene@sils.li>2023-02-25 07:54:37 +0100
commit06696ca201682f63ea50da3ab41d992ed6b61816 (patch)
tree93152237a2e968cd433d1ca21671dcba52e772b8 /home-manager/packages/scripts/apps/con2pdf
parentFix(hosts): Update UUIDs for mammun hosts (diff)
downloadnixos-config-06696ca201682f63ea50da3ab41d992ed6b61816.tar.gz
nixos-config-06696ca201682f63ea50da3ab41d992ed6b61816.zip
Feat(packages): Add my scripts
Diffstat (limited to '')
-rwxr-xr-xhome-manager/packages/scripts/apps/con2pdf101
1 files changed, 101 insertions, 0 deletions
diff --git a/home-manager/packages/scripts/apps/con2pdf b/home-manager/packages/scripts/apps/con2pdf
new file mode 100755
index 00000000..7d23fe82
--- /dev/null
+++ b/home-manager/packages/scripts/apps/con2pdf
@@ -0,0 +1,101 @@
+#! /bin/sh
+# shellcheck disable=SC2086
+# shellcheck source=/dev/null
+. ~/.local/lib/shell/lib
+
+
+# Vars
+counter=0;
+a_set=false;
+pw=$(pwd)
+
+usage() {
+    cat << EOF
+    This is a help doc!
+    -p for path
+    -h for help
+    -n for name
+    -g gen pdf dir
+    -r for number of pages per pdf
+EOF
+exit 0;
+}
+
+# Ops
+while getopts ":hp:n:gr:" flag;do
+    case "$flag" in
+        p)
+            Command_path=$OPTARG
+            ;;
+        n)
+            name=$OPTARG
+            ;;
+        g)
+            gen=true
+            ;;
+        r)
+            pages=$OPTARG
+            ;;
+        h)
+            usage;;
+        *)
+            usage;;
+
+        esac
+    done
+[ -z "$pages" ] && die "No pages set"
+
+
+# Scan
+if [ -z $Command_path ];then
+    tm=$(mktemp -d)
+    cd $tm || die "Bug"
+
+    for i in $(seq $pages);do
+        scanimage --format=tiff --progress \
+            --source ADF --device="airscan:w1:Brother DCP-9022CDW" \
+            --batch=%d.tif --batch-increment=$pages --batch-start=$i
+        [ $? -ne 0 ] && scanimage --format=tiff --progress \
+            --source ADF --device="airscan:w1:Brother DCP-9022CDW" \
+            --batch=%d.tif --batch-increment=$pages --batch-start=$i
+        if [ $pages -ge 2 ];then
+            msg "Finished first turn, please change side!";
+            readp "Ready to continue?" noop
+        fi
+    done
+else
+    tm=$Command_path;
+fi
+cd $pw || die "Bug"
+
+# mk pdf
+if [ "$gen" = true ];then
+    mkdir pdfs
+    cd pdfs/  || die "Bug"
+fi
+
+while IFS= read -r i;do
+
+    if [ $pages -ge 2 ];then
+        a_set=false;
+        if [ -z "$a" ];then
+            a="$i"
+            a_set=true;
+            : $((counter += 1))
+        fi
+
+        if [ -n "$a" ] && ! [ "$a_set" = true ];then
+            convert "$a" "$i" -compress jpeg -quality 70 "$name"_"$counter".pdf
+            a=
+        fi
+    else
+        : $((counter += 1))
+        convert "$i" -compress jpeg -quality 70 "$name"_"$counter".pdf
+    fi
+
+
+done < "$(tmp "ls $tm | sort -n | awk -v a=$tm -v c='/' '{printf a} {printf c} {print \$0}' ")"
+
+
+rm -r $tm
+if [ -d /tmp/LIB_FILE_TEMP_DIR/ ];then rm -r /tmp/LIB_FILE_TEMP_DIR/; fi