You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. #!/bin/bash
  2. set -e
  3. exec 3>&1 # make stdout available as fd 3 for the result
  4. exec 1>&2 # redirect all output to stderr for logging
  5. source $(dirname $0)/common.sh
  6. source=$1
  7. if [ -z "$source" ]; then
  8. echo "usage: $0 <path/to/source>"
  9. exit 1
  10. fi
  11. cd $source
  12. payload=$(mktemp $TMPDIR/concoure-curl-resource-request.XXXXXX)
  13. cat > $payload <&0
  14. url=$(jq -r '.source.url // ""' < $payload)
  15. filename=$(jq -r '.source.filename // ""' < $payload)
  16. skip_ssl_verification=$(jq -r '.source.skip_ssl_verification // ""' < $payload)
  17. username=$(jq -r '.source.username // ""' < $payload)
  18. password=$(jq -r '.source.password // ""' < $payload)
  19. if [ -z "$url" ]; then
  20. echo "invalid payload (missing url)"
  21. exit 1
  22. fi
  23. if [ -z "$filename" ]; then
  24. filename="file"
  25. fi
  26. # Building CURL request
  27. args_url="$url"
  28. args_security=
  29. [ -n "$username" ] && args_security="-u $username";
  30. [ -n "$username" ] && [ -n "$password" ] && args_security="$args_security:$password";
  31. trueValue="true"
  32. [ -n "$skip_ssl_verification" ] && [ "${skip_ssl_verification,,}" = "${trueValue,,}" ] && args_security="$args_security -k";
  33. final_url=$(echo "$args_security" " $args_url")
  34. version=$(check_version "$final_url")
  35. if [ -z "$version" ]; then
  36. echo "Version could not be retrieved"
  37. exit 1
  38. fi
  39. curl "-L" $args_security "$args_url" "-o" "$filename"
  40. jq -n "{ version: {version: $(echo $version | jq .[].version )}}" >&3