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.

83 lines
2.0 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. try_list() {
  30. eval "cd '$SDEROOT/package' && ls -1d $1/ 2> /dev/null" |
  31. sed -e "s,^,$SDEROOT/package/,"
  32. }
  33. for ref; do
  34. # sanitise
  35. ref=$(echo "$ref" | tr 'A-Z.; ' 'a-z___')
  36. if [ -d "$ref" ]; then
  37. list="$ref"
  38. elif expr "$ref" : '.*/' > /dev/null; then
  39. if [ -e "$ref" ]; then
  40. list="${ref%/*}"
  41. else
  42. list=$(try_list "$ref")
  43. fi
  44. else
  45. list=$(try_list "*/$ref")
  46. fi
  47. echo "$list" | while read dir; do
  48. (cd "$dir" && pwd -P)
  49. done | sed -n -e "s,^$SDEROOT/package/\([^/]*\)/\([^/]*\).*,\1/\2,p"
  50. done
  51. }
  52. # package_desc <pkg>
  53. #
  54. package_desc() {
  55. ls -1d "$SDEROOT/package"/*/"$1/$1.desc" 2> /dev/null | head -n 1
  56. }
  57. # package_tag <tag>
  58. #
  59. package_tag() {
  60. local tag=$(echo "$1" | tr 'a-z' 'A-Z')
  61. grep -e "^\(\[.*\)\?\[$tag\]" "$SDEROOT/etc/desc_format" |
  62. sed -e 's, *(\*) *$,,' -e 's,[\t ]\+, ,g' | tr -d '[]'
  63. }
  64. # package_desc_extract <descfile> <tag>
  65. #
  66. package_desc_extract() {
  67. local pattern=$(package_tag "$2" | sed -e '/ / {s/ \+/\\|/g;s/^/\\(/;s/$/\\)/;}')
  68. sed -n -e "s/^\[$pattern\][ \t]*//p;" "$1"
  69. }