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.
 
 
 
 

122 lines
2.2 KiB

  1. #!/bin/sh -
  2. set -e
  3. usage() {
  4. echo 'Usage: $0 [ -m ] <file>'
  5. echo 'Usage: $0 -c <date>'
  6. echo ''
  7. echo 'date is specified as YYYYMMDD'
  8. if [ x"$1" != x"" ]; then
  9. exit $1
  10. fi
  11. }
  12. args=`getopt cm $*`
  13. if [ $? -ne 0 ]; then
  14. usage 2
  15. fi
  16. set -- $args
  17. while :; do
  18. case "$1" in
  19. -c)
  20. complete=1
  21. shift
  22. ;;
  23. -m)
  24. more=1
  25. shift
  26. ;;
  27. --)
  28. shift; break
  29. ;;
  30. esac
  31. done
  32. if [ x"$complete" = x"1" -a x"$more" = x"1" ]; then
  33. echo '-m and -c cannot be specified at the same time.'
  34. usage 2
  35. elif [ x"$complete" = x"1" -a $# -ne 1 ]; then
  36. echo 'must only specify a date with -c'
  37. usage 2
  38. elif [ x"$complete" != x"1" -a $# -ne 1 ]; then
  39. echo 'must specify exactly one file'
  40. usage 2
  41. fi
  42. mkdir "$0.running"
  43. if [ x"$complete" = x"1" ]; then
  44. sort -u snapshot.complete.idx | xz > snapshot.complete.idx.xz
  45. awk '$5 >= "'"$1"'" {
  46. if (!system("wget --method=HEAD " $9))
  47. print
  48. }
  49. ' snapshot.idx | sort -u | xz > snapshot.idx.xz
  50. rm snapshot.idx snapshot.complete.idx
  51. rmdir "$0.running"
  52. exit 0
  53. fi
  54. # minimize file
  55. tmpfname="tmp.snapinf.asc"
  56. awk '
  57. output != 1 && tolower($1) == "message-id:" {
  58. print
  59. next
  60. }
  61. $0 == "-----BEGIN PGP SIGNED MESSAGE-----" {
  62. output = 1
  63. }
  64. output == 1 {
  65. print
  66. }
  67. $0 == "-----END PGP SIGNATURE-----" {
  68. output = 0
  69. }' "$1" > "$tmpfname"
  70. if ! gpg --verify "$tmpfname"; then
  71. echo 'failed verify'
  72. rm "$tmpfname"
  73. rmdir "$0.running"
  74. exit 1
  75. fi
  76. # process file
  77. awk -f ./mksnapidx.awk "$tmpfname" > additional
  78. rm "$tmpfname"
  79. # only check if there isn't more to come
  80. if [ x"$more" = x"1" ]; then
  81. (cat snapshot.idx || :; cat additional) > snapshot.idx.new
  82. (cat snapshot.complete.idx || :; cat additional) > snapshot.complete.idx.new
  83. else
  84. (xzcat snapshot.idx.xz; cat additional) | sort -u | awk '
  85. {
  86. if (!system("wget --method=HEAD " $9))
  87. print
  88. }
  89. ' > snapshot.idx.new
  90. xz snapshot.idx.new
  91. (xzcat snapshot.complete.idx.xz || :; cat additional) | sort -u > snapshot.complete.idx.new
  92. xz snapshot.complete.idx.new
  93. fi
  94. rm additional
  95. # install new indexes
  96. if [ x"$more" = x"1" ]; then
  97. mv snapshot.idx.new snapshot.idx
  98. mv snapshot.complete.idx.new snapshot.complete.idx
  99. else
  100. mv snapshot.idx.new.xz snapshot.idx.xz
  101. mv snapshot.complete.idx.new.xz snapshot.complete.idx.xz
  102. fi
  103. rmdir "$0.running"