Skip to content

Instantly share code, notes, and snippets.

@benok
Last active February 24, 2024 10:57
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save benok/10eec2efbe09070150ed2100d29dc743 to your computer and use it in GitHub Desktop.
Save benok/10eec2efbe09070150ed2100d29dc743 to your computer and use it in GitHub Desktop.
[entware] List up manually installed packages
#!/bin/ash
list_pkgs() {
opkg list-installed | cut -f 1 -d " "
}
show_deps() {
opkg depends $1 | sed -e 1d -e 's/^\s*//'
}
if [ $(id -u) != 0 ]; then
echo 'you must be root.'
exit 1
fi
TMPDIR=/tmp/$$
if [ -d $TMPDIR ]; then
rm -rf $TMPDIR
fi
mkdir $TMPDIR
trap "rm -rf $TMPDIR; exit 1" 1 2 3 15
# listup default packages
echo "entware-opt" > $TMPDIR/defaults
show_deps entware-opt >> $TMPDIR/defaults
# listup installed, but not default
touch $TMPDIR/pkgs_not_default
mkdir $TMPDIR/deps
for p in $(list_pkgs); do
egrep "^$p\$" $TMPDIR/defaults > /dev/null
if [ $? != 0 ]; then
echo $p >> $TMPDIR/pkgs_not_default
# listup depends
show_deps $p > $TMPDIR/deps/$p.deps
fi
done
# listup not depended by any others from not defaults
for p in $(cat $TMPDIR/pkgs_not_default); do
egrep "^$p\$" $TMPDIR/deps/* > /dev/null
if [ $? != 0 ]; then
echo $p
fi
done
rm -rf $TMPDIR
exit 0
@Gruummy
Copy link

Gruummy commented Feb 3, 2020

For me this extension is not working with ash
I had to change it to bash.
Otherwise the error was:
./opkg_list_installed.sh: 38: [[: not found

One possible explanation :
https://unix.stackexchange.com/questions/155838/shell-script-throws-a-not-found-error-when-run-from-a-sh-file-but-if-entered-ma

@benok
Copy link
Author

benok commented Feb 3, 2020

Ah, I confirmed my ash is actually just a symlink to bash on my env (Synology).
Could you test with the updated one ?
Thank you for your comment.

@Gruummy
Copy link

Gruummy commented Feb 4, 2020

Could you test with the updated one ?
Thank you for your comment.

The new version works with #!/bin/ash
Thanks....

@TTimo
Copy link

TTimo commented Nov 14, 2021

Doesn't work with busybox either (which is common on a lot of devices)

@benok
Copy link
Author

benok commented Jan 31, 2022

@TTimo,
I don't use Entware on the embedded environment like DD-WRT, etc.
If you know some emulated environment (VM or docker image) using busybox, I could make this work.

I'm not sure which part of the script doesn't work with busybox, though.
Are there any missing external commands below?

  • cut
  • sed
  • id
  • egrep
    or
  • ash? (If ash is missing change the first line to #!/bin/sh)

@zhihuiyuze
Copy link

Hi,
I wrote a small script to restore packages from installed_packages.txt

packages=$(cat installed_packages.txt)

for package in $packages
 do 
 #echo $package
 opkg install $package
 done

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