You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

send-sms 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. SCRIPT_NAME="$(realpath "$0")"
  3. SCRIPT_PATH="$(dirname "$SCRIPT_NAME")"
  4. cd "$SCRIPT_PATH"
  5. usage() {
  6. printf " Usage:\\n\\n"
  7. printf " [FILE=/path/to/contacts.vcf] DEVICE=XXXXXXXXXXXXXXXX %s\\n" "$0"
  8. }
  9. if [ -z "$DEVICE" ]; then
  10. usage
  11. exit 0
  12. fi
  13. if [ -n "$FILE" ]; then
  14. SEARCH="$(whiptail --title "Filtrer les destinataires" --inputbox "Laissez vide pour tout voir" 8 50 3>&1 1>&2 2>&3)"
  15. COMMAND="whiptail --title \"Contacts\" --menu \"Choisir un destinataire\" 25 65 16"
  16. COMMAND="$COMMAND $(FILE="$FILE" ./extract-contacts | sort | while read CONTACT; do
  17. VALUE="$(echo "$CONTACT" | cut -d\| -f2 | sed 's/"//g')"
  18. LABEL="$(echo "$CONTACT" | cut -d\| -f1 | sed 's/"//g')"
  19. if [ -n "$SEARCH" ]; then
  20. if [ -n "$(echo "$LABEL" | grep -i "$SEARCH")" ]; then
  21. printf " \"%s\" \"%s\"" "$VALUE" " $LABEL "
  22. fi
  23. else
  24. printf " \"%s\" \"%s\"" "$VALUE" " $LABEL "
  25. fi
  26. done)"
  27. PHONE="$(eval "$COMMAND 3>&1 1>&2 2>&3")"
  28. else
  29. PHONE="$(whiptail --title "Saisir le numéro" --inputbox "" 8 50 3>&1 1>&2 2>&3)"
  30. fi
  31. if [ -n "$PHONE" ]; then
  32. TMP_FILE="/tmp/send-sms-$(tr -dc "qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urandom | head -c 16)"
  33. TMP_FILE2="/tmp/send-sms-$(tr -dc "qwertQWERTasdfgASDFGzxcvbZXCVB" < /dev/urandom | head -c 16)"
  34. touch "$TMP_FILE"
  35. touch "$TMP_FILE2"
  36. chmod 600 "$TMP_FILE"
  37. chmod 600 "$TMP_FILE2"
  38. vim "$TMP_FILE"
  39. if [ -n "$(cat "$TMP_FILE")" ]; then
  40. whiptail --textbox "$TMP_FILE" --title "SMS pour $PHONE" 15 70
  41. if (whiptail --title "Confirmation" --yesno "Valides-tu l'expédition du SMS ?" 8 50 3>&1 1>&2 2>&3) then
  42. kdeconnect-cli --device "$DEVICE" --send-sms "$(cat "$TMP_FILE")" --destination "$PHONE" > "$TMP_FILE2" 2>&1
  43. if [ ! $? -eq 0 ]; then
  44. if (whiptail --title "Confirmation" --yesno "$(cat $TMP_FILE2)\nEssayer à nouveau ?" 12 50 3>&1 1>&2 2>&3) then
  45. kdeconnect-cli --device "$DEVICE" --send-sms "$(cat "$TMP_FILE")" --destination "$PHONE"
  46. fi
  47. fi
  48. else
  49. printf "Aborded!\\n"
  50. fi
  51. else
  52. printf "Aborded!\\n"
  53. fi
  54. rm "$TMP_FILE"
  55. rm "$TMP_FILE2"
  56. fi