Brian Silverman | d94642c | 2014-03-27 18:21:41 -0700 | [diff] [blame] | 1 | #!/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 | |
| 8 | GET_IP=$(dirname $0)/get_ip |
| 9 | SUM=md5sum |
| 10 | FROM_DIR=$1 |
| 11 | TO_DIR=/home/driver/robot_code/bin |
| 12 | TMPDIR=/tmp/aos_downloader |
| 13 | TARGET=driver@$(${GET_IP} prime) |
| 14 | |
| 15 | SUMS=$(cd ${FROM_DIR} && ${SUM} *) |
| 16 | |
| 17 | TO_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 Silverman | ab63da3 | 2014-03-29 19:19:55 -0700 | [diff] [blame^] | 18 | if [[ $? != 0 ]]; then |
| 19 | echo 'Connecting to target failed.' |
| 20 | exit 1 |
| 21 | fi |
Brian Silverman | d94642c | 2014-03-27 18:21:41 -0700 | [diff] [blame] | 22 | |
| 23 | if [[ -z "${TO_DOWNLOAD}" ]]; then |
| 24 | echo "Nothing to download" |
| 25 | exit 0 |
| 26 | fi |
| 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 Silverman | ab63da3 | 2014-03-29 19:19:55 -0700 | [diff] [blame^] | 32 | if [[ $? != 0 ]]; then |
| 33 | echo 'Copying files into /tmp on target failed.' |
| 34 | exit 1 |
| 35 | fi |
Brian Silverman | d94642c | 2014-03-27 18:21:41 -0700 | [diff] [blame] | 36 | ssh ${TARGET} "mv ${TMPDIR}/* ${TO_DIR} && echo 'Done moving new executables into place' && ionice -c 3 bash -c 'sync && sync && sync'" |
Brian Silverman | ab63da3 | 2014-03-29 19:19:55 -0700 | [diff] [blame^] | 37 | exit $? |