anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

anastasis-authorization-sms.sh (657B)


      1 #!/bin/bash
      2 # This file is in the public domain.
      3 # Send an SMS
      4 set -eu
      5 
      6 if [ $# -ne 1 ]
      7 then
      8     echo "Usage: $0 <phone_number>" 1>&2
      9     exit 1
     10 fi
     11 
     12 SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
     13 SCRIPT_NAME=$(basename "$0")
     14 BASE="${SCRIPT_NAME%.sh}"
     15 
     16 PHONE_NUMBER="$1"
     17 MESSAGE=$(cat -)
     18 
     19 # List of sub-scripts to try.
     20 PROVIDERS="telesign clicksend"
     21 
     22 for PROVIDER in $PROVIDERS
     23 do
     24     SCRIPT_PATH="$SCRIPT_DIR/${BASE}-${PROVIDER}.sh"
     25     if [ -x "$SCRIPT_PATH" ]
     26     then
     27 	if echo "$MESSAGE" | "$SCRIPT_PATH" "$PHONE_NUMBER"
     28 	then
     29 	    exit 0
     30 	else
     31 	    echo "$PROVIDER failed." 1>&2
     32 	fi
     33     fi
     34 done
     35 
     36 echo "All SMS providers failed." 1>&2
     37 exit 1