Here are the OpenWrt shell scripts, which have only one purpose to help you get a real list of packages that you have installed using opkg
after setting up OpenWrt. While it may seem like a simple task, it's not straightforward. I recommend checking out this README.md file in this Gist for instructions and recommendations on which script to use.
Displaying a list of packages that I have personally installed is not a straightforward problem, as the status "user installed" will include various other packages besides the ones I installed. Therefore, using the opkg status
command will produce way too many results and only confuse you.
In a nutshell, the approach that works most effectively in scripts is to use package installation timestamps and compare them to some reference timestamp to determine exactly which packages I have installed. One reference that some scripts use, for instance, is the kernel installation timestamp, which is the one that couldn't have been installed later.
Here is the list of scripts mentioned in the original Gist from various sources, such as:
The basic and obvious script, for example by Kristaps Esterliņš, which would logically be expected to work correctly, but it does not. It is based on identifying "user installed" packages, which is not very accurate because there are many more such packages than those that I have installed. This is what I tried first and got disappointed.
If you don't have curl
installed, it's usually easy to solve this by typing opkg install curl
.
# download
wget -q https://gist.githubusercontent.com/cvladan/898c3ad14c5ba31806a131ae6bf39e28/raw/list-my-packages-naive.sh -O ~/list-my-packages-naive.sh && chmod +x "$_"
# and run
~/list-my-packages-naive.sh
# or just run directly
curl -s https://gist.githubusercontent.com/cvladan/898c3ad14c5ba31806a131ae6bf39e28/raw/list-my-packages-naive.sh | sh
The first viable solution was offered in a single Gist by Alfred Krohmer. However, in the comments, there are improved versions, all of which I tried, but in the end, I chose the one that displays the most accurate or minimal list of packages that I installed.
curl -s https://gist.githubusercontent.com/cvladan/898c3ad14c5ba31806a131ae6bf39e28/raw/list-my-packages-inaccurate-and-slow.sh | sh
You'll notice that the script is slow and also rather inaccurate, so do not hesitate to interrupt it if you can't stand waiting.
There is a recommended improvement of this script. The script uses the busybox
timestamp as a reference, but since you can update busybox via opkg update, its installation time is not ideal. The kernel is a part of the system that can't be installed via opkg
, so it's better to use that instead, i.e. use opkg info kernel
instead of opkg info busybox
. In most cases both values will be the same, but in some cases using the kernel will be more accurate.
The updated version of the same script uses the same principle, but with a nicer appearance and significantly improved speed. It also generates files that contain lists of packages. However, the script is still just as inaccurate as before.
curl -s https://gist.githubusercontent.com/cvladan/898c3ad14c5ba31806a131ae6bf39e28/raw/list-my-packages-inaccurate-fancy.sh | sh
The following script by Eric Anderson is notably the fastest as it reads data from the file /usr/lib/opkg/status
, without having to repeatedly execute opkg
commands. More importantly, this script provides the best and most realistic results. The modified version of this script is my favorite and I actively use it.
curl -s https://gist.githubusercontent.com/cvladan/898c3ad14c5ba31806a131ae6bf39e28/raw/list-my-packages-proper-concept.sh | sh
For the last script, it is necessary to install the bash
package since ash
is the default shell for OpenWrt. However, I do not want to install bash
solely for the purpose of running a single script. Therefore, unfortunately, I have not tested it. Use it as you wish.
curl -s https://gist.githubusercontent.com/cvladan/898c3ad14c5ba31806a131ae6bf39e28/raw/list-my-packages-using-bash.sh | bash
Finally, back to the list-my-packages-proper-concept.sh
script, which gave by far the best results. I improved that script a bit and copied it to /usr/bin
and use it as the opkg-my
command. If you want to do the same, just type the following
wget -q https://gist.githubusercontent.com/cvladan/898c3ad14c5ba31806a131ae6bf39e28/raw/list-my-packages.sh -O /usr/bin/opkg-my && chmod +x "$_"
And you can always run it directly, without installation:
curl -s https://gist.githubusercontent.com/cvladan/898c3ad14c5ba31806a131ae6bf39e28/raw/list-my-packages.sh | sh