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.

78 lines
1.9 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: lib/sde-package.in
  5. # Copyright (C) 2006 - 2009 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_autodetect() {
  15. pwd -P | sed -n -e "s,^$SDEROOT/package/[^/]*/\([^/]*\)\(/.*\)\?$,\1,p"
  16. }
  17. package_autodetect_repo() {
  18. pwd -P | sed -n -e "s,^$SDEROOT/package/\([^/]*\)\(/.*\)\?,\1,p"
  19. }
  20. package_exists() {
  21. local x=$(ls -1 "$SDEROOT/package"/*/"$1/$1.desc" 2> /dev/null)
  22. [ -s "$x" ]
  23. }
  24. package_confdir() {
  25. ls -1d "$SDEROOT/package"/*/"$1" 2> /dev/null | head -n 1
  26. }
  27. package_parse() {
  28. local ref= list=
  29. for ref; do
  30. # sanitise
  31. ref=$(echo "$ref" | tr 'A-Z' 'a-z')
  32. if [ -d "$ref" ]; then
  33. list="$ref"
  34. elif expr "$ref" : '.*/' > /dev/null; then
  35. if [ -e "$ref" ]; then
  36. list="${ref%/*}"
  37. else
  38. list=$(eval "ls -1d '$SDEROOT/package'/$ref/")
  39. fi
  40. else
  41. list=$(eval "ls -1d '$SDEROOT/package'/*/$ref/")
  42. fi
  43. echo "$list" | while read dir; do
  44. (cd "$dir" && pwd -P)
  45. done | sed -n -e "s,^$SDEROOT/package/\([^/]*\)/\([^/]*\).*,\1/\2,p"
  46. done
  47. }
  48. # package_desc <pkg>
  49. #
  50. package_desc() {
  51. ls -1d "$SDEROOT/package"/*/"$1/$1.desc" 2> /dev/null | head -n 1
  52. }
  53. # package_tag <tag>
  54. #
  55. package_tag() {
  56. local tag=$(echo "$1" | tr 'a-z' 'A-Z')
  57. grep -e "^\(\[.*\)\?\[$tag\]" "$SDEROOT/etc/desc_format" |
  58. sed -e 's, *(\*) *$,,' -e 's,[\t ]\+, ,g' | tr -d '[]'
  59. }
  60. # package_desc_extract <descfile> <tag>
  61. #
  62. package_desc_extract() {
  63. local pattern=$(package_tag "$2" | sed -e '/ / {s/ \+/\\|/g;s/^/\\(/;s/$/\\)/;}')
  64. sed -n -e "s/^\[$pattern\][ \t]*//p;" "$1"
  65. }