| 1 | #!/usr/bin/env bash |
| 2 | # This file is part of Libre-Streamer. |
| 3 | # |
| 4 | # Libre-Streamer is free software: you can redistribute it and/or modify |
| 5 | # it under the terms of the GNU General Public License as published by |
| 6 | # the Free Software Foundation, either version 3 of the License, or |
| 7 | # (at your option) any later version. |
| 8 | # |
| 9 | # Libre-Streamer is distributed in the hope that it will be useful, |
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | # GNU General Public License for more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License |
| 15 | # along with Libre-Streamer. If not, see <http://www.gnu.org/licenses/>. |
| 16 | # |
| 17 | # Copyright (C) 2014 Nico Cesar |
| 18 | |
| 19 | if [ $# -lt 1 ] |
| 20 | then |
| 21 | echo $# |
| 22 | echo "usage: $0 elphel_camera_IP_address [config.xml] [/etc/autocampars.xml]" |
| 23 | fi |
| 24 | |
| 25 | if [ "x$2" = "x" ] |
| 26 | then |
| 27 | config_file=config.xml |
| 28 | else |
| 29 | config_file=$2 |
| 30 | fi |
| 31 | |
| 32 | if [ "x$3" = "x" ] |
| 33 | then |
| 34 | dest_file=/etc/autocampars.xml |
| 35 | else |
| 36 | dest_file=$2 |
| 37 | fi |
| 38 | |
| 39 | echo -n "pinging $1 ... " |
| 40 | ping -c2 $1 > /dev/null |
| 41 | RESULT=$? |
| 42 | |
| 43 | if [ $RESULT -ne 0 ] |
| 44 | then |
| 45 | echo cant ping $1 |
| 46 | exit 1 |
| 47 | fi |
| 48 | echo OK |
| 49 | |
| 50 | #do an url encode of the file |
| 51 | python -c 'import sys,urllib; print urllib.urlencode([("content",sys.stdin.read())])' < $config_file > /tmp/tmp_file |
| 52 | |
| 53 | #upload to the camera |
| 54 | curl -0 http://$1/admin-bin/editcgi.cgi?file= -d "save_file=/etc/autocampars.xml" -d "mode=0100644" -d "convert_crlf_to_lf=on" -d '@/tmp/tmp_file' | grep "Wrote" |
| 55 | RESULT=$? |
| 56 | |
| 57 | if [ $RESULT -ne 0 ] |
| 58 | then |
| 59 | echo problems loading the config |
| 60 | exit 1 |
| 61 | fi |
| 62 | exit 0 |