blob: 3efdb557b99fb6f16ed69d6123523ac6caae1b42 [file] [log] [blame]
Brian Silvermand94642c2014-03-27 18:21:41 -07001#!/bin/bash
2#set -x
3
4# Downloads code to the prime in a way that avoids clashing too badly with
5# starter.
6# Requires 1 argument (the directory to download).
7
8GET_IP=$(dirname $0)/get_ip
9SUM=md5sum
10FROM_DIR=$1
11TO_DIR=/home/driver/robot_code/bin
12TMPDIR=/tmp/aos_downloader
13TARGET=driver@$(${GET_IP} prime)
14
15SUMS=$(cd ${FROM_DIR} && ${SUM} *)
16
Brian Silverman2430eb82014-04-01 12:54:24 -070017TO_DOWNLOAD=$(ssh ${TARGET} "rm -rf ${TMPDIR} && mkdir ${TMPDIR} && cd ${TO_DIR} && echo '${SUMS}' | ${SUM} --check --quiet |& grep -F FAILED | sed 's/^\\(.*\\): FAILED.*"'$'"/\\1/g'")
Brian Silvermanab63da32014-03-29 19:19:55 -070018if [[ $? != 0 ]]; then
19 echo 'Connecting to target failed.'
20 exit 1
21fi
Brian Silvermand94642c2014-03-27 18:21:41 -070022
23if [[ -z "${TO_DOWNLOAD}" ]]; then
24 echo "Nothing to download"
25 exit 0
26fi
27
28# Compression seems to make it go faster even when the network isn't the
29# bottleneck with a BBB. Maybe it's because ethernet on the BBB uses so much
30# CPU?
31( cd ${FROM_DIR} && scp -o "Compression yes" ${TO_DOWNLOAD} ${TARGET}:${TMPDIR} )
Brian Silvermanab63da32014-03-29 19:19:55 -070032if [[ $? != 0 ]]; then
33 echo 'Copying files into /tmp on target failed.'
34 exit 1
35fi
Brian Silvermand94642c2014-03-27 18:21:41 -070036ssh ${TARGET} "mv ${TMPDIR}/* ${TO_DIR} && echo 'Done moving new executables into place' && ionice -c 3 bash -c 'sync && sync && sync'"
Brian Silvermanab63da32014-03-29 19:19:55 -070037exit $?