From b812602d486df9bea39dfad23910a2449350d09c Mon Sep 17 00:00:00 2001 From: Pedro Pombeiro Date: Sun, 22 Sep 2024 19:22:13 +0200 Subject: [PATCH] Exit script if scan cancelled --- script/scanRear.sh | 6 ++++-- script/scantofile-0.2.4-1.sh | 4 +++- script/trigger_telegram.sh | 23 +++++++++++------------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/script/scanRear.sh b/script/scanRear.sh index 85eb9bf..9f7317c 100755 --- a/script/scanRear.sh +++ b/script/scanRear.sh @@ -12,15 +12,17 @@ if [ "$USE_JPEG_COMPRESSION" = "true" ]; then gm_opts+=(-compress JPEG -quality 80) fi +set -e # Exit on error + # device=$1 mkdir -p /tmp -cd /tmp || exit +cd /tmp date=$(ls -rd */ | grep "$(date +"%Y-%m-%d")" | head -1) date=${date%/} filename_base="/tmp/$date/${date}-back-page" output_file="${filename_base}%04d.pnm" -cd "/tmp/${date}" || exit +cd "/tmp/${date}" pkill -P "$(cat scan_pid)" rm scan_pid diff --git a/script/scantofile-0.2.4-1.sh b/script/scantofile-0.2.4-1.sh index 6ed0f11..1e4893f 100755 --- a/script/scantofile-0.2.4-1.sh +++ b/script/scantofile-0.2.4-1.sh @@ -16,8 +16,10 @@ # device=$1 date=$(date +%Y-%m-%d-%H-%M-%S) + set -e # Exit on error + mkdir -p "/tmp/$date" - cd "/tmp/$date" || exit + cd "/tmp/$date" filename_base="/tmp/${date}/${date}-front-page" output_file="${filename_base}%04d.pnm" echo "filename: $output_file" diff --git a/script/trigger_telegram.sh b/script/trigger_telegram.sh index 6280167..f96f6e6 100755 --- a/script/trigger_telegram.sh +++ b/script/trigger_telegram.sh @@ -3,18 +3,17 @@ # Check if TELEGRAM_TOKEN and TELEGRAM_CHATID are both set if [ -z "${TELEGRAM_TOKEN}" ] || [ -z "${TELEGRAM_CHATID}" ]; then echo "TELEGRAM_TOKEN or TELEGRAM_CHATID is not set" - exit 1 -fi - -# Use the environment variables TELEGRAM_TOKEN and TELEGRAM_CHATID -TOKEN="$TELEGRAM_TOKEN" -CHAT_ID="$TELEGRAM_CHATID" +else + # Use the environment variables TELEGRAM_TOKEN and TELEGRAM_CHATID + TOKEN="$TELEGRAM_TOKEN" + CHAT_ID="$TELEGRAM_CHATID" -# The message is passed as a parameter -MESSAGE="Scanner: $1" + # The message is passed as a parameter + MESSAGE="Scanner: $1" -# URL encode the message to handle spaces and special characters -ENCODED_MESSAGE=$(echo "$MESSAGE" | jq -sRr @uri) + # URL encode the message to handle spaces and special characters + ENCODED_MESSAGE=$(echo "$MESSAGE" | jq -sRr @uri) -# Send the message using wget -wget -qO- --post-data="chat_id=$CHAT_ID&text=$ENCODED_MESSAGE" "https://api.telegram.org/$TOKEN/sendMessage" > /dev/null + # Send the message using wget + wget -qO- --post-data="chat_id=$CHAT_ID&text=$ENCODED_MESSAGE" "https://api.telegram.org/$TOKEN/sendMessage" >/dev/null +fi