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.
 
 
 
 

169 lines
4.5 KiB

  1. #!/bin/sh -
  2. #
  3. # Copyright 2018, 2022 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. #
  31. # Note: It appears that sometimes files can "disappear" from the server, so,
  32. # uncompress snapshot.complete.idx.xz to both snapshot.complete.idx and
  33. # snapshot.idx, and then run "sh addinfo.sh -c YYYYMMDD" with the oldest
  34. # known snapshot.
  35. usage() {
  36. echo "Usage: $0 [ -m ] <file>"
  37. echo "Usage: $0 -c <date>"
  38. echo ''
  39. echo 'Options:'
  40. echo ' -m Do not check what files are available. This is useful for'
  41. echo ' bulk import.'
  42. echo ' -c Complete a bulk import (previously using -m), and assume that'
  43. echo ' any snapshots before specified data are unfetchable.'
  44. echo ''
  45. echo 'date is specified as YYYYMMDD'
  46. if [ x"$1" != x"" ]; then
  47. exit $1
  48. fi
  49. }
  50. args=`getopt cm $*`
  51. if [ $? -ne 0 ]; then
  52. usage 2
  53. fi
  54. set -- $args
  55. while :; do
  56. case "$1" in
  57. -c)
  58. complete=1
  59. shift
  60. ;;
  61. -m)
  62. more=1
  63. shift
  64. ;;
  65. --)
  66. shift; break
  67. ;;
  68. esac
  69. done
  70. if [ x"$complete" = x"1" -a x"$more" = x"1" ]; then
  71. echo '-m and -c cannot be specified at the same time.'
  72. usage 2
  73. elif [ x"$complete" = x"1" -a $# -ne 1 ]; then
  74. echo 'must only specify a date with -c'
  75. usage 2
  76. elif [ x"$complete" != x"1" -a $# -ne 1 ]; then
  77. echo 'must specify exactly one file'
  78. usage 2
  79. fi
  80. while ! mkdir "$0.running"; do
  81. sleep 1;
  82. done
  83. export SNAPAID_SH=source
  84. . $(dirname $0)/snapaid.sh
  85. if [ x"$complete" = x"1" ]; then
  86. if [ ! -f snapshot.complete.idx ]; then
  87. echo 'snapshot.complete.idx does not exist, aborting...'
  88. rmdir "$0.running"
  89. exit 5
  90. fi
  91. if [ ! -f snapshot.idx ]; then
  92. echo 'snapshot.idx does not exist, aborting...'
  93. rmdir "$0.running"
  94. exit 5
  95. fi
  96. sort -u snapshot.complete.idx | xz > snapshot.complete.idx.new.xz
  97. awk '$5 == "xxx" || $5 >= "'"$1"'" {
  98. if (!system("wget --method=HEAD " $9))
  99. print
  100. }
  101. ' snapshot.idx | sort -u | xz > snapshot.idx.new.xz
  102. chmod 644 snapshot.idx.new.xz snapshot.complete.idx.new.xz
  103. mv snapshot.idx.new.xz snapshot.idx.xz
  104. mv snapshot.complete.idx.new.xz snapshot.complete.idx.xz
  105. rm snapshot.idx snapshot.complete.idx
  106. rmdir "$0.running"
  107. exit 0
  108. fi
  109. # minimize file
  110. tmpfname="tmp.snapinf.asc"
  111. minimizeemail < "$1" > "$tmpfname"
  112. if ! verifygpgfile "$tmpfname"; then
  113. echo 'failed verify'
  114. rm "$tmpfname"
  115. rmdir "$0.running"
  116. exit 1
  117. fi
  118. # process file
  119. awk -f ./mksnapidx.awk "$tmpfname" > additional
  120. rm "$tmpfname"
  121. # only check if there isn't more to come
  122. if [ x"$more" = x"1" ]; then
  123. echo queuing $(wc -l additional) entries
  124. (cat snapshot.idx 2>/dev/null || xzcat snapshot.idx.xz; cat additional) > snapshot.idx.new
  125. (cat snapshot.complete.idx 2>/dev/null || xzcat snapshot.complete.idx.xz; cat additional) > snapshot.complete.idx.new
  126. else
  127. (xzcat snapshot.idx.xz; cat additional) | sort -u | awk '
  128. {
  129. print "testing " $9 > "/dev/stderr"
  130. if (!system("wget --method=HEAD " $9))
  131. print
  132. }
  133. ' > snapshot.idx.new
  134. xz snapshot.idx.new
  135. (xzcat snapshot.complete.idx.xz || :; cat additional) | sort -u > snapshot.complete.idx.new
  136. xz snapshot.complete.idx.new
  137. fi
  138. rm additional
  139. # install new indexes
  140. if [ x"$more" = x"1" ]; then
  141. mv snapshot.idx.new snapshot.idx
  142. mv snapshot.complete.idx.new snapshot.complete.idx
  143. else
  144. chmod 644 snapshot.idx.new.xz snapshot.complete.idx.new.xz
  145. mv snapshot.idx.new.xz snapshot.idx.xz
  146. mv snapshot.complete.idx.new.xz snapshot.complete.idx.xz
  147. fi
  148. rmdir "$0.running"