luisbandalap

luisbandalap / opkg_list_installed.sh

Last active 3 hours ago

Like 0

from https://gist.github.com/luisbandalap/2e17ba58e4f9f18d95704de24e17bc83

Revision 8a522d5ebd221a6c1af11adeacdb3cbca3e6c7f9

opkg_list_installed.sh Raw
1#!/bin/ash
2
3list_pkgs() {
4 opkg list-installed | cut -f 1 -d " "
5}
6
7show_deps() {
8 opkg depends $1 | sed -e 1d -e 's/^\s*//'
9}
10
11if [ $(id -u) != 0 ]; then
12 echo 'you must be root.'
13 exit 1
14fi
15
16TMPDIR=/tmp/$$
17if [ -d $TMPDIR ]; then
18 rm -rf $TMPDIR
19fi
20mkdir $TMPDIR
21
22trap "rm -rf $TMPDIR; exit 1" 1 2 3 15
23
24# listup default packages
25echo "entware-opt" > $TMPDIR/defaults
26show_deps entware-opt >> $TMPDIR/defaults
27
28# listup installed, but not default
29touch $TMPDIR/pkgs_not_default
30mkdir $TMPDIR/deps
31for p in $(list_pkgs); do
32 egrep "^$p\$" $TMPDIR/defaults > /dev/null
33 if [ $? != 0 ]; then
34 echo $p >> $TMPDIR/pkgs_not_default
35 # listup depends
36 show_deps $p > $TMPDIR/deps/$p.deps
37 fi
38done
39
40# listup not depended by any others from not defaults
41for p in $(cat $TMPDIR/pkgs_not_default); do
42 egrep "^$p\$" $TMPDIR/deps/* > /dev/null
43 if [ $? != 0 ]; then
44 echo $p
45 fi
46done
47
48rm -rf $TMPDIR
49
50exit 0
51