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.

119 lines
3.7 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(s)> <target-file(s)> \\"
  34. echo " <desc-file(s)> -repository <repository>"
  35. echo
  36. echo " Compute checksums for (source) files mentioned in .desc files and output"
  37. echo " a patch which can be applied to the ROCK sources to update the checksums."
  38. echo " Only checksums for files that have the checksum set to 0 will be computed."
  39. echo " Process single packages, a single repository, single .desc files or files"
  40. echo " from a target directory (e.g. target/bootdisk/download.txt)."
  41. echo
  42. echo "Options:"
  43. echo " -override create new checksums even if old ones are not equal 0;"
  44. echo " checksums set to X are not changed anyhow"
  45. echo " -help show this help text"
  46. echo
  47. echo "Example: create a cksum patch and apply it"
  48. echo " ./scripts/Create-CkSumPatch gcc -repository stf target/bootdisk/download.txt \\"
  49. echo " package/base/dietlibc/dietlibc.desc | patch -p0"
  50. echo
  51. exit
  52. ;;
  53. target/*) files="$files $1" ; shift ;;
  54. *.desc) files="$files $1" ; shift ;;
  55. *) files="$files `echo package/*/$1/$1.desc`" ; shift ;;
  56. esac
  57. done
  58. # cksum_file path-to-desc-or-target-file
  59. cksum_file() {
  60. case "$1" in
  61. target/*)
  62. has_D='cat'
  63. sedscript='s,^[0-9]* *$file,$newcksum $file,'
  64. ;;
  65. *.desc)
  66. has_D='fgrep "[D]" | sed "s/[[]D[^ ]*//"'
  67. sedscript='s,\[D\] *[0-9]* *$file,[D] $newcksum $file,'
  68. ;;
  69. *)
  70. echo "!!! File type not recognized" >&2
  71. return -1
  72. esac
  73. if [ ! -f "$1" ]; then
  74. echo "!!! File not found: $1" >&2
  75. return -1
  76. fi
  77. cp $1 /tmp/$$
  78. eval "egrep -v '^#' $1 | $has_D" | while read cksum file url flags; do
  79. [ "$cksum" = 'X' ] && continue
  80. [ "$cksum" != '0' -a "$override" = '0' ] && continue
  81. gzfile=`source_file cksum $file url $flags`
  82. bzfile="`echo "$gzfile" | sed 's,\.\(t\?\)\(gz\|Z\)$,.\1bz2,'`"
  83. if [ ! -f "$bzfile" ]; then
  84. echo "!!! File not present: $bzfile" >&2
  85. continue
  86. fi
  87. if [[ "$bzfile" = *.bz2 ]] || [[ "$bzfile" = *.tbz2 ]] ; then
  88. echo -n "$bzfile (bzip2): " >&2
  89. newcksum="`bunzip2 < $bzfile | cksum | cut -f1 -d' '`"
  90. else
  91. echo -n "$gzfile (raw): " >&2
  92. newcksum="`cksum $gzfile | cut -f1 -d' '`"
  93. fi
  94. echo $newcksum >&2
  95. if [ "$cksum" != 0 -a "$cksum" != "$newcksum" ]; then
  96. echo "!!! Checksum of $file changed (was $cksum)." >&2
  97. fi
  98. eval "sed \"$sedscript\" -i /tmp/$$"
  99. done
  100. diff -u $1 /tmp/$$
  101. rm -f /tmp/$$
  102. }
  103. echo "Creating checksum patch ..." >&2
  104. for f in $files; do
  105. cksum_file $f
  106. done