Skip to content

Commit

Permalink
Exit script if scan cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
pedropombeiro committed Sep 22, 2024
1 parent 56b6ab1 commit fffcc05
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
6 changes: 4 additions & 2 deletions script/scanRear.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ fi
device="$1"
script_dir="/opt/brother/scanner/brscan-skey/script"

set -e # Exit on error

mkdir -p /tmp
cd /tmp || exit
cd /tmp
date=$(ls -rd */ | grep "$(date +"%Y-%m-%d")" | head -1)
date=${date%/}
tmp_dir="/tmp/${date}"
Expand All @@ -25,7 +27,7 @@ tmp_output_file="${filename_base}%04d.pnm"
tmp_output_pdf_file="${tmp_dir}/${date}.pdf"
output_pdf_file="/scans/${date}.pdf"

cd "$tmp_dir" || exit
cd "$tmp_dir"

kill -9 "$(cat scan_pid)"
rm scan_pid
Expand Down
6 changes: 5 additions & 1 deletion script/scantofile-0.2.4-1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
tmp_output_file="${filename_base}%04d.pnm"
output_pdf_file="/scans/${date}.pdf"

set -e # Exit on error

mkdir -p "$tmp_dir"
cd "$tmp_dir" || exit
cd "$tmp_dir"
filename_base="/tmp/${date}/${date}-front-page"
output_file="${filename_base}%04d.pnm"
echo "filename: $tmp_output_file"

function scan_cmd() {
Expand Down
23 changes: 11 additions & 12 deletions script/trigger_telegram.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fffcc05

Please sign in to comment.