Skip to content

Instantly share code, notes, and snippets.

@alfredkrohmer
Created February 11, 2017 13:39
Show Gist options
  • Select an option

  • Save alfredkrohmer/8d4c2a5ab62e690772f3d9de5ad2d978 to your computer and use it in GitHub Desktop.

Select an option

Save alfredkrohmer/8d4c2a5ab62e690772f3d9de5ad2d978 to your computer and use it in GitHub Desktop.
List all user-installed packages on OpenWrt / LEDE
#!/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
@5p0ng3b0b
Copy link

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*

@crzsotona
Copy link

crzsotona commented Jun 13, 2025

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

@5p0ng3b0b
Copy link

@crzsotona
The title and filename of the OPs original script says "list user installed packages". That is what the script does. It does NOT list packages in the OG or custom firmware that has already been flashed to the device. Happy for you that you managed to discover that it is useless for anything else.

@tojestzart
Copy link

now for apk equivalent?

@fish-finger-flinger
Copy link

@tojestzart
These are the droids commands you are looking for:

# Install the owut package if it is not installed already (needs openwrt v24.10 or greater)
[ ! -f "$(which owut)" ] && [ -f "$(which apk)" ] && apk update&&apk add owut
[ ! -f "$(which owut)" ] && [ -f "$(which opkg)" ] && opkg update&&opkg install owut

# show packages that are installed on the device but are not in the default sysupgrade firmware
# (ie user installed or added in custom fw)
owut list

# show all installed packages (without listing dependencies)
owut blob | grep '   '|cut -d'"' -f2

# This also shows all apps without dependencies (obviously openwrt >=25)
# The file was generated by running apk update
cat /etc/apk/world

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment