A utility for downloading and verifying FreeBSD releases and snapshots
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.
 
 
 
 

149 lines
3.5 KiB

  1. #!/bin/sh -
  2. #
  3. # Copyright 2018 John-Mark Gurney.
  4. # All rights reserved.
  5. #
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions
  8. # are met:
  9. # 1. Redistributions of source code must retain the above copyright
  10. # notice, this list of conditions and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. # notice, this list of conditions and the following disclaimer in the
  13. # documentation and/or other materials provided with the distribution.
  14. #
  15. # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  16. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  19. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  21. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  23. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  24. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  25. # SUCH DAMAGE.
  26. #
  27. # $Id$
  28. #
  29. set -e
  30. usage() {
  31. echo "Usage: $0 [ -m ] <file>"
  32. echo "Usage: $0 -c <date>"
  33. echo ''
  34. echo 'date is specified as YYYYMMDD'
  35. if [ x"$1" != x"" ]; then
  36. exit $1
  37. fi
  38. }
  39. args=`getopt cm $*`
  40. if [ $? -ne 0 ]; then
  41. usage 2
  42. fi
  43. set -- $args
  44. while :; do
  45. case "$1" in
  46. -c)
  47. complete=1
  48. shift
  49. ;;
  50. -m)
  51. more=1
  52. shift
  53. ;;
  54. --)
  55. shift; break
  56. ;;
  57. esac
  58. done
  59. if [ x"$complete" = x"1" -a x"$more" = x"1" ]; then
  60. echo '-m and -c cannot be specified at the same time.'
  61. usage 2
  62. elif [ x"$complete" = x"1" -a $# -ne 1 ]; then
  63. echo 'must only specify a date with -c'
  64. usage 2
  65. elif [ x"$complete" != x"1" -a $# -ne 1 ]; then
  66. echo 'must specify exactly one file'
  67. usage 2
  68. fi
  69. mkdir "$0.running"
  70. if [ x"$complete" = x"1" ]; then
  71. sort -u snapshot.complete.idx | xz > snapshot.complete.idx.xz
  72. awk '$5 >= "'"$1"'" {
  73. if (!system("wget --method=HEAD " $9))
  74. print
  75. }
  76. ' snapshot.idx | sort -u | xz > snapshot.idx.xz
  77. rm snapshot.idx snapshot.complete.idx
  78. rmdir "$0.running"
  79. exit 0
  80. fi
  81. # minimize file
  82. tmpfname="tmp.snapinf.asc"
  83. awk '
  84. output != 1 && tolower($1) == "message-id:" {
  85. print
  86. next
  87. }
  88. $0 == "-----BEGIN PGP SIGNED MESSAGE-----" {
  89. output = 1
  90. }
  91. output == 1 {
  92. print
  93. }
  94. $0 == "-----END PGP SIGNATURE-----" {
  95. output = 0
  96. }' "$1" > "$tmpfname"
  97. if ! gpg --verify "$tmpfname"; then
  98. echo 'failed verify'
  99. rm "$tmpfname"
  100. rmdir "$0.running"
  101. exit 1
  102. fi
  103. # process file
  104. awk -f ./mksnapidx.awk "$tmpfname" > additional
  105. rm "$tmpfname"
  106. # only check if there isn't more to come
  107. if [ x"$more" = x"1" ]; then
  108. (cat snapshot.idx || :; cat additional) > snapshot.idx.new
  109. (cat snapshot.complete.idx || :; cat additional) > snapshot.complete.idx.new
  110. else
  111. (xzcat snapshot.idx.xz; cat additional) | sort -u | awk '
  112. {
  113. if (!system("wget --method=HEAD " $9))
  114. print
  115. }
  116. ' > snapshot.idx.new
  117. xz snapshot.idx.new
  118. (xzcat snapshot.complete.idx.xz || :; cat additional) | sort -u > snapshot.complete.idx.new
  119. xz snapshot.complete.idx.new
  120. fi
  121. rm additional
  122. # install new indexes
  123. if [ x"$more" = x"1" ]; then
  124. mv snapshot.idx.new snapshot.idx
  125. mv snapshot.complete.idx.new snapshot.complete.idx
  126. else
  127. mv snapshot.idx.new.xz snapshot.idx.xz
  128. mv snapshot.complete.idx.new.xz snapshot.complete.idx.xz
  129. fi
  130. rmdir "$0.running"