Last active
January 1, 2026 07:37
-
-
Save Sn0wo2/a462842739eebbe5dc48fbd772e768ca to your computer and use it in GitHub Desktop.
upgrade opkg all packages
This file contains hidden or 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
| # Thanks https://www.pcoic.com/system/linux/3261.html | |
| #!/bin/bash | |
| set -e | |
| export PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
| echo "==> Updating package lists ..." | |
| opkg update | |
| TMP=$(mktemp) | |
| opkg list-upgradable | grep -v '^Multiple' > "$TMP" || true | |
| TOTAL=$(wc -l < "$TMP") | |
| if [ "$TOTAL" -eq 0 ]; then | |
| echo | |
| echo "------------------------------------------------" | |
| echo "🎉 All packages are up to date, nothing to do." | |
| echo "------------------------------------------------" | |
| rm -f "$TMP" | |
| exit 0 | |
| fi | |
| echo | |
| echo "There are $TOTAL packages can be upgraded." | |
| echo | |
| echo " 1) Upgrade ONLY LuCI packages (safe, recommended)" | |
| echo " 2) Upgrade ALL packages (may cause file clash, do it carefully)" | |
| echo | |
| printf "Select [1/2] (default 1): " | |
| read -r CH | |
| case "$CH" in | |
| 2|all|ALL) GREP="" ;; | |
| *) GREP="luci-" ;; | |
| esac | |
| PKGS=$(grep "$GREP" "$TMP" | cut -d' ' -f1 | xargs) | |
| rm -f "$TMP" | |
| if [ -z "$PKGS" ]; then | |
| echo "No matched packages, exit." | |
| exit 0 | |
| fi | |
| echo "==> Upgrading selected packages ..." | |
| set +e | |
| for P in $PKGS; do | |
| echo " upgrading $P ..." | |
| opkg upgrade "$P" | |
| RET=$? | |
| if [ $RET -ne 0 ]; then | |
| echo " [!] $P upgrade failed (code $RET), continue anyway ..." | |
| fi | |
| done | |
| echo "==> Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment