Skip to content

Instantly share code, notes, and snippets.

@dogtopus
Last active September 6, 2020 05:56
Show Gist options
  • Save dogtopus/ca19415c6e6229bb9803a8bb5017200a to your computer and use it in GitHub Desktop.
Save dogtopus/ca19415c6e6229bb9803a8bb5017200a to your computer and use it in GitHub Desktop.
The missing upgrade-all feature for opkg. Drop into /etc/profile.d/ re-login and use `opkg update && opkg upgrade-all` to upgrade all packages
#!/bin/sh
__opkgx_append_to_list() {
local _listfile="${1}"
shift
cp "${_listfile}" "${_listfile}.bak"
for pkg in "$@"; do
echo "${pkg}" >> "${_listfile}"
done
diff -u "${_listfile}.bak" "${_listfile}"
}
__opkgx_remove_from_list() {
local _listfile="${1}"
shift
local _newlist=$(mktemp) && \
echo "$@" | xargs printf -- '-e\0%s\0' | xargs -0 fgrep -xv "${_listfile}" > "${_newlist}"
# intentionally not checking the exit code here to allow empty files
# create a backup just in case
cp "${_listfile}" "${_listfile}.bak"
mv "${_newlist}" "${_listfile}"
diff -u "${_listfile}.bak" "${_listfile}"
}
opkgx() {
case "${1}" in
upgrade-all)
# https://openwrt.org/docs/guide-user/additional-software/opkg
_upgradable="$(opkg list-upgradable | cut -f 1 -d ' ')"
[ -z "${_upgradable}" ] || echo "${_upgradable}" | xargs opkg upgrade
;;
upgrade-all-nokmod)
_upgradable="$(opkg list-upgradable | cut -f 1 -d ' ' | grep -v '^kmod-')"
[ -z "${_upgradable}" ] || echo "${_upgradable}" | xargs opkg upgrade
;;
restore)
echo '=> Removing masked packages...'
[ -f /etc/removed ] && cat /etc/removed | xargs opkg remove
echo '=> Restoring previously saved packages...'
[ -f /etc/installed ] && cat /etc/installed | xargs opkg install
;;
append)
shift
__opkgx_append_to_list /etc/installed "${@}"
;;
remove)
shift
__opkgx_remove_from_list /etc/installed "${@}"
;;
mask)
shift
__opkgx_append_to_list /etc/removed "${@}"
;;
unmask)
shift
__opkgx_remove_from_list /etc/removed "${@}"
;;
*)
/bin/opkg "${@}"
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment