sftp.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. # Prerequisites
  3. # Environment Variables:
  4. # UPLOAD_USER - user to upload to sftp server
  5. # KEY is assumed to be path to a ssh key for UPLOAD_USER
  6. DIR=$1
  7. shift
  8. KEY=$1
  9. shift
  10. FILES=$*
  11. source $(dirname $0)/../common/util.sh
  12. set_pr_id
  13. set_branch
  14. if [ ! -z ${PR_ID+x} ] || [ $current_branch != "master" ]; then
  15. DIR=${DIR}/branches
  16. fi
  17. if [ -s $KEY ]; then
  18. if [ ! -z ${PR_ID+x} ] || [ $current_branch != "master" ]; then
  19. # clean up old copies of the same branch/PR
  20. if [ ! -z ${PR_ID+x} ]; then
  21. echo "rm *PR${PR_ID}*" | sftp -i$KEY "${UPLOAD_USER}@dl.slic3r.org:$DIR/"
  22. fi
  23. if [ $current_branch != "master" ]; then
  24. echo "rm *${current_branch}*" | sftp -i$KEY "${UPLOAD_USER}@dl.slic3r.org:$DIR/"
  25. fi
  26. fi
  27. for i in $FILES; do
  28. filepath=$i # this is expected to be an absolute path
  29. tmpfile=$(mktemp)
  30. echo put $filepath > $tmpfile
  31. sftp -b $tmpfile -i$KEY "${UPLOAD_USER}@dl.slic3r.org:$DIR/"
  32. result=$?
  33. if [ $? -eq 1 ]; then
  34. echo "Error with SFTP"
  35. exit $result;
  36. fi
  37. done
  38. else
  39. echo "$KEY is not available, not deploying."
  40. fi
  41. exit $result