Created
July 24, 2026 11:04
-
-
Save cherts/b3c7711b5ba19de3565cba32801331d0 to your computer and use it in GitHub Desktop.
Upgrade all opkg 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
| #!/bin/sh | |
| MAX_UPDATE_ATTEMPTS=5 | |
| MAX_UPGRADE_ATTEMPTS=3 | |
| _restart() { | |
| echo "Restart uhttpd and rpcd..." | |
| /etc/init.d/uhttpd restart | |
| /etc/init.d/rpcd restart | |
| } | |
| attempt=${MAX_UPDATE_ATTEMPTS} | |
| while [ ${attempt} -gt 0 ] | |
| do | |
| echo "Run opkg update, attempt $((${MAX_UPDATE_ATTEMPTS}-${attempt}+1)) of ${MAX_UPDATE_ATTEMPTS}..." | |
| opkg update >/dev/null 2>&1 | |
| if [ $? -eq 0 ]; then | |
| echo "Done" | |
| break | |
| else | |
| echo "ERROR: Command opkg update failed." | |
| sleep 2 | |
| fi | |
| attempt=$(($attempt-1)) | |
| done | |
| NUM_UPGRADABLE=$(opkg list-upgradable 2>/dev/null | wc -l) | |
| if [ ${NUM_UPGRADABLE} -ne 0 ]; then | |
| echo "Number of upgradable packages is ${NUM_UPGRADABLE}" | |
| attempt=${MAX_UPGRADE_ATTEMPTS} | |
| while [ ${attempt} -gt 0 ] | |
| do | |
| echo "Run opkg upgrade, attempt $((${MAX_UPGRADE_ATTEMPTS}-${attempt}+1)) of ${MAX_UPGRADE_ATTEMPTS}..." | |
| opkg list-upgradable | cut -f 1 -d ' ' | xargs opkg upgrade | |
| if [ $? -eq 0 ]; then | |
| _restart | |
| break | |
| else | |
| echo "ERROR: Upgrade not completed." | |
| sleep 2 | |
| fi | |
| attempt=$(($attempt-1)) | |
| done | |
| else | |
| echo "No packages need upgrade. Exit..." | |
| exit 0 | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment