I want to write a script to check the version of a opkg package before installing it.
I've done a lot of research and found a few answer on dpkg system but none on opkg system.
I've tried opkg info
, opkg status
, opkg list
but they all seem to work on installed packages, but not with .opk
files.
I can somehow get the information by opkg install file.opk --noaction
but it's very slow and the output could be hard to parse reliably because the test installation could fail for all different reasons.
And opkg compare-versions
only compares strings so no solution.
Update:
I thought more about this.
The opk package is basically a .tar.gz
file and version number is stored in one of the text files in it (in the CONTROL/control
file).
So to get the version info from the package, it's inevitable to decompress it, so it has to take some time.
Although a quick solution is to put the version number as part of the file name of the package then parse the name, but file name can be very easily altered.
My plan is to use a two-pass approach: 1) include version number as part of the package name and parse the package name to get a "not-very-trustable" version number; 2) if it looks good then do a "dry run" installation to get the real version number as is in the CONTROL/control
file. If it's also good then proceed to real installation.
One of the problems with this approach is that, it effectively doubled the amount of time to do a real installation: before a real installation can run a dry run is run first, which takes equal amount of time.
Update 2:
The above update is not entirely true because opk is an ar
archive that has two files in it debian-binary
control.tar.gz
data.tar.gz
, and version info is in control.tar.gz
.
So it's feasible to quickly extract control.tar.gz
from opk
then extract control
from control.tar.gz
, then get version number from there.
opkg info
command doesn't provide info about installed package but from the index. After anopkg update
, if a newer version is available on the repo, theopkg info
version will display the newer version, even if the package isn't yet installed. TheStatus
field gives you the information about the package installation. – didil Sep 27 '17 at 13:19