-
-
Save alfredkrohmer/8d4c2a5ab62e690772f3d9de5ad2d978 to your computer and use it in GitHub Desktop.
#!/bin/sh | |
FLASH_TIME=$(opkg info busybox | grep '^Installed-Time: ') | |
for i in $(opkg list-installed | cut -d' ' -f1) | |
do | |
if [ "$(opkg info $i | grep '^Installed-Time: ')" != "$FLASH_TIME" ] | |
then | |
echo $i | |
fi | |
done |
Hello
For me, none of these scripts work.
I noticed that a few of my packages have exactly the same installed time, so busybox would be the only package excluded from the output list.
I build my images with image builder in a "slow" VM.
I think installed time is not the flash time, but the install time during the build process of the image.
I found a workaround by reducing the precision of the install time value.
`#!/bin/sh
PRECISION=6
trunk_time () {
PKGTIME=$(opkg info "$1" | grep '^Installed-Time: ' | cut -f2 -d ' ')
PKGTIME=${PKGTIME:0:$2}
return
}
trunk_time busybox $PRECISION && BUILD_TIME=$PKGTIME
for i in $(opkg list-installed | cut -d' ' -f1)
do
trunk_time $i $PRECISION
if [ "$PKGTIME" != "$BUILD_TIME" ]
then
echo $i
fi
done
`
Understanding these scripts look to be correct for many, do I miss something?
Sorry but seems like I donot know how to insert code in my message
Oh .. Many Tnxs .. I took care about whats programs installed, wrote at a list .. but is possible I missed something in the way .. it's is very useful ..
Yet another variant:
DISTRI_TIME=$(grep Installed-Time /usr/lib/opkg/status | sort | head -n1)
while read -r line; do
case "$line" in
"Package: "*)
package="$line"
_skip=false;;
"${DISTRI_TIME}")
_skip=true;;
"Auto-Installed: yes")
_skip=true;;
"") # Empty line delimenates individual package blocks
[ "$_skip" = true ] || echo "$package" | awk '{print $2}';;
esac
done < /usr/lib/opkg/status | sort
Cheers!
And yet another variant. This one produces a more accurate/minimal list, as it also skips all dependents of other packages. It's based on bash, as it uses associative arrays.
https://gist.github.com/don-coleman/2218210aec58986acc80467f9a15d42b
Thanks @guymarc! Your script is the only one that worked for me. The other scripts here just list every single package installed. Maybe it is that way because I also used the Image Builder.
as someone suggested on https://www.sindastra.de/p/1213/list-user-installed-packages-in-openwrt
You can update busybox via opkg update, so it’s install time can be wrong as reference.
As a result you will have wrong list.
Only one thing you cannot install via opkg is kernel – because you update it over flashing new firmware.
So the kernel’s install time should be used as flash time.
FLASH_TIME=$(opkg info kernel | grep ‘^Installed-Time: ‘)
Here's my take on the subject using only busybox commands in an ash shell. Combine all of the above with some code golf magic.
#!/bin/sh
P=/usr/lib/opkg/status
T=$(awk -v RS= '/^P.{0,8}ker/' $P|grep '^I'|cut -d' ' -f2)
awk -v RS= -v t="$T" '$0 !~t' $P|grep '^Pa'|cut -d' ' -f2|sort
But wait, can't more can be done? You are looking to list packages required for imagebuilder, and you only need the packages that automatically install all the other packages as dependencies. Fret not, there's a script for that too.
#!/bin/sh
P=/usr/lib/opkg/status
T=$(awk -v RS= '/^P.{0,8}ker/' $P|grep '^I'|cut -d' ' -f2)
I=$(awk -v RS= -v t="$T" '$0 !~t' $P|grep '^Pa'|cut -d' ' -f2|sort)
D=$(awk -v RS= -v t="$T" '$0 !~t' $P|grep '^D'|cut -d' ' -f2-|sed 's#, #\n#g'|sort|uniq)
p=;for i in $I;do if [ $(echo $D|grep -c $i) = 0 ];then p="$p $i";fi;done;echo $p
*drops mic*
Here's my take on the subject using only busybox commands in an ash shell. Combine all of the above with some code golf magic.
But wait, can't more can be done? You are looking to list packages required for imagebuilder, and you only need the packages that automatically install all the other packages as dependencies. Fret not, there's a script for that too.#!/bin/sh P=/usr/lib/opkg/status T=$(awk -v RS= '/^P.{0,8}ker/' $P|grep '^I'|cut -d' ' -f2) I=$(awk -v RS= -v t="$T" '$0 !~t' $P|grep '^Pa'|cut -d' ' -f2|sort) D=$(awk -v RS= -v t="$T" '$0 !~t' $P|grep '^D'|cut -d' ' -f2-|sed 's#, #\n#g'|sort|uniq) p=;for i in $I;do if [ $(echo $D|grep -c $i) = 0 ];then p="$p $i";fi;done;echo $p
This script could find only those packages that weren't included in image already (all preinstalled packages have same time), so it's pretty useless for image builder in this state.
Slightly modified script from @tinxx would give all packages required for image builder:
while read -r line; do
case "$line" in
"Package: "*)
package="$line"
_skip=false;;
"Auto-Installed: yes")
_skip=true;;
"") # Empty line delimenates individual package blocks
[ "$_skip" = true ] || echo "$package" | awk '{print $2}';;
esac
done < /usr/lib/opkg/status | sort
That's way faster, @ejona86. A fraction of a second versus multiple seconds. Great