The future is now: opkg vs apk

<Hmm, goes and checks his own packages' install scripts...>

It appears apk does the same as opkg in this regard, exit code is "ok" whenever the command executes, regardless of results.

On my alpine box, picked an installed package from the list:

$ apk list --installed zstd-libs ; echo $?
zstd-libs-1.5.6-r0 x86_64 {zstd} (BSD-3-Clause OR GPL-2.0-or-later) [installed]
0

$ apk list --installed blarg ; echo $?
0


When I wrote owut, I originally used the rpc-sys packagelist call, but found that lacking and started parsing the opkg database. I've since reverted to (mostly) rpc-sys, but it is missing some pieces that would help here specifically. I think we can replicate the is-installed functionality by using it with the package-manager-agnostic form:

$ ubus call rpc-sys packagelist '{"all":true}' | grep -qw 'tc-tiny' ; echo $?
0

$ ubus call rpc-sys packagelist '{"all":true}' | grep -qw 'blarg' ; echo $?
1

What I'd really like to do is add both is-installed and what-provides functionality to https://github.com/openwrt/rpcd/blob/master/sys.c#L184. (It is going to need to be reworked for the APK database in any case, so might as well pile on.)

I'm thinking something like this, with the count value added specifically to address use in shell scripts where it makes things a lot easier.

$ ubus call rpc-sys packagelist '{"installed": "tc-tiny"}'
{
  "count": 1,
  "packages": {
    "tc-tiny" : "version"
  }
}

$ ubus call rpc-sys packagelist '{"installed": "blarg"}'
{
  "count": 0,
  "packages": {
  }
}

Then we could do this (kinda verbose, clearly a function candidate):

$ ubus call rpc-sys packagelist '{"installed": "blarg"}' | jsonfilter -e '$.count'
0


Then for completeness (I have a use case in owut for this one, https://github.com/efahl/owut/issues/10):

$ ubus call rpc-sys packagelist '{"what-provides": "vim"}'
{
  "count": 1,
  "packages": {
    "vim-full" : "version"
  }
}

EDIT:

$ cat is-installed-rpc.sh
#!/bin/sh

not_installed()
{
    local pkg="$1"
    local ver="$(ubus call rpc-sys packagelist '{"all": true}' |
                 jsonfilter -q -e "$.packages['$pkg']")"
    [ -z "$ver" ]
}

if not_installed "$1"; then
    echo "You need to install $1"
else
    echo "$1 is already installed"
fi

$ ./is-installed-rpc.sh tc-tiny
tc-tiny is already installed

$ ./is-installed-rpc.sh blarg
You need to install blarg
1 Like