-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdent
More file actions
executable file
·140 lines (123 loc) · 3.08 KB
/
dent
File metadata and controls
executable file
·140 lines (123 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/bin/bash
# Copyright (C) 2010 Saar <@saar at identi.ca>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License or (at your option) version 3 or any later version.
#
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see http://www.gnu.org/licenses/
SOURCE="Dentinal"
##if you want, comment or change these lines
LAT="29.653374"
LONG="52.505379"
##if want to save username [and password] uncomment below lines and replace with your username and password
#USERNAME="username"
#PASSWORD="password"
##Requirements
#curl
##Options
#libnotify-bin
function usage {
echo "Usage: $0 [-i image] [-s source] [-u user] [-p password] [-t latitude -g longitude] [-r in_reply_to_status_id] [-x proxyhost:port] dent"
exit 1
}
function showMessage {
if [ -x /usr/bin/notify-send ]
then
notify-send "$2" "$1"
else
echo "$MESSAGE"
fi
}
while getopts i:s:u:p:r:t:g:x: opt ; do
case "$opt" in
i) IMAGE="$OPTARG";;
s) SOURCE="$OPTARG";;
u) USERNAME="$OPTARG";;
p) PASSWORD="$OPTARG";;
r) REPID="$OPTARG";;
t) LAT="$OPTARG";;
g) LONG="$OPTARG";;
x) PROXY="$OPTARG";;
\?) usage;;
esac
done
shift $[OPTIND -1]
STATUS="$*"
STATUS=`echo "$STATUS" | sed 's/@/\&\#64\;/g'`
ARGS=( )
if [ -n "$USERNAME" ]
then
N="${#ARGS[@]}"
ARGS[N]="-u"
if [ -n "$PASSWORD" ]
then
ARGS[N+1]="$USERNAME:$PASSWORD"
else
ARGS[N+1]="$USERNAME"
fi
else
showMessage "Username required!" "Error"
exit 2;
fi
if [ -n "$STATUS" ]
then
N="${#ARGS[@]}"
ARGS[N]="-F"
ARGS[N+1]="status=$STATUS"
else
usage
fi
if [ -n "$IMAGE" ]
then
N="${#ARGS[@]}"
ARGS[N]="-F"
ARGS[N+1]="media=@$IMAGE"
fi
if [ -n "$SOURCE" ]
then
N="${#ARGS[@]}"
ARGS[N]="-F"
ARGS[N+1]="source=$SOURCE"
fi
if [ -n "$REPID" ]
then
N="${#ARGS[@]}"
ARGS[N]="-F"
ARGS[N+1]="in_reply_to_status_id=$REPID"
fi
if [ -n "$PROXY" ]
then
N="${#ARGS[@]}"
ARGS[N]="-x"
ARGS[N+1]="$PROXY"
fi
if [ -n "$LAT" -a -n "$LONG" ]
then
N="${#ARGS[@]}"
ARGS[N]="-F"
ARGS[N+1]="lat=$LAT"
ARGS[N+2]="-F"
ARGS[N+3]="long=$LONG"
fi
TEMP=`mktemp`
CODE=`curl -o "$TEMP" -w "%{http_code}" "${ARGS[@]}" http://identi.ca/api/statuses/update.xml`
if [ "$CODE" == "200" ]
then
ID=`cat "$TEMP" | grep -o -m 1 "<id>[^<]*</id>" | sed 's/<id>\([^<]*\)<\/id>/\1/'`
NAME=`cat "$TEMP" | grep -o -m 1 "<name>[^<]*</name>" | sed 's/<name>\([^<]*\)<\/name>/\1/'`
MESSAGE="$NAME, '$STATUS' was submitted successfully. http://identi.ca/notice/$ID"
showMessage "$MESSAGE" "Success"
else
MESSAGE=`cat "$TEMP" | grep -o -m 1 "<error>[^<]*</error>" | sed 's/<error>\([^<]*\)<\/error>/\1/'`
showMessage "$MESSAGE" "Error"
fi
rm "$TEMP"