Script to upload images to imageshack from console. Require bash and curl.
1 #!/bin/bash
2 #
3 # imageshack_upload.sh
4 #
5 # Copyright (c) 2007 by enki <enki@crocobox.org>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 # USA.
21 #
22 # Changelog :
23 # * 2006/10/22 - Updated to support files with space .
24 # Changes proposed by slubman(http://www.slubman.net)
25 # * 2006/10/22 - First version
26
27 myver='0.2'
28 CURL=$(which curl)
29
30
31
32 TMPFILE=$(mktemp /tmp/imageshack.XXXXXXXXXX) || exit 1
33
34 cleanup() {
35 rm -rf $TMPFILE
36 [ "$1" ] && exit $1
37 }
38
39 usage() {
40 echo "imageshack_upload $myver"
41 echo "usage: $0 <root>"
42 echo
43 echo "This script allow you to send image to htpp://www.imageshack.us"
44 echo "in command line"
45 echo
46 echo "example: imageshack_upload.sh `pwd`/myimage.png"
47 echo
48 }
49
50 if [ $# -lt 1 ]; then
51 usage
52 rm -rf $TMPFILE
53 exit 1
54 fi
55
56 if [ "$1" = "-h" -o "$1" = "--help" ]; then
57 usage
58 rm -rf $TMPFILE
59 exit 0
60 fi
61
62
63 img="$1"
64
65 if ! [ -f "$img" ]; then
66 echo "Error: file don't exist"
67 exit 1
68 fi
69
70 $CURL -H Expect: -F fileupload="@${img}" -F xml=yes http://www.imageshack.us/index.php > $TMPFILE
71
72 echo "Url of image on imageshack:"
73 echo $(cat $TMPFILE | grep -E "<image_link>(.*)</image_link>" | sed 's|<image_link>\(.*\)</image_link>|\1|')
74
75 cleanup
Pages : 1