gen-sha1-list.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. ## Iterate through complete package archive to generate a complete list of SHA1
  3. ## command parameter 'init' will build from scratch. Very slow.
  4. root=/srv/apt-mirror
  5. archive=$root/mirror
  6. dest=/srv/http/htdocs/apt-sec/mirror/Sha1Sums
  7. var=$root/var
  8. NEW=$var/NEW
  9. ALL=$var/ALL
  10. action="$1"
  11. echo "Updating Sha1Sums.."
  12. shalist () {
  13. pkg="$1"
  14. tmp=$(mktemp -d)
  15. ar -t $pkg |grep -q data.tar.gz && ( ar p $pkg data.tar.gz | tar xzC $tmp || echo "Can't extract from $pkg" )
  16. ar -t $pkg |grep -q data.tar.bz2 && ( ar p $pkg data.tar.bz2 | tar xjC $tmp || echo "Can't extract from $pkg" )
  17. cd $tmp
  18. find . -type f -print0 |xargs -0 sha1sum |tee -a $dest.paths | cut -c -42|sed -e "s/ .*/::$(basename $pkg)/" >> $dest.pkgs
  19. cd /
  20. rm -rf $tmp || (echo Trying even harder...; chmod -R u+rwx $tmp; rm -rf $tmp)
  21. }
  22. case $action in
  23. "init")
  24. # delete and rebuild shalist
  25. echo "Reinit - deleting current SHA1 sums.."
  26. rm $dest.pkgs
  27. rm $dest.paths
  28. echo "Reinitializing SHA1 DB.."
  29. n=0
  30. for deb in $(find $archive -type f -iname \*.deb); do
  31. let n++
  32. printf "%5d\t$deb\n" $n
  33. shalist $deb
  34. done
  35. ;;
  36. "update")
  37. # record removed packets, remove sha1sums of packets recorded *last week*
  38. # delete packages from last week
  39. del=$var/DEL-$(date +%w)
  40. touch $del
  41. grep -v -F -f $del $dest.pkgs > $dest.pkgs.tmp
  42. mv $dest.pkgs.tmp $dest.pkgs
  43. echo -n > $del
  44. # record newly removed packages, overwriting last week's record
  45. for pkg in $(cut -c 43- $dest.pkgs|uniq); do
  46. grep -q \\/$pkg$ $ALL || echo $pkg >> $del
  47. done
  48. # add sha sums for new pkgs
  49. for deb in $(cat $NEW); do
  50. deb=$(echo $deb|sed 's/.*:\/\/'//);
  51. echo "Adding $pkg.."
  52. shalist $archive/$deb
  53. done
  54. # delete, so we don't use them again
  55. # (hopefully, apt-mirror does not need it...?)
  56. echo -n > $NEW
  57. ;;
  58. "nosha1")
  59. echo > $dest.pkgs
  60. echo > $dest.paths
  61. ;;
  62. *)
  63. echo
  64. echo "Usage: $0 (init|update)"
  65. echo
  66. exit
  67. esac
  68. ln $dest.pkgs $dest
  69. bzip2 -f $dest