From f6e98f275480b56a24478f790d6c231e9db13a01 Mon Sep 17 00:00:00 2001 From: Reed Wade Date: Sun, 1 Nov 2020 14:26:25 +0100 Subject: [PATCH] Move the send sms logic in a dedicated script This allow userscripts to send sms using the sxmo way so we now can create our own sms clients. Signed-off-by: Reed Wade Signed-off-by: Maarten van Gompel --- scripts/modem/sxmo_modemsendsms.sh | 51 ++++++++++++++++++++++++++++++ scripts/modem/sxmo_modemtext.sh | 25 +-------------- 2 files changed, 52 insertions(+), 24 deletions(-) create mode 100755 scripts/modem/sxmo_modemsendsms.sh diff --git a/scripts/modem/sxmo_modemsendsms.sh b/scripts/modem/sxmo_modemsendsms.sh new file mode 100755 index 0000000..e7d5cf1 --- /dev/null +++ b/scripts/modem/sxmo_modemsendsms.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env sh +LOGDIR="$XDG_CONFIG_HOME"/sxmo/modem + +info() { + echo "$1" > /dev/stderr +} + +err() { + info "$1" + exit 1 +} + +usage() { + err "Usage: $(basename "$0") number [-|message]" +} + +modem_n() { + MODEMS="$(mmcli -L)" + echo "$MODEMS" | grep -qoE 'Modem\/([0-9]+)' || err "Couldn't find modem - is your modem enabled?" + echo "$MODEMS" | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2 +} + +MODEM="$(modem_n)" +[ 0 -eq $# ] && usage +NUMBER="$1" + +if [ "-" = "$2" ]; then + TEXT="$(cat)" +else + shift + [ 0 -eq $# ] && usage + + TEXT="$*" +fi +TEXTSIZE="${#TEXT}" + +SMSNO="$( + mmcli -m "$MODEM" --messaging-create-sms="text='$TEXT',number=$NUMBER" | + grep -o "[0-9]*$" +)" +mmcli -s "${SMSNO}" --send || err "Couldn't send text message" +for i in $(mmcli -m "$MODEM" --messaging-list-sms | grep " (sent)" | cut -f5 -d' ') ; do + mmcli -m "$MODEM" --messaging-delete-sms="$i" +done + +TIME="$(date --iso-8601=seconds)" +mkdir -p "$LOGDIR/$NUMBER" +printf %b "Sent to $NUMBER at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUMBER/sms.txt" +printf %b "$TIME\tsent_txt\t$NUMBER\t$TEXTSIZE chars\n" >> "$LOGDIR/modemlog.tsv" + +info "Sent text message ok" diff --git a/scripts/modem/sxmo_modemtext.sh b/scripts/modem/sxmo_modemtext.sh index 55db8b0..cb9bf46 100755 --- a/scripts/modem/sxmo_modemtext.sh +++ b/scripts/modem/sxmo_modemtext.sh @@ -33,29 +33,6 @@ editmsg() { cat "$TMP" } -sendmsg() { - MODEM="$(modem_n)" - NUMBER="$1" - TEXT="$2" - TEXTSIZE="${#TEXT}" - - SMSNO="$( - mmcli -m "$MODEM" --messaging-create-sms="text='$TEXT',number=$NUMBER" | - grep -o "[0-9]*$" - )" - mmcli -s "${SMSNO}" --send || err "Couldn't send text message\nPostponed to $(postpone "$NUMBER" "$TEXT")" - for i in $(mmcli -m "$MODEM" --messaging-list-sms | grep " (sent)" | cut -f5 -d' ') ; do - mmcli -m "$MODEM" --messaging-delete-sms="$i" - done - - TIME="$(date --iso-8601=seconds)" - mkdir -p "$LOGDIR/$NUMBER" - printf %b "Sent to $NUMBER at $TIME:\n$TEXT\n\n" >> "$LOGDIR/$NUMBER/sms.txt" - printf %b "$TIME\tsent_txt\t$NUMBER\t$TEXTSIZE chars\n" >> "$LOGDIR/modemlog.tsv" - - err "Sent text message ok" -} - choosenumbermenu() { modem_n >/dev/null || err "Couldn't determine modem number - is modem online?" @@ -88,7 +65,7 @@ sendtextmenu() { printf %b "Edit Message ($(echo "$TEXT" | head -n1))\nSend to → $NUMBER\nPostpone\nCancel" | menu dmenu -c -idx 1 -p "Confirm" -fn "Terminus-20" -l 10 )" - echo "$CONFIRM" | grep -E "^Send" && sendmsg "$NUMBER" "$TEXT" && exit 0 + echo "$CONFIRM" | grep -E "^Send" && (echo "$TEXT" | sxmo_modemsendsms.sh "$NUMBER" -) && exit 0 echo "$CONFIRM" | grep -E "^Cancel$" && exit 1 echo "$CONFIRM" | grep -E "^Edit Message" && TEXT="$(editmsg "$NUMBER" "$TEXT")" echo "$CONFIRM" | grep -E "^Postpone$" && err "Postponed to $(postpone "$NUMBER" "$TEXT")"