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.

128 lines
2.6 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-config-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: Alters the description of a package
  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. config_usage() {
  22. local progname=$(echo ${0##*/} | tr '-' ' ')
  23. [ $# -eq 0 ] || echo_error "$@"
  24. cat <<-EOT
  25. Usage: $progname <pkg>* <action> [<tag> [<value>]]*
  26. Actions:
  27. get returns the content of a tag
  28. set sets a tag value, removing any previous value
  29. add appends a new value for a tag
  30. remove removes a tag, optionally matching a pattern
  31. show dumps the fully description
  32. lint cleans the description
  33. EOT
  34. exit 1
  35. }
  36. # parse arguments
  37. shortopts='?'
  38. longopts='help'
  39. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  40. [ $? -eq 0 ] || config_usage
  41. eval set -- "$options"
  42. while [ $# -gt 0 ]; do
  43. case "$1" in
  44. --help)
  45. config_usage
  46. ;;
  47. --)
  48. shift; break
  49. ;;
  50. -*)
  51. config_usage "$1: Not implemented"
  52. ;;
  53. *)
  54. break
  55. esac
  56. shift
  57. done
  58. # extract packages list
  59. #
  60. pkgs=
  61. while [ $# -gt 1 ]; do
  62. case "$1" in
  63. get|set|add|remove|show|list) # action
  64. break;
  65. esac
  66. x=$(package_parse "$1" | tr '\n' ' ')
  67. if [ -n "$x" ]; then
  68. pkgs="$pkgs $x"
  69. shift
  70. else
  71. config_usage "$1: Invalid package"
  72. fi
  73. done
  74. pkgs=$(echo "$pkgs" | sed -e 's,^ \+,,' -e 's, \+$,,')
  75. [ -n "$pkgs" -a $# -gt 0 ] || config_usage
  76. action="$1"; shift
  77. tag2pattern() {
  78. local tag=$(echo "$tag" | tr 'a-z' 'A-Z')
  79. local pattern=$(grep -e '^\[' "$SDEROOT/etc/desc_format" | grep -e "\[$tag\]" |
  80. sed -e 's, *(\*) *$,,' -e 's, \+,\\|,g' | tr -d '[]')
  81. if [ -z "$pattern" ]; then
  82. return;
  83. elif expr "$pattern" : '.*|' > /dev/null; then
  84. pattern="\\($pattern\\)"
  85. fi
  86. echo "^\[$pattern\]"
  87. }
  88. case "$action" in
  89. get)
  90. # extract given tags
  91. pattern=
  92. for tag; do
  93. x=$(tag2pattern "$tag")
  94. if [ -n "$x" ]; then
  95. pattern="$pattern -e '$x'"
  96. else
  97. echo_error "$tag: Invalid tag"
  98. fi
  99. done
  100. files=
  101. for x in $pkgs; do
  102. files="$files $x/${x#*/}.desc"
  103. done
  104. cd "$SDEROOT/package"
  105. eval "grep $pattern $files"
  106. ;;
  107. *)
  108. echo_error "$action: Not yet implemented."
  109. esac