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.

114 lines
3.0 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-package/update.in
  5. # Copyright (C) 2006 - 2007 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; version 2 of the License. A copy of the
  12. # GNU General Public License can be found in the file COPYING.
  13. # --- SDE-COPYRIGHT-NOTE-END ---
  14. package_patch_update() {
  15. local descfile="$1" ver="$2" location="$3"
  16. local oldver= sedopt=
  17. local tmpfile=$( mktemp )
  18. oldver=$( sed -n -e 's,^\[V\][ \t]\+\([^ \t]\+\)[ \t]*,\1,p' "$descfile" | head -n 1 )
  19. echo_info "$pkg ($oldver -> $ver)"
  20. awk -f $SDEROOT/lib/sde-package/package-update.awk -v "ver=$ver" -v "location=$location" "$descfile" > $tmpfile
  21. if diff -u $descfile $tmpfile; then
  22. echo_warning "No change detected."
  23. else
  24. cp $tmpfile "$descfile"
  25. fi
  26. rm -f $tmpfile
  27. }
  28. package_do_update() {
  29. local pkg="$1" ver="$2" location="$3"
  30. local confdir=$( ls -1d "$SDEROOT/package/"*"/$pkg" 2> /dev/null )
  31. local descfile="${confdir}/${pkg}.desc"
  32. local oldver=
  33. if [ -z "$confdir" -o ! -f "$descfile" ]; then
  34. echo_error "Package '$pkg' doesn't exist."
  35. return 1
  36. elif [ -z "$ver" ]; then
  37. echo_info "Updating checksum for $pkg."
  38. else
  39. package_patch_update "$descfile" "$ver" "$location"
  40. fi
  41. cd "$SDEROOT"
  42. ./bin/sde-download -q "$pkg" && ./lib/sde-package/patch-cksum.sh "$pkg" | patch -p0
  43. }
  44. package_update_md5() {
  45. local md5="$1" baseurl=
  46. local nolocation= location=
  47. shift
  48. echo_info "Loading MD5 file from '$md5'"
  49. if [ "$1" == "--no-location" ]; then
  50. nolocation=yes; shift
  51. echo_info "(Using individual download locations)"
  52. fi
  53. baseurl="${md5%/*}"
  54. $SDEROOT/bin/sde-parse-md5 "$md5" | while read pkg ver file; do
  55. if [ -z "$nolocation" ]; then
  56. location="$baseurl/$file";
  57. package_do_update "$pkg" "$ver" "${location%/*}/"
  58. else
  59. package_do_update "$pkg" "$ver"
  60. fi
  61. done
  62. }
  63. package_update() {
  64. local pkg= ver=
  65. local nolocation=
  66. local location=
  67. if [ "$1" == "--no-location" ]; then
  68. nolocation=yes; shift
  69. elif [ "$1" == "--location" ]; then
  70. location="$2"; shift 2
  71. fi
  72. if [ "$1" == "--md5" ]; then
  73. package_update_md5 "$2" ${nolocation:+--no-location}
  74. return $?
  75. elif [ $# -eq 2 ]; then
  76. # package and version
  77. pkg="$( echo "$1" | tr A-Z a-z)"
  78. ver="$2"
  79. elif [ $# -eq 1 ]; then
  80. # package or verion?
  81. pkg="$( echo "$1" | tr A-Z a-z)"
  82. if [ ! -d "$( echo "$SDEROOT/package/"*"/$pkg/" )" ]; then
  83. pkg="$( package_autodetect )"
  84. ver="$1"
  85. fi
  86. elif [ $# -eq 0 ]; then
  87. # can i refresh an autodetected package?
  88. pkg=$( package_autodetect )
  89. else
  90. echo_error "Invalid Syntax."
  91. package_usage
  92. return 1
  93. fi
  94. if [ -n "$pkg" ]; then
  95. package_do_update "$pkg" "$ver" "${location}"
  96. else
  97. echo_error "I could't guess which package you want to update."
  98. package_usage
  99. return 2
  100. fi
  101. }