dc590440adb2dfe45440b0067dff94bd22e42372
Raven First version of the script...

Raven authored 9 years ago

1) #!/bin/bash
raven split int to two repos, ext...

raven authored 9 years ago

2) # find location of the script
3) # ## TODO Softcode this.
4) pwd=~/src/sms
Raven added the option to edit th...

Raven authored 9 years ago

5) 
raven split int to two repos, ext...

raven authored 9 years ago

6) # set user variables. (see config_example)
7) . ~/src/sms-data/config
8) 
9) # Where to store the tempfile when using vim
Raven added the option to edit th...

Raven authored 9 years ago

10) sms_tempfile=~/.sms_temp
raven split int to two repos, ext...

raven authored 9 years ago

11) ###########
Raven First version of the script...

Raven authored 9 years ago

12) n=1;
raven split int to two repos, ext...

raven authored 9 years ago

13) for entry in $(cat $pwd/../sms-data/contacts);do
Raven First version of the script...

Raven authored 9 years ago

14) echo $n $entry;
15) n=$(($n+1))
16) done;
17) 
18) while true
19) do
20)   # (1) prompt user for recipent, and read command line argument
21)    read -p "To: " toinput
22)   # (2) handle the input we were given
23)        case $toinput in
24)             [\+0][0-9]* ) nr=$toinput; break;;
25)             [1-9]* )    n=0;
raven split int to two repos, ext...

raven authored 9 years ago

26)                         for entry in $(cat $pwd/../sms-data/contacts);do
Raven First version of the script...

Raven authored 9 years ago

27)                             n=$(($n+1))
28)                             if (($n==$toinput)); then
29)                                 nr=$(echo $entry|cut -d ',' -f2)
30)                             fi
31)                         done
32)                     break;;
33)                 * ) echo 'Please enter the nr. of an entry or a full phonenumber';;
34)         esac
35) done
36) 
Raven added the option to edit th...

Raven authored 9 years ago

37) tempdata=0
38) 
Raven First version of the script...

Raven authored 9 years ago

39)   # (3) prompt user for message content, and read command line argument
Raven added sed and cat input opt...

Raven authored 9 years ago

40) read -p "Message: " messageinput
41) 
42) case $messageinput in
43)     sed )
44)         echo -n 'Message: '
45)         messageinput=$(sed '/^$/q');;
46)     cat )
47)         echo -n 'Message: '
48)         messageinput=$(cat);;
Raven added the option to edit th...

Raven authored 9 years ago

49)     vim )
50)         touch $sms_tempfile
51)         tempdata=1
52)         vim $sms_tempfile
53)         messageinput=$(cat $sms_tempfile);;
Raven added sed and cat input opt...

Raven authored 9 years ago

54)     * ) ;;
55)     esac
56) 
Raven First version of the script...

Raven authored 9 years ago

57) while true
58) do
59)       # (1) prompt user, and read command line argument
60)     read -p "Send message to $nr?[n] " answer
61)       # (2) handle the input we were given
62)      case $answer in
63)         [nN]* ) action=info;break;;
64)             * )  break;;
65)       esac
66) done
67) echo -----------
68)     curl http://www.sms-revolution.ch/API/httpsms.php -d user=$user \
69)     -d password=$password --data-urlencode "text=$messageinput" \
70)     -d to=$nr -d from=$from -d action=$action -d typ=$typ \
raven split int to two repos, ext...

raven authored 9 years ago

71)     -d timestamp=$timestamp -d return=$return -d httphead=$httphead
72) 
73) # TODO get a usable return value from curl and actualy make this work.
74) if (($tempdata == 1)); then
75)     if $(echo $response | grep 100); then
Raven added the option to edit th...

Raven authored 9 years ago

76)         rm $sms_tempfile
77)     else
raven split int to two repos, ext...

raven authored 9 years ago

78)         echo "response was not 100, leaving tempfile where it is"