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.

233 lines
5.4 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. [ -n "$SDEROOT" ] ||
  16. export SDEROOT=$( cd "${0%/*}/.."; pwd -P )
  17. . $SDEROOT/lib/libsde.in
  18. list_usage() {
  19. local progname=${0##*/}
  20. cat <<EOT
  21. Usage: $progname [--arch <arch>]
  22. $progname [--cfg <config>] [--extenders] [--repositories] [ITEMS...]
  23. EOT
  24. }
  25. list_arch() {
  26. local repo= arch="$1"
  27. local files=
  28. if [ ! -s $SDEROOT/architecture/$arch/archtest.out ]; then
  29. echo_error "wrong architecture ($arch) specified, aborting."
  30. return 1
  31. fi
  32. # the .awk file needs complete $SDEROOT relative .desc locations
  33. cd $SDEROOT
  34. for repo in package/*; do
  35. files=$( ls -1d $repo/*/*.desc 2> /dev/null )
  36. if [ -n "$files" ]; then
  37. gawk -f ./lib/sde-package/package-list.awk -v "arch=$arch" $files
  38. fi
  39. done | sort -k 3
  40. }
  41. list_desc_extenders() {
  42. local config="$1"
  43. local repo= pkg= pattern= pattern2= confdir=
  44. shift
  45. [ $# -gt 0 ] || return
  46. if [ $# -eq 1 ]; then
  47. pattern=$1
  48. else
  49. pattern="{$( echo $* | tr ' ' ',' )}"
  50. fi
  51. if [ -z "$config" ]; then
  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. else
  59. for repo in $( grep '^X' $SDEROOT/config/$config/packages | cut -d' ' -f4 | sort -u ); do
  60. set -- $( grep "^X [^ ]\+ [^ ]\+ $repo " "$SDEROOT/config/$config/packages" | cut -d' ' -f5 )
  61. if [ $# -eq 1 ]; then
  62. pattern2=$1
  63. else
  64. pattern2="{$( echo $* | tr ' ' ',' )}"
  65. fi
  66. ( cd "$SDEROOT"; eval ls -1d package/$repo/${pattern2}/pkg_${pattern}_{pre,post}.conf 2> /dev/null | cut -d/ -f-3 | sort -u )
  67. done | while read confdir; do
  68. pkg=${confdir##*/}
  69. echo $confdir/$pkg.desc
  70. done
  71. fi
  72. }
  73. list_desc_repo() {
  74. local repo="$1" pkg= desc=
  75. if [ -d "$SDEROOT/package/$repo/" ]; then
  76. set -- $( cd "$SDEROOT/package/$repo/"; ls -1d * 2> /dev/null )
  77. for pkg; do
  78. desc="package/$repo/$pkg/$pkg.desc"
  79. if [ -f "$SDEROOT/$desc" ]; then
  80. echo "$desc"
  81. fi
  82. done
  83. if [ -n "$extenders" ]; then
  84. # get desc of extenders of those packages
  85. list_desc_extenders '' "$@"
  86. fi
  87. fi
  88. }
  89. list_desc() {
  90. local config="$1" patterns=
  91. local repo= file= pkg= desc=
  92. shift;
  93. if [ -z "$config" ]; then
  94. if [ $# -eq 0 ]; then
  95. # no config, use the whole db
  96. for repo in $( cd "$SDEROOT/package"; ls -1d * 2> /dev/null ); do
  97. extenders= list_desc_repo "$repo"
  98. done
  99. elif [ -z "$repositories" ]; then
  100. # no config, but a given set of packages
  101. for pkg; do
  102. desc=$( cd "$SDEROOT"; ls -1d package/*/$pkg/$pkg.desc )
  103. if [ -f "$SDEROOT/$desc" ]; then
  104. echo "$desc"
  105. fi
  106. done
  107. if [ -n "$extenders" ]; then
  108. # get desc of extenders of those packages
  109. list_desc_extenders '' "$@"
  110. fi
  111. else
  112. for repo; do
  113. list_desc_repo "$repo"
  114. done
  115. fi
  116. elif [ -r "$SDEROOT/config/$config/packages" ]; then
  117. if [ $# -eq 0 ]; then
  118. # every active package
  119. grep '^X' config/xfce/packages | cut -d' ' -f4,5 | while read repo pkg; do
  120. desc=package/$repo/$pkg/$pkg.desc
  121. if [ -f "$SDEROOT/$desc" ]; then
  122. echo "$desc"
  123. fi
  124. done
  125. elif [ -z "$repositories" ]; then
  126. if [ $# -eq 1 ]; then
  127. pattern=$1
  128. else
  129. pattern="\\($( echo $* | sed -e "s/ /\\\\|/g" )\\)"
  130. fi
  131. grep "^X [^ ]\+ [^ ]\+ [^ ]\+ $pattern " "$SDEROOT/config/$config/packages" | cut -d' ' -f4,5 | while read repo pkg; do
  132. desc=package/$repo/$pkg/$pkg.desc
  133. if [ -f "$SDEROOT/$desc" ]; then
  134. echo "$desc"
  135. fi
  136. done
  137. if [ -n "$extenders" ]; then
  138. # get desc of extenders of those packages
  139. list_desc_extenders "$config" "$@"
  140. fi
  141. elif [ $# -gt 0 ]; then
  142. if [ $# -eq 1 ]; then
  143. pattern=$1
  144. else
  145. pattern="\\($( echo $* | sed -e "s/ /\\\\|/g" )\\)"
  146. fi
  147. grep "^X [^ ]\+ [^ ]\+ $pattern " "$SDEROOT/config/$config/packages" | cut -d' ' -f4,5 | while read repo pkg; do
  148. desc=package/$repo/$pkg/$pkg.desc
  149. if [ -f "$SDEROOT/$desc" ]; then
  150. echo "$desc"
  151. fi
  152. done
  153. if [ -n "$extenders" ]; then
  154. # get desc of extenders of those packages
  155. list_desc_extenders "$config" $( grep "^X [^ ]\+ [^ ]\+ $pattern " "$SDEROOT/config/$config/packages" |
  156. cut -d' ' -f 5 )
  157. fi
  158. fi
  159. else
  160. echo_abort -1 "$config: config not found."
  161. fi
  162. }
  163. arch=
  164. config=
  165. mode=desc
  166. extenders=
  167. repositories=
  168. shortopts='a:c:er'
  169. longopts='arch:,cfg:,extenders,repositories'
  170. options=$( getopt -o "$shortopts" -l "$longopts" -- "$@" )
  171. if [ $? -ne 0 ]; then
  172. list_usage
  173. exit -1
  174. fi
  175. # load new arguments list
  176. eval set -- "$options"
  177. # arguments
  178. while [ $# -gt 0 ]; do
  179. case "$1" in
  180. -a|--arch) mode=arch
  181. arch="$2"; shift ;;
  182. -c|--cfg) config="$2"; shift ;;
  183. -r|--repositories)
  184. repositories=yes ;;
  185. -e|--extenders)
  186. extenders=yes ;;
  187. --) shift; break ;;
  188. *) echo_abort 1 "Unknown argument '$1', aborting."
  189. esac
  190. shift
  191. done
  192. case "$mode" in
  193. arch) list_arch "$arch" ;;
  194. desc) list_desc "$config" "$@" ;;
  195. *) list_usage ;;
  196. esac