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.

166 lines
4.0 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=${0##*/}
  23. cat <<EOT
  24. Usage: ${progname//-/ } [--location <url>] [<package>] [<version>]
  25. Updates a package (which is autodetected if you are on it) to a
  26. given version, or simply download and regenerate checksums.
  27. Using --location you are able to specify which will be the new
  28. download location for this update.
  29. ${progname//-/ } [--no-location] --md5 <url> (Alias: up)
  30. Updates a set of packages based on a remote .md5 file
  31. Using --no-location you tell the tool to not assume the download
  32. location of the md5 file for the updates but keep their individual
  33. download locations.
  34. EOT
  35. }
  36. shortopts=''
  37. longopts='help,location:,no-location,md5:'
  38. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  39. if [ $? -ne 0 ]; then
  40. update_usage
  41. exit -1
  42. fi
  43. # load new arguments list
  44. eval set -- "$options"
  45. location=
  46. nolocation=
  47. md5file=
  48. while [ $# -gt 0 ]; do
  49. case "$1" in
  50. --help)
  51. update_usage
  52. exit 0 ;;
  53. --location)
  54. location=$2; shift
  55. ;;
  56. --no-location)
  57. nolocation=yes
  58. ;;
  59. --md5)
  60. md5file=$2; shift
  61. ;;
  62. --) shift; break ;;
  63. *) echo_abort 1 "Unknown argument '$1', aborting."
  64. esac
  65. shift
  66. done
  67. update_patch_package() {
  68. local descfile="$1" ver="$2" location="$3"
  69. local oldver= sedopt=
  70. local tmpfile=$( mktemp )
  71. oldver=$( sed -n -e 's,^\[V\][ \t]\+\([^ \t]\+\)[ \t]*,\1,p' "$descfile" | head -n 1 )
  72. echo_info "$pkg ($oldver -> $ver)"
  73. awk -f $SDEROOT/lib/sde-package/package-update.awk -v "ver=$ver" -v "location=$location" "$descfile" > $tmpfile
  74. if diff -u $descfile $tmpfile; then
  75. echo_warning "No change detected."
  76. else
  77. cp $tmpfile "$descfile"
  78. fi
  79. rm -f $tmpfile
  80. }
  81. update_package() {
  82. local pkg="$1" ver="$2" location="$3"
  83. local confdir=$( package_confdir "$pkg" )
  84. local descfile="${confdir}/${pkg}.desc"
  85. local oldver=
  86. if [ -z "$confdir" -o ! -f "$descfile" ]; then
  87. echo_error "Package '$pkg' doesn't exist."
  88. return 1
  89. elif [ -z "$ver" ]; then
  90. echo_info "Updating checksum for $pkg."
  91. else
  92. update_patch_package "$descfile" "$ver" "$location"
  93. fi
  94. cd "$SDEROOT"
  95. ./bin/sde-download -q "$pkg" && ./lib/sde-package/patch-cksum.sh "$pkg" | patch -p0
  96. }
  97. update_package_md5() {
  98. local md5="$1" baseurl=
  99. local nolocation= location=
  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. baseurl="${md5%/*}"
  107. $SDEROOT/bin/sde-parse-md5 "$md5" | while read pkg ver file; do
  108. if [ -z "$nolocation" ]; then
  109. location="$baseurl/$file";
  110. update_package "$pkg" "$ver" "${location%/*}/"
  111. else
  112. update_package "$pkg" "$ver"
  113. fi
  114. done
  115. }
  116. if [ -n "$md5file" ]; then
  117. update_package_md5 "$md5file" ${nolocation:+--no-location}
  118. return $?
  119. elif [ $# -eq 2 ]; then
  120. # package and version
  121. pkg="$( echo "$1" | tr A-Z a-z)"
  122. ver="$2"
  123. elif [ $# -eq 1 ]; then
  124. # package or version?
  125. pkg="$( echo "$1" | tr A-Z a-z)"
  126. if [ ! -d "$( package_confdir "$pkg" )" ]; then
  127. pkg="$( package_autodetect )"
  128. ver="$1"
  129. fi
  130. elif [ $# -eq 0 ]; then
  131. # can i refresh an autodetected package?
  132. pkg=$( package_autodetect )
  133. else
  134. echo_error "Invalid Syntax."
  135. update_usage
  136. exit 1
  137. fi
  138. if [ -n "$pkg" ]; then
  139. update_package "$pkg" "$ver" "${location}"
  140. else
  141. echo_error "I could't guess which package you want to update."
  142. update_usage
  143. exit 2
  144. fi