sms-sender/send-sms

57 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
SCRIPT_NAME="$(realpath "$0")"
SCRIPT_PATH="$(dirname "$SCRIPT_NAME")"
cd "$SCRIPT_PATH"
usage() {
printf " Usage:\\n"
printf " FILE=/path/to/contacts.vcf DEVICE=XXXXXXXXXXXXXXXX %s\\n" "$0"
}
if [ -z "$FILE" ] || [ -z "$DEVICE" ]; then
usage
exit 0
fi
SEARCH="$(whiptail --title "Filtre de contact" --inputbox "" 8 50 3>&1 1>&2 2>&3)"
COMMAND="whiptail --title \"Contacts\" --menu \"Choose a recipient\" 25 65 16"
COMMAND="$COMMAND $(FILE="$FILE" ./extract-contacts | sort | while read CONTACT; do
VALUE="$(echo "$CONTACT" | cut -d\| -f2 | sed 's/"//g')"
LABEL="$(echo "$CONTACT" | cut -d\| -f1 | sed 's/"//g')"
if [ -n "$SEARCH" ]; then
if [ -n "$(echo "$LABEL" | grep -i "$SEARCH")" ]; then
printf " \"%s\" \"%s\"" "$VALUE" "$LABEL"
fi
else
printf " \"%s\" \"%s\"" "$VALUE" "$LABEL"
fi
done)"
PHONE="$(eval "$COMMAND 3>&1 1>&2 2>&3")"
if [ -n "$PHONE" ]; then
TMP_FILE="/tmp/send-sms-$(tr -dc "qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urandom | head -c 16)"
touch "$TMP_FILE"
chmod 600 "$TMP_FILE"
vim "$TMP_FILE"
if [ -n "$(cat "$TMP_FILE")" ]; then
whiptail --textbox "$TMP_FILE" --title "SMS pour $PHONE" 15 70
if (whiptail --title "Confirmation" --yesno "Valides-tu l'expédition du SMS ?" 8 50 3>&1 1>&2 2>&3) then
kdeconnect-cli --device "$DEVICE" --send-sms "$(cat "$TMP_FILE")" --destination "$PHONE"
else
printf "Aborded!\\n"
fi
fi
rm "$TMP_FILE"
fi