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.

109 lines
3.1 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 - 2003 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. -*)
  32. echo "Usage:"
  33. echo "./scripts/Create-CkSumPatch [options] <package-name>"
  34. echo "./scripts/Create-CkSumPatch [options] <target-name>"
  35. echo "./scripts/Create-CkSumPatch [options] <file-path>"
  36. echo "./scripts/Create-CkSumPatch [options] -repository <repo-name>"
  37. echo " "
  38. echo "Options:"
  39. echo " -override Create new cksum if old one should be valid."
  40. echo " -help This."
  41. exit
  42. ;;
  43. target/*) files="$files $1" ; shift ;;
  44. *.desc) files="$files $1" ; shift ;;
  45. *) files="$files `echo package/*/$1/$1.desc`" ; shift ;;
  46. esac
  47. done
  48. # cksum_file path-to-desc-or-target-file
  49. cksum_file() {
  50. case "$1" in
  51. target/*)
  52. has_D='cat'
  53. sedscript='s,^[0-9]* *$file,$newcksum $file,'
  54. ;;
  55. *.desc)
  56. has_D='fgrep "[D]" | sed "s/[[]D[^ ]*//"'
  57. sedscript='s,\[D\] *[0-9]* *$file,[D] $newcksum $file,'
  58. ;;
  59. *)
  60. echo "!!! File type not recognized" >&2
  61. return -1
  62. esac
  63. if [ ! -f "$1" ]; then
  64. echo "!!! File not found: $1" >&2
  65. return -1
  66. fi
  67. cp $1 /tmp/$$
  68. eval "egrep -v '^#' $1 | $has_D" | while read cksum file url flags; do
  69. [ "$cksum" = 'X' ] && continue
  70. [ "$cksum" != '0' -a "$override" = '0' ] && continue
  71. gzfile=`source_file cksum $file url $flags`
  72. bzfile="`echo "$gzfile" | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  73. if [ ! -f "$bzfile" ]; then
  74. echo "!!! File not present: $bzfile" >&2
  75. continue
  76. fi
  77. if [[ "$bzfile" = *.bz2 ]] || [[ "$bzfile" = *.tbz2 ]] ; then
  78. echo -n "$bzfile (bzip2): " >&2
  79. newcksum="`bunzip2 < $bzfile | cksum | cut -f1 -d' '`"
  80. else
  81. echo -n "$gzfile (raw): " >&2
  82. newcksum="`cksum $gzfile | cut -f1 -d' '`"
  83. fi
  84. echo $newcksum >&2
  85. if [ "$cksum" != 0 -a "$cksum" != "$newcksum" ]; then
  86. echo "!!! Checksum of $file changed (was $cksum)." >&2
  87. fi
  88. eval "sed \"$sedscript\" -i /tmp/$$"
  89. done
  90. diff -u $1 /tmp/$$
  91. rm -f /tmp/$$
  92. }
  93. echo "Creating cksum.patch ..." >&2
  94. for f in $files; do
  95. cksum_file $f
  96. done