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.

186 lines
4.0 KiB

  1. #!/bin/bash
  2. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. #
  5. # Filename: bin/sde-check-package
  6. # Copyright (C) 2009 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: Checks for possible updates of a list of packages
  16. #Alias: pkg ver version
  17. [ -n "$SDEROOT" ] ||
  18. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  19. . "$SDEROOT/lib/libsde.in"
  20. . "$SDEROOT/lib/sde-package.in"
  21. cachedir="$SDEROOT/tmp/checkver"
  22. check_usage() {
  23. local progname=$(echo ${0##*/} | tr '-' ' ')
  24. [ $# -eq 0 ] || echo_error "$@"
  25. cat <<-EOT
  26. Usage: $progname <pkg>*
  27. EOT
  28. exit 1
  29. }
  30. # parse arguments
  31. shortopts='?'
  32. longopts='help'
  33. options=$(getopt -o "$shortopts" -l "$longopts" -- "$@")
  34. [ $? -eq 0 ] || check_usage
  35. eval set -- "$options"
  36. while [ $# -gt 0 ]; do
  37. case "$1" in
  38. --help)
  39. check_usage
  40. ;;
  41. --)
  42. shift; break
  43. ;;
  44. -*)
  45. check_usage "$1: Not implemented"
  46. ;;
  47. *)
  48. break
  49. esac
  50. shift
  51. done
  52. # extract packages list
  53. #
  54. pkgs=
  55. while [ $# -gt 0 ]; do
  56. x=$(package_parse "$1" | tr '\n' ' ')
  57. if [ -n "$x" ]; then
  58. pkgs="$pkgs $x"
  59. else
  60. check_usage "$1: Invalid package"
  61. fi
  62. shift
  63. done
  64. [ -n "$pkgs" ] || check_usage
  65. check_package_update() {
  66. local pkg="$1" ver="$2" file="$3" dump="$4"
  67. local prefix= suffix= matches= found=
  68. # case 1, version is obvious part of the name
  69. if expr "$file" : ".*${ver//\./\\.}" > /dev/null; then
  70. prefix="${file%$ver*}"
  71. suffix="${file#$prefix$ver}"
  72. fi
  73. # case 2, known suffix and a dash separating prefix and version
  74. if [ -z "$prefix$suffix" ]; then
  75. suffix='\.tar\.\(gz\|bz2\)'
  76. prefix=$(echo "$file" | sed -n -e "s,^\(.*-\)\([0-9].*\)$suffix\$,\1,p")
  77. [ -n "$prefix" ] || suffix=
  78. fi
  79. if [ -n "$prefix$suffix" ]; then
  80. # if we have a prefix or suffix at this point
  81. found=$(sed -n -e "s,^$prefix\([0-9].*\)$suffix\$,\1,p" "$dump" | sort -u)
  82. else
  83. found=
  84. fi
  85. if [ -n "$found" ]; then
  86. found=$("$versionsort" $found | tac | sed -e "s|^${ver//./\.}\$|*$ver*|" | tr '\n' ' ')
  87. echo "$pkg ($ver) $file ($url) $found"
  88. else
  89. echo_warning "$pkg ($ver) $file ($url) nothing found."
  90. fi
  91. }
  92. download_url_dump() {
  93. lock "$dump"
  94. [ -e "$dump" ] ||
  95. "$SDEROOT/lib/sde-download/dump-tokenized.sh" "$url" > "$dump" 2> "$dump.stderr"
  96. unlock "$dump"
  97. }
  98. check_package() {
  99. local repo="${1%/*}" pkg="${1#*/}"
  100. local desc="$SDEROOT/package/$repo/$pkg/$pkg.desc"
  101. local cvurl=$(package_desc_extract "$desc" CV-URL)
  102. local ver=$(package_desc_extract "$desc" V)
  103. local x= y= file= url= protocol= dump=
  104. while read x file url; do
  105. case "$url" in
  106. -!*|!*)
  107. file="${url##*/}"
  108. url=$(echo "$url" | sed -e 's,^-\?!,,' -e 's,/[^/]*$,/,')
  109. ;;
  110. -*)
  111. url="${url#-}"
  112. ;;
  113. esac
  114. if [ -n "$cvurl" ]; then
  115. url="$cvurl"
  116. elif [ -s "$SDEROOT/etc/check_package.sed" ]; then
  117. # translate
  118. url=$(echo "$url" | sed -f "$SDEROOT/etc/check_package.sed")
  119. fi
  120. protocol="${url%%:*}"
  121. dump=$(echo "$url.out" | tr '?&:/ ' '_____')
  122. dump="$cachedir/$dump"
  123. case "$protocol" in
  124. http|https|ftp)
  125. download_url_dump
  126. ;;
  127. sourceforge)
  128. url="http://sourceforge.net/projects/${url#sourceforge://}files/"
  129. download_url_dump
  130. ;;
  131. *)
  132. echo_warning "$pkg: $protocol not supported."
  133. continue
  134. ;;
  135. esac
  136. if [ -s "$dump" ]; then
  137. check_package_update "$pkg" "$ver" "$file" "$dump"
  138. else
  139. echo_warning "$pkg ($ver) $file ($url) empty output."
  140. fi
  141. done < <(package_desc_extract "$desc" D)
  142. }
  143. mkdir -p "$cachedir" || exit $?
  144. # compile vsersionsort is missing
  145. #
  146. versionsort="$SDEROOT/bin/versionsort"
  147. versionsort_c="$SDEROOT/src/tools-source/versionsort.c"
  148. if [ "$versionsort_c" -nt "$versionsort" ]; then
  149. gcc -o "$versionsort" -Os -W -Wall "$versionsort_c" || exit $?
  150. fi
  151. trap ':' 'INT'
  152. for x in $pkgs; do
  153. check_package "$x" &
  154. done < /dev/null
  155. wait