gen_gradle_deps_file.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/sh
  2. # Copyright (c) 2020, The Tor Project, Inc.
  3. #
  4. # Redistribution and use in source and binary forms, with or without
  5. # modification, are permitted provided that the following conditions are
  6. # met:
  7. #
  8. # * Redistributions of source code must retain the above copyright
  9. # notice, this list of conditions and the following disclaimer.
  10. #
  11. # * Redistributions in binary form must reproduce the above
  12. # copyright notice, this list of conditions and the following disclaimer
  13. # in the documentation and/or other materials provided with the
  14. # distribution.
  15. #
  16. # * Neither the names of the copyright owners nor the names of its
  17. # contributors may be used to endorse or promote products derived from
  18. # this software without specific prior written permission.
  19. #
  20. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. # Usage:
  32. # 1) Point to a log file with all the dependency download attempts (for its
  33. # generation see: projects/common/how-to-create-gradle-dependencies-list.txt)
  34. # 2) Double-check that you get the same SHA-256 sums when downloaded from a
  35. # different network location. E.g. by using `torsocks` with this script after
  36. # having made a copy of `gradle-dependencies-list.txt` from 1) and comparing
  37. # the two .txt files.
  38. log="$1"
  39. # Step 1: Extract all the download attempts out of the log file, ignore the ones
  40. # for maven-metadata.xml files. We don't need those.
  41. cat $log | grep "Performing HTTP" | grep -o "https://.*" | \
  42. grep -v "maven-metadata.xml" | sort | uniq > dl-attempts
  43. # Step 2: Fetch all the dependencies and calculate the SHA-256 sum
  44. while read line
  45. do
  46. wget -U "" $line
  47. fn=$(basename "$line")
  48. sha256=`sha256sum $fn | cut -d ' ' -f 1`
  49. echo "$sha256 | $line" >> deps
  50. rm $fn
  51. done < dl-attempts
  52. # Step 3: Add the header at the beginning of the final dependency file.
  53. echo "# On how to update dependencies see projects/common/how-to-create-gradle\
  54. -dependencies-list.txt" > gradle-dependencies-list.txt
  55. echo "# Don't forget to update var/gradle_dependencies_version when modifying \
  56. this file" >> gradle-dependencies-list.txt
  57. echo "sha256sum | url" >> gradle-dependencies-list.txt
  58. # Step 4: Keep only successfully downloaded artifacts, remove duplicates, and
  59. # sort based on download URL.
  60. grep ^[a-f0-9] deps | rev | sort -t/ -u -k1,4 | rev | \
  61. sort -k 3 >> gradle-dependencies-list.txt
  62. # Step 5: Clean up
  63. rm dl-attempts
  64. rm deps
  65. exit 0