Last active
September 18, 2024 23:44
-
-
Save benok/10eec2efbe09070150ed2100d29dc743 to your computer and use it in GitHub Desktop.
[entware] List up manually installed packages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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.
Could you test with the updated one ?
Thank you for your comment.
The new version works with #!/bin/ash
Thanks....
Doesn't work with busybox either (which is common on a lot of devices)
@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)
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
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