tavinus / opkg-upgrade

List and install OpenWRT / LEDE opkg upgradable packages
323 stars 61 forks source link

Integrating opkg-upgrade in .profile - how to use background checking for new packages #15

Closed cmonty14 closed 2 years ago

cmonty14 commented 2 years ago

Hello, I have integrated opkg-upgrade in .profile, means I get this when starting a shell-session as root:

thomas@eddie:~$ sudo su -

BusyBox v1.33.2 (2022-04-16 12:59:34 UTC) built-in shell (ash)

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 OpenWrt 21.02.3, r16554-1d4dea6d4f
 -----------------------------------------------------

My current WAN IP is: xxx.xxx.xxx.xxx

Software status report:
--> No upgrades available.

This is implemented with the following coding in .profile:

YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo "Software status report:"
opkg-upgrade -u \
&& echo -e "${YELLOW}--> Upgrades are available.${NC}\n----> List available upgrades: opkg-upgrade -l\n----> Upgrade packages: opkg-upgrade\n" \
|| echo -e "${GREEN}--> No upgrades available.${NC}\n"

The downside of this implementation is that I have to wait several seconds until the command prompt is ready.

Question: Can I check for new packages in the background (regularely) and then fetch the results only w/o waiting for command opkg-upgrade -u to return data?

THX

cmonty14 commented 2 years ago

For interested people here's a working solution:

root@eddie:~# crontab -l
@daily /usr/sbin/opkg-upgrade -u && touch /tmp/opkg-upgrade-check || rm -f /tmp/opkg-upgrade-check

/root/.profile:

upgradeCheckFile='/tmp/opkg-upgrade-check'
YELLOW='\033[1;33m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
echo "Software status report:"
if [ -f $upgradeCheckFile ];
  then 
     echo -e "${YELLOW}--> Upgrades are available.${NC}\n----> List available upgrades: opkg-upgrade -l\n----> Upgrade packages: opkg-upgrade\n"
  else
     echo -e "${GREEN}--> No upgrades available.${NC}\n"
fi
tavinus commented 1 year ago

The delay is probably because it is fetching the lists (opkg update).

Usually the lists reside into a temporary folder. You would probably need to change it to a permanent folder (can be done if you have a pendrive into the router) and also run opkg update from cron regularly. Then you can run opkg-upgrade with the -n flag for it to skip the opkg update part. It will just use the current available lists without getting new ones.

Note: I am not sure, but if you run with -n without lists available (just rebooted and still using the temp folder) - you will get an error on execution. This could be remedied by also adding an opkg-update to the boot sequence.