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.

170 lines
3.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-list-pkg
  6. # Copyright (C) 2007 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: generate lists needed by other commands
  16. set -e
  17. [ -n "$SDEROOT" ] ||
  18. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  19. . $SDEROOT/lib/libsde.in
  20. list_usage() {
  21. local progname=${0##*/}
  22. cat <<EOT
  23. Usage: $progname [--arch <arch>]
  24. $progname [--cfg <config>] [--extenders] [--repositories] [ITEMS...]
  25. EOT
  26. }
  27. list_arch() {
  28. local repo= arch="$1"
  29. local files=
  30. if [ ! -s $SDEROOT/architecture/$arch/archtest.out ]; then
  31. echo_error "wrong architecture ($arch) specified, aborting."
  32. return 1
  33. fi
  34. # the .awk file needs complete $SDEROOT relative .desc locations
  35. cd $SDEROOT
  36. for repo in package/*; do
  37. files=$( ls -1d $repo/*/*.desc 2> /dev/null )
  38. if [ -n "$files" ]; then
  39. gawk -f ./lib/sde-package/package-list.awk -v "arch=$arch" $files
  40. fi
  41. done | sort -k 3
  42. }
  43. list_desc_extenders() {
  44. local repo= pkg= pattern= confdir=
  45. if [ $# -eq 0 ]; then
  46. return
  47. elif [ $# -eq 1 ]; then
  48. pattern=$1
  49. else
  50. pattern="{$( echo $* | tr ' ' ',' )}"
  51. fi
  52. for repo in $( cd "$SDEROOT/package"; ls -1d * 2> /dev/null ); do
  53. ( cd "$SDEROOT"; eval ls -1d package/$repo/*/pkg_${pattern}_{pre,post}.conf 2> /dev/null | cut -d/ -f-3 | sort -u )
  54. done | while read confdir; do
  55. pkg=${confdir##*/}
  56. echo $confdir/$pkg.desc
  57. done
  58. }
  59. list_desc_repo() {
  60. local repo="$1" pkg= desc=
  61. if [ -d "$SDEROOT/package/$repo/" ]; then
  62. set -- $( cd "$SDEROOT/package/$repo/"; ls -1d * 2> /dev/null )
  63. for pkg; do
  64. desc="package/$repo/$pkg/$pkg.desc"
  65. if [ -f "$SDEROOT/$desc" ]; then
  66. echo "$desc"
  67. fi
  68. done
  69. if [ -n "$extenders" ]; then
  70. # get desc of extenders of those packages
  71. list_desc_extenders "$@"
  72. fi
  73. fi
  74. }
  75. list_desc() {
  76. local config="$1"
  77. local repo= file= pkg= desc=
  78. shift;
  79. if [ -z "$config" ]; then
  80. if [ $# -eq 0 ]; then
  81. # no config, use the whole db
  82. for repo in $( cd "$SDEROOT/package"; ls -1d * 2> /dev/null ); do
  83. extenders= list_desc_repo "$repo"
  84. done
  85. elif [ -z "$repositories" ]; then
  86. # no config, but a given set of packages
  87. for pkg; do
  88. desc=$( cd "$SDEROOT"; ls -1d package/*/$pkg/$pkg.desc )
  89. if [ -f "$SDEROOT/$desc" ]; then
  90. echo "$desc"
  91. fi
  92. done
  93. if [ -n "$extenders" ]; then
  94. # get desc of extenders of those packages
  95. list_desc_extenders "$@"
  96. fi
  97. else
  98. for repo; do
  99. list_desc_repo "$repo"
  100. done
  101. fi
  102. elif [ -r "$SDEROOT/config/$config/packages" ]; then
  103. echo_abort 1 "Not yet implemented"
  104. else
  105. echo_abort -1 "$config: config not found."
  106. fi
  107. }
  108. arch=
  109. config=
  110. mode=desc
  111. extenders=
  112. repositories=
  113. shortopts='a:c:r'
  114. longopts='arch:,cfg:,extenders,repositories'
  115. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  116. if [ $? -ne 0 ]; then
  117. list_usage
  118. exit -1
  119. fi
  120. # load new arguments list
  121. eval set -- "$options"
  122. # arguments
  123. while [ $# -gt 0 ]; do
  124. case "$1" in
  125. -a|--arch) mode=arch
  126. arch="$2"; shift ;;
  127. -c|--cfg) config="$2"; shift ;;
  128. -r|--repositories)
  129. repositories=yes ;;
  130. --extenders)
  131. extenders=yes ;;
  132. --) shift; break ;;
  133. *) echo_abort 1 "Unknown argument '$1', aborting."
  134. esac
  135. shift
  136. done
  137. case "$mode" in
  138. arch) list_arch "$arch" ;;
  139. desc) list_desc "$config" "$@" ;;
  140. *) list_usage ;;
  141. esac