download_webclient.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/bin/bash
  2. cd "$(dirname "$0")"
  3. function download_compat {
  4. if [[ "$AZ_CACHE" != "" ]]
  5. then
  6. download_id=$(echo "$2" | md5sum | sed 's/ .*//g')
  7. if [[ -e "$AZ_CACHE/$3/$download_id" ]]
  8. then
  9. echo "Cache hit: $AZ_CACHE/$3/$download_id"
  10. cp "$AZ_CACHE/$3/$download_id" "$1"
  11. return
  12. elif [[ "$3" != "" ]]
  13. then
  14. rm -r "$AZ_CACHE/$3" 2> /dev/null
  15. fi
  16. fi
  17. if [[ "$(which wget 2>/dev/null)" != "" ]]
  18. then
  19. wget -qO "$1" "$2"
  20. else [[ "$(which curl)" != "" ]]
  21. curl -sL "$2" > "$1"
  22. fi
  23. if [[ "$AZ_CACHE" != "" ]]
  24. then
  25. echo "Saving to: $AZ_CACHE/$3/$download_id"
  26. mkdir -p "$AZ_CACHE/$3/"
  27. cp "$1" "$AZ_CACHE/$3/$download_id"
  28. fi
  29. }
  30. function get_resource_version {
  31. curl -s --head https://github.com/"$1"/releases/latest | \
  32. grep -i '^location: ' | sed 's/.*tag\///g' | tr -d '\r'
  33. }
  34. if [[ "$1" == "--gen-fingerprint" ]]
  35. then
  36. (
  37. get_resource_version iwalton3/jellyfin-web-jmp
  38. ) | tee az-cache-fingerprint.list
  39. exit 0
  40. fi
  41. # Download web client
  42. update_web_client="no"
  43. mkdir -p build
  44. if [[ ! -e "build/dist" ]]
  45. then
  46. update_web_client="yes"
  47. elif [[ -e ".last_wc_version" ]]
  48. then
  49. if [[ "$(get_resource_version iwalton3/jellyfin-web-jmp)" != "$(cat .last_wc_version)" ]]
  50. then
  51. update_web_client="yes"
  52. fi
  53. fi
  54. if [[ "$update_web_client" == "yes" ]]
  55. then
  56. echo "Downloading web client..."
  57. wc_version=$(get_resource_version iwalton3/jellyfin-web-jmp)
  58. download_compat dist.zip "https://github.com/iwalton3/jellyfin-web-jmp/releases/download/$wc_version/dist.zip" "wc"
  59. rm -r build/dist 2> /dev/null
  60. rm -r dist 2> /dev/null
  61. unzip dist.zip > /dev/null && rm dist.zip
  62. mv dist build/
  63. echo "$wc_version" > .last_wc_version
  64. fi