mirror of the now-defunct rocklinux.org
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.

123 lines
3.9 KiB

  1. #!/bin/bash
  2. #
  3. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  4. #
  5. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  6. # Please add additional copyright information _after_ the line containing
  7. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  8. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  9. #
  10. # ROCK Linux: rock-src/scripts/Create-CkSumPatch
  11. # ROCK Linux is Copyright (C) 1998 - 2004 Clifford Wolf
  12. #
  13. # This program is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version. A copy of the GNU General Public
  17. # License can be found at Documentation/COPYING.
  18. #
  19. # Many people helped and are helping developing ROCK Linux. Please
  20. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  21. # file for details.
  22. #
  23. # --- ROCK-COPYRIGHT-NOTE-END ---
  24. . scripts/functions
  25. override=0
  26. files=''
  27. while [ "$1" ]; do
  28. case "$1" in
  29. -override) override=1 ; shift ;;
  30. -repository) files="$files `echo package/$2/*/*.desc`" ; shift ; shift ;;
  31. -all)
  32. files="$files $( egrep -l '^\[D\] +0+ ' package/*/*/*.desc )"
  33. files="$files $( egrep -l '^0+ ' target/*/download.txt target/*/*/download.txt )"
  34. shift ;;
  35. -*)
  36. echo "Usage:"
  37. echo "./scripts/Create-CkSumPatch [options] <package-name(s)> <target-file(s)> \\"
  38. echo " <desc-file(s)> -repository <repository>"
  39. echo
  40. echo " Compute checksums for (source) files mentioned in .desc files and output"
  41. echo " a patch which can be applied to the ROCK sources to update the checksums."
  42. echo " Only checksums for files that have the checksum set to 0 will be computed."
  43. echo " Process single packages, a single repository, single .desc files or files"
  44. echo " from a target directory (e.g. target/bootdisk/download.txt)."
  45. echo
  46. echo "Options:"
  47. echo " -override create new checksums even if old ones are not equal 0;"
  48. echo " checksums set to X are not changed anyhow"
  49. echo " -help show this help text"
  50. echo
  51. echo "Example: create a cksum patch and apply it"
  52. echo " ./scripts/Create-CkSumPatch gcc -repository stf target/bootdisk/download.txt \\"
  53. echo " package/base/dietlibc/dietlibc.desc | patch -p1"
  54. echo
  55. exit
  56. ;;
  57. target/*) files="$files $1" ; shift ;;
  58. *.desc) files="$files $1" ; shift ;;
  59. *) files="$files `echo package/*/$1/$1.desc`" ; shift ;;
  60. esac
  61. done
  62. # cksum_file path-to-desc-or-target-file
  63. cksum_file() {
  64. case "$1" in
  65. target/*)
  66. has_D='cat'
  67. sedscript='s,^[0-9]* *$file,$newcksum $file,'
  68. ;;
  69. *.desc)
  70. has_D='fgrep "[D]" | sed "s/[[]D[^ ]*//"'
  71. sedscript='s,\[D\] *[0-9]* *$file,[D] $newcksum $file,'
  72. ;;
  73. *)
  74. echo "!!! File type not recognized" >&2
  75. return -1
  76. esac
  77. if [ ! -f "$1" ]; then
  78. echo "!!! File not found: $1" >&2
  79. return -1
  80. fi
  81. cp $1 /tmp/$$
  82. eval "egrep -v '^#' $1 | $has_D" | while read cksum file url flags; do
  83. [ "$cksum" = 'X' ] && continue
  84. [ "$cksum" != '0' -a "$override" = '0' ] && continue
  85. gzfile=`source_file cksum $file url $flags`
  86. bzfile="`echo "$gzfile" | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  87. if [ ! -f "$bzfile" ]; then
  88. echo "!!! File not present: $bzfile" >&2
  89. continue
  90. fi
  91. if [[ "$bzfile" = *.bz2 ]] || [[ "$bzfile" = *.tbz2 ]] ; then
  92. echo -n "$bzfile (bzip2): " >&2
  93. newcksum="`bunzip2 < $bzfile | cksum | cut -f1 -d' '`"
  94. else
  95. echo -n "$gzfile (raw): " >&2
  96. newcksum="`cksum $gzfile | cut -f1 -d' '`"
  97. fi
  98. echo $newcksum >&2
  99. if [ "$cksum" != 0 -a "$cksum" != "$newcksum" ]; then
  100. echo "!!! Checksum of $file changed (was $cksum)." >&2
  101. fi
  102. eval "sed \"$sedscript\" -i /tmp/$$"
  103. done
  104. diff -u ./$1 /tmp/$$ | sed -e "s,^+++ /tmp/$$,+++ ./$1,g"
  105. rm -f /tmp/$$
  106. }
  107. echo "Creating checksum patch ..." >&2
  108. for f in $files; do
  109. cksum_file $f
  110. done