diff options
author | Dieter Plaetinck <dieter@plaetinck.be> | 2009-03-11 21:38:57 +0100 |
---|---|---|
committer | Dieter Plaetinck <dieter@plaetinck.be> | 2009-03-11 21:38:57 +0100 |
commit | 4897786b9d662dd45ee36d98de2aecdd3a8894bc (patch) | |
tree | 13b4665d31b273e297a3eb0ecd4295ec05057700 /src/core | |
parent | f5bca6d04342c0d6d08494e0d669ff36642214f2 (diff) |
abstracting some pacman logic
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/libs/lib-pacman.sh | 27 | ||||
-rw-r--r-- | src/core/libs/lib-ui-interactive.sh | 8 |
2 files changed, 31 insertions, 4 deletions
diff --git a/src/core/libs/lib-pacman.sh b/src/core/libs/lib-pacman.sh index 2fc7663..48fb61b 100644 --- a/src/core/libs/lib-pacman.sh +++ b/src/core/libs/lib-pacman.sh @@ -132,3 +132,30 @@ pacman_what_is_this_for () ! [ -d /var/lib/pacman ] && mkdir -p /var/lib/pacman } +list_package_groups () +{ + $PACMAN_TARGET -Sg +} + + +# List the packages in one or more repos or groups. output is one or more lines, each line being like this: +# <repo/group name> packagename [version, if $1=repo] +# $1 repo or group +# $2 one or more repo or group names +# TODO: check the validity of the specified names in $2 +list_packages () +{ + [ "$1" = repo -o "$2" = group ] || die_error "list_packages \$1 must be repo or group. not $1!" + [ "$1" = repo ] && $PACMAN_TARGET -Sl $2 + [ "$1" = group ] && $PACMAN_TARGET -Sg $2 +} + +# find out the group to which one or more packages belong +# $1 packages separated by spaces +# output format: multiple lines, each line like: +# <pkgname> <group> +# TODO: check $1 +which_group () +{ + PACKAGE_GROUPS=`$PACMAN_TARGET -Si $1| awk '/^Name/{ printf("%s ",$3) } /^Group/{ print $3 }'` +} diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index b9d5469..9a49344 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -605,7 +605,7 @@ interactive_select_packages() { # show group listing for group selection, base is ON by default, all others are OFF local _catlist="base ^ ON" - for i in $($PACMAN_TARGET -Sg | sed "s/^base$/ /g"); do + for i in $(list_package_groups | sed "s/^base$/ /g"); do _catlist="${_catlist} ${i} - OFF" done @@ -614,10 +614,10 @@ interactive_select_packages() { # assemble a list of packages with groups, marking pre-selected ones # <package> <group> <selected> - local _pkgtmp="$($PACMAN_TARGET -Sl core | awk '{print $2}')" # all packages in core repository + local _pkgtmp="$(list_packages repo core | awk '{print $2}')" # all packages in core repository local _pkglist='' - $PACMAN_TARGET -Si $_pkgtmp | awk '/^Name/{ printf("%s ",$3) } /^Group/{ print $3 }' > $ANSWER + which_group $_pkgtmp while read pkgname pkgcat; do # check if this package is in a selected group # slightly ugly but sorting later requires newlines in the variable @@ -626,7 +626,7 @@ interactive_select_packages() { else _pkglist="$(echo -e "${_pkglist}\n${pkgname} ${pkgcat} OFF")" fi - done < $ANSWER + done <<< "$PACKAGE_GROUPS" # sort by category _pkglist="$(echo "$_pkglist" | sort -f -k 2)" |