sftp-symlink.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. EXT=$1
  11. shift
  12. FILES=$*
  13. if [ -z ${READLINK+x} ]; then
  14. READLINK_BIN=readlink
  15. else
  16. READLINK_BIN=$READLINK
  17. fi
  18. source $(dirname $0)/../common/util.sh
  19. set_pr_id
  20. set_branch
  21. if [ ! -z ${PR_ID+x} ] || [ $current_branch != "master" ]; then
  22. DIR=${DIR}/branches
  23. fi
  24. if [ -s $KEY ]; then
  25. for i in $FILES; do
  26. filepath=$(${READLINK_BIN} -f "$i")
  27. filepath=$(basename $filepath)
  28. tmpfile=$(mktemp)
  29. echo "rm Slic3r-${current_branch}-latest.${EXT}" | sftp -i$KEY "${UPLOAD_USER}@dl.slic3r.org:$DIR/"
  30. echo "symlink $filepath Slic3r-${current_branch}-latest.${EXT} " > $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 symlink"
  35. exit $result;
  36. fi
  37. done
  38. else
  39. echo "$KEY is not available, not symlinking."
  40. fi
  41. exit $result