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.

164 lines
3.9 KiB

  1. #!/bin/sh
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-update-package
  6. # Copyright (C) 2006 - 2008 The OpenSDE Project
  7. #
  8. # More information can be found in the files COPYING and README.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License. A copy of the
  13. # GNU General Public License can be found in the file COPYING.
  14. # --- SDE-COPYRIGHT-NOTE-END ---
  15. #Description: Updates a package to a new upstream version
  16. #Alias: pkg
  17. [ -n "$SDEROOT" ] ||
  18. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  19. . "$SDEROOT/lib/libsde.in"
  20. . "$SDEROOT/lib/sde-package.in"
  21. update_usage() {
  22. local progname=
  23. progname="$(echo ${0##*/} | tr - ' ')"
  24. cat <<EOT
  25. Usage: $progname [--location <url>] [<package>] [<version>]
  26. Updates a package (which is autodetected if you are on it) to a
  27. given version, or simply download and regenerate checksums.
  28. Using --location you are able to specify which will be the new
  29. download location for this update.
  30. $progname [--no-location] --md5 <url> (Alias: up)
  31. Updates a set of packages based on a remote .md5 file
  32. Using --no-location you tell the tool to not assume the download
  33. location of the md5 file for the updates but keep their individual
  34. download locations.
  35. EOT
  36. }
  37. shortopts=
  38. longopts='help,location:,no-location,md5:'
  39. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  40. if [ $? -ne 0 ]; then
  41. update_usage
  42. exit -1
  43. fi
  44. # load new arguments list
  45. eval set -- "$options"
  46. location=
  47. nolocation=
  48. md5file=
  49. while [ $# -gt 0 ]; do
  50. case "$1" in
  51. --help)
  52. update_usage
  53. exit 0 ;;
  54. --location)
  55. location=$2; shift
  56. ;;
  57. --no-location)
  58. nolocation=yes
  59. ;;
  60. --md5)
  61. md5file=$2; shift
  62. ;;
  63. --) shift; break ;;
  64. *) echo_abort 1 "Unknown argument '$1', aborting."
  65. esac
  66. shift
  67. done
  68. update_patch_package() {
  69. local descfile="$1" ver="$2" location="$3"
  70. local oldver= sedopt=
  71. local tmpfile=$( mktemp )
  72. oldver=$( sed -n -e 's,^\[V\][ \t]\+\([^ \t]\+\)[ \t]*,\1,p' "$descfile" | head -n 1 )
  73. echo_info "$pkg ($oldver -> $ver)"
  74. gawk -f $SDEROOT/lib/sde-package/package-update.awk -v "ver=$ver" -v "location=$location" "$descfile" > $tmpfile
  75. if diff -u $descfile $tmpfile; then
  76. echo_warning "No change detected."
  77. else
  78. cp $tmpfile "$descfile"
  79. fi
  80. rm -f $tmpfile
  81. }
  82. update_package() {
  83. local pkg="$1" ver="$2" location="$3"
  84. local confdir=$( package_confdir "$pkg" )
  85. local descfile="${confdir}/${pkg}.desc"
  86. local oldver=
  87. if [ -z "$confdir" -o ! -f "$descfile" ]; then
  88. echo_error "Package '$pkg' doesn't exist."
  89. return 1
  90. elif [ -z "$ver" ]; then
  91. echo_info "Updating checksum for $pkg."
  92. else
  93. update_patch_package "$descfile" "$ver" "$location"
  94. fi
  95. cd "$SDEROOT"
  96. ./bin/sde-download -q "$pkg" && ./lib/sde-package/patch-cksum.sh "$pkg" | patch -p0
  97. }
  98. update_package_md5() {
  99. local md5="$1" nolocation=
  100. shift
  101. echo_info "Loading MD5 file from '$md5'"
  102. if [ "$1" = "--no-location" ]; then
  103. nolocation=yes; shift
  104. echo_info "(Using individual download locations)"
  105. fi
  106. $SDEROOT/bin/sde-parse-md5 "$md5" | while read pkg ver file; do
  107. if [ -z "$nolocation" ]; then
  108. update_package "$pkg" "$ver" "${file%/*}/"
  109. else
  110. update_package "$pkg" "$ver"
  111. fi
  112. done
  113. }
  114. if [ -n "$md5file" ]; then
  115. update_package_md5 "$md5file" ${nolocation:+--no-location}
  116. exit $?
  117. elif [ $# -eq 2 ]; then
  118. # package and version
  119. pkg="$( echo "$1" | tr A-Z a-z)"
  120. ver="$2"
  121. elif [ $# -eq 1 ]; then
  122. # package or version?
  123. pkg="$( echo "$1" | tr A-Z a-z)"
  124. if [ ! -d "$( package_confdir "$pkg" )" ]; then
  125. pkg="$( package_autodetect )"
  126. ver="$1"
  127. fi
  128. elif [ $# -eq 0 ]; then
  129. # can i refresh an autodetected package?
  130. pkg=$( package_autodetect )
  131. else
  132. echo_error "Invalid Syntax."
  133. update_usage
  134. exit 1
  135. fi
  136. if [ -n "$pkg" ]; then
  137. update_package "$pkg" "$ver" "${location}"
  138. else
  139. echo_error "I could't guess which package you want to update."
  140. update_usage
  141. exit 2
  142. fi