sftp-symlink.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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} ]; then
  22. exit 0
  23. fi
  24. if [ ! -z ${PR_ID+x} ] || [ $current_branch != "master" ]; then
  25. DIR=${DIR}/branches
  26. fi
  27. if [ -s $KEY ]; then
  28. for i in $FILES; do
  29. filepath=$(${READLINK_BIN} -f "$i")
  30. filepath=$(basename $filepath)
  31. tmpfile=$(mktemp)
  32. echo "rm Slic3r-${current_branch}-latest.${EXT}" | sftp -i$KEY "${UPLOAD_USER}@dl.slic3r.org:$DIR/"
  33. echo "symlink $filepath Slic3r-${current_branch}-latest.${EXT} " > $tmpfile
  34. sftp -b $tmpfile -i$KEY "${UPLOAD_USER}@dl.slic3r.org:$DIR/"
  35. result=$?
  36. if [ $? -eq 1 ]; then
  37. echo "Error with SFTP symlink"
  38. exit $result;
  39. fi
  40. done
  41. else
  42. echo "$KEY is not available, not symlinking."
  43. fi
  44. exit $result