OpenSDE Framework (without history before r20070)
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.

97 lines
2.5 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: lib/sde-package/patch-cksum.sh
  6. # Copyright (C) 2006 - 2007 The OpenSDE Project
  7. # Copyright (C) 2004 - 2006 The T2 SDE Project
  8. # Copyright (C) 1998 - 2003 Clifford Wolf
  9. #
  10. # More information can be found in the files COPYING and README.
  11. #
  12. # This program is free software; you can redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as published by
  14. # the Free Software Foundation; version 2 of the License. A copy of the
  15. # GNU General Public License can be found in the file COPYING.
  16. # --- SDE-COPYRIGHT-NOTE-END ---
  17. . lib/functions.in
  18. override=0
  19. files=''
  20. usage()
  21. {
  22. echo "Usage:"
  23. echo "./scripts/Create-CkSumPatch [options] <package-name>"
  24. echo "./scripts/Create-CkSumPatch [options] <target-name>"
  25. echo "./scripts/Create-CkSumPatch [options] <file-path>"
  26. echo " "
  27. echo "Options:"
  28. echo " -override Create new cksum if old one should be valid."
  29. echo " -help This."
  30. }
  31. while [ "$1" ]; do
  32. case "$1" in
  33. -override) override=1 ; shift ;;
  34. -repository) files="$files `echo package/$2/*/*.desc`" ; shift ; shift ;;
  35. -*|-help) usage ; exit
  36. ;;
  37. target/*) files="$files $arg" ; shift ;;
  38. *.desc) files="$files $arg" ; shift ;;
  39. *) files="$files `echo package/*/$1/$1.desc`" ; shift ;;
  40. esac
  41. done
  42. # cksum_file path-to-desc-or-target-file
  43. cksum_file() {
  44. case "$1" in
  45. target/*)
  46. has_D='cat'
  47. sedscript='s,^[0-9]* *$file,$newcksum $file,'
  48. ;;
  49. *.desc)
  50. has_D='fgrep "[D]" | sed "s/[[]D[^ ]*//"'
  51. sedscript='s,\[D\] *[0-9]* *$file,[D] $newcksum $file,'
  52. ;;
  53. *)
  54. echo "!!! File type not recognized" >&2
  55. return -1
  56. esac
  57. if [ ! -f "$1" ]; then
  58. echo "!!! File not found: $1" >&2
  59. return -1
  60. fi
  61. cp $1 /tmp/$$
  62. eval "egrep -v '^#' $1 | $has_D" | while read cksum file url args; do
  63. [ "$cksum" = 'X' ] && continue
  64. [ "$cksum" != '0' -a "$override" = '0' ] && continue
  65. gzfile=`source_file cksum $file $url $flags`
  66. bzfile="`bz2filename "$gzfile"`"
  67. if [ ! -f "$bzfile" ]; then
  68. echo "!!! File not present: $bzfile" >&2
  69. continue
  70. fi
  71. echo -n "$bzfile: " >&2
  72. newcksum=$( sh lib/sde-download/cksum.sh "$bzfile" | cut -d' ' -f2 )
  73. echo $newcksum >&2
  74. if [ "$cksum" != 0 -a "$cksum" != "$newcksum" ]; then
  75. echo "!!! Checksum of $file changed (was $cksum)." >&2
  76. fi
  77. eval "sed \"$sedscript\" -i /tmp/$$"
  78. done
  79. diff -u ./$1 /tmp/$$
  80. rm -f /tmp/$$
  81. }
  82. for f in $files; do
  83. cksum_file $f
  84. done