5 apkv: Quickly add and remove packages to/from Alpine virtual packages.
8 $0 add <packages> <virtual>
9 Add <packages> to virtual package <virtual>. If the virtual package
10 does not exist, it will be created.
11 $0 del <packages> <virtual>
12 Remove <packages> from virtual package <virtual>. Empty virtual
13 packages are removed from world. The shorthand '$0 del * <virtual>' can
14 be used to empty <virtual>.
16 List all or specific virtual packages and their contents.
20 Virtual packages must be prefixed with a dot to be managed with apkv. If one is
21 not present, it will be added automatically.
23 Methods can be shortened to their closest unambiguous forms, e.g. a, d, or l.
24 However, due to implementation specifics, any string starting with those forms
25 will work; that functionality is unspecified and is not guaranteed.
27 For example, the following are equivalent:
30 $0 abcdefg syslinux .virt
45 [ -z "$_pkg" ] && return 1
47 _list=$(echo "$(for x do echo $x; done)" | sort | uniq)
49 apk info -e "$_pkg" >/dev/null || return 1
50 _list=$(apk info -R "$_pkg" | awk 'NR > 1 && NF' | sort)
52 echo -e "\e[1m$_pkg\e[0m:" $_list
58 l*) for x in ${*:-$(apk info | grep '^\.')}; do
59 show_reqs "$(prepend_dot "$x")"
66 *) [ -n "$method" ] && echo "Invalid method $method" >&2; usage; exit 1;;
70 # get and validate packages
74 if [ -n "$pkgs" ]; then
76 elif [ -n "$virt" ]; then
81 if [ -z "$pkgs" ]; then
82 echo 'Not enough arguments' >&2
86 virt=$(prepend_dot $virt)
87 # exit if database locked (99) or no package found to delete from (1)
88 apk info -e "$virt" >/dev/null
90 if [ $code -eq 99 -o \( $method = del -a $code -ne 0 \) ]; then
94 # we have validated our args, so let's prepare to run apk: get sudo command if
95 # it exists and we are not already root
97 if [ "$(id -u)" != 0 ] && command -v sudo >/dev/null 2>&1; then
98 sudo=$(command -v sudo)
101 # handle quick delete shorthand mentioned in help
102 if [ $method = del -a '*' = "$pkgs" ]; then
103 $sudo apk del "$virt"
107 currpkgs=$(apk info -R "$virt" | awk 'NR > 1 && NF')
109 # $(echo) construct is to use word splitting to normalize whitespace
110 add) currpkgs="$(echo $currpkgs) $pkgs";;
111 del) # XXX: there's probably a more efficient way to do this
113 currpkgs=$(echo "$currpkgs" | grep -vFiw $x)
117 if [ -z "$currpkgs" ]; then
118 # virtual package is empty
119 $sudo apk del "$virt"
121 show_reqs "$virt" $currpkgs
122 $sudo apk add -t "$virt" $currpkgs
124 # pass along sudo/apk exit code