74 lignes
2 KiB
Bash
Fichier exécutable
74 lignes
2 KiB
Bash
Fichier exécutable
#!/bin/sh
|
|
|
|
SCRIPT_NAME="$(realpath "$0")"
|
|
SCRIPT_PATH="$(dirname "$SCRIPT_NAME")"
|
|
|
|
cd "$SCRIPT_PATH"
|
|
|
|
usage() {
|
|
printf " Usage:\\n\\n"
|
|
printf " [FILE=/path/to/contacts.vcf] DEVICE=XXXXXXXXXXXXXXXX %s\\n" "$0"
|
|
}
|
|
|
|
if [ -z "$DEVICE" ]; then
|
|
usage
|
|
|
|
exit 0
|
|
fi
|
|
|
|
if [ -n "$FILE" ]; then
|
|
SEARCH="$(whiptail --title "Filtrer les destinataires" --inputbox "Laissez vide pour tout voir" 8 50 3>&1 1>&2 2>&3)"
|
|
|
|
COMMAND="whiptail --title \"Contacts\" --menu \"Choisir un destinataire\" 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")"
|
|
else
|
|
PHONE="$(whiptail --title "Saisir le numéro" --inputbox "" 8 50 3>&1 1>&2 2>&3)"
|
|
fi
|
|
|
|
|
|
if [ -n "$PHONE" ]; then
|
|
TMP_FILE="/tmp/send-sms-$(tr -dc "qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urandom | head -c 16)"
|
|
TMP_FILE2="/tmp/send-sms-$(tr -dc "qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urandom | head -c 16)"
|
|
touch "$TMP_FILE"
|
|
touch "$TMP_FILE2"
|
|
chmod 600 "$TMP_FILE"
|
|
chmod 600 "$TMP_FILE2"
|
|
|
|
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" > "$TMP_FILE2" 2>&1
|
|
|
|
if [ ! $? -eq 0 ]; then
|
|
if (whiptail --title "Confirmation" --yesno "$(cat $TMP_FILE2)\nEssayer à nouveau ?" 12 50 3>&1 1>&2 2>&3) then
|
|
kdeconnect-cli --device "$DEVICE" --send-sms "$(cat "$TMP_FILE")" --destination "$PHONE"
|
|
fi
|
|
fi
|
|
else
|
|
printf "Aborded!\\n"
|
|
fi
|
|
else
|
|
printf "Aborded!\\n"
|
|
fi
|
|
|
|
rm "$TMP_FILE"
|
|
rm "$TMP_FILE2"
|
|
fi
|