Sysupgrade >>auto reinstall<< packages

Hi,

I've written a script to automatically reinstall packages when doing a sysupgrade. This needs to run once before sysupgrade and bob's your uncle. The script itself will figure out what it needs to reinstall =)

I could spend hours figuring out where to put that call in sysupgrade but i thought it was easier to just ask someone who knows.

  1. Where in sysupgrade can i put this call ?
  2. How do i propose a patch ? (this is my first)

What it would look like: https://streamable.com/zn99v (start 6.00)

Thanks.

Saw no video, only heard music (might be my script blocker).

A request is probably easiest:

https://github.com/openwrt/openwrt/pull/new/master

Your software seems promising, I may use it in the future. Currently, I simply do the following (just upgraded a router today from 18.01.0 to 18.01.1). The below device had wireguard, tcpdump and snmpd installed:

/etc/crontabs/root:

10 16 * * * opkg update                                                                                                                                                
12 16 * * * opkg install kmod-udptunnel4 kmod-udptunnel6 kmod-wireguard wireguard-tools wireguard luci-proto-wireguard luci-app-wireguard tcpdump snmpd                
14 16 * * * sleep 70 && touch /etc/banner && reboot

Also, if you're still developing - as another option, perhaps you could just have your software simply make the needed cron entries?

Not trying to disparage you from your effort that seems to work, at least for you. But how about showing us something ... anything? Your code, a description of your process? You are asking us to comment on something you don't show.

Edit: We had a brief conversation about your undertaking on IRC the other day. As I said there, I can think of a number of circumstances where an automatic installation of packages could lead to problems, ranging from race conditions to a setup that will not boot anymore. I am genuinely curious how you tackle these problems, but again, "did you see it? Of course you didn't, there was nothing to see" is preciously little to base an opinion on, let alone an educated analysis.

Every afternoon, you are installing all the necessary packages, then rebooting? Why?

Edit: To clarify, I believe that cron is the worst possible place to trigger an automatism after sysupgrade.

2 Likes

:laughing: Gracious, no!

As I said:

I simply add this to cron before flashing an upgrade on a remote router (18.06.1). I remove it after success. I access this router via Wireguard. The only other workaround would be to build a custom firmware with Wireguard included.

Yea...I have no other choice in this instance, except driving a great distance when security updates are needed on the device (save flashing a custom firmware). I agree the safest option in my case would probably be flashing a custom firmware.

1 Like

FYI: "[OpenWrt-Devel] [PATCH v3 0/4] base-files: add new backup options"

http://lists.infradead.org/pipermail/openwrt-devel/2018-August/013633.html

2 Likes

Hi,

Through you i found: https://openwrt.org/submitting-patches
Pull Request submitted: https://github.com/openwrt/openwrt/pull/1298

Thanks, it was really helpful and educational =)

1 Like

I dont know how i missed you post, but i did :confused:

Thanks, it helped a lot. I thought i could put a couple of hours in a simple patch, but that turned out to be more complicated :grin:

I opened a new PR: https://github.com/openwrt/openwrt/pull/1310

sysupgrade backup will now contain a list of packages
sysupgrade will restore these package from this list
sysupgrade will restore these packages after firmware upgrade

How do your proposed changes handle when packages are obsoleted, have name changes, or dependency changes across releases?

Edit: Additional comments on the PR including handling of permanent and transient failures, as well as package repo not being available during first boot.

That is handled by opkg, it saves "only" user installed packages.
So if you install fdisk, only fdisk will be saved to the packagelist not any of its dependencies.

I replace rc.local before so it can execute later after reboot when the system is up after S95done. Only on proper executing it will then put back the old one and remove itself.

Name changes, you have a point there. I wonder how frequently that occurs though ?

Obsolete, got to take a look at that. I dont know.

Points taken

I would ignore the name change aspect for now. When we change a fundamental part in base, or split it into variants, we usually try to let it provide its former name as virtual provider, this way opkg will still find it when requesting the old name for install.

At least from what I've seen, opkg doesn't discriminate between "installed by direct user request" and "installed as a dependency". Ideally, the reinstall would be driven only by the "direct user request" packages, with their now-current dependencies installed, as appropriate.

1 Like

Would it be safer if this feature had an option to only save the list and then user could run opkg after upgrade with the list.
This would be helpful in cases that not enough space is available for all the packages.

1 Like

Sorry about that, it already filters "direct user request" packages only.

The system stays the same until rc.local is executed through S95done.
By then the system is already up. It would be the same as doing a firmware upgrade, and then login and run opkg update and opkg install .

If there is not enough space, opkg will not install all the packages. Thats a problem, although not a different result, unless i'm missing something ?

1 Like

Added commandline options: https://streamable.com/2hiqn

Idea's/comments/insights are welcome. (1310 comment updated)

upgrade-option:
	-a           attempt to reinstall "direct user request" packages

backup-command:
	-a           attempt to reinstall "direct user request" packages
	             on restore. (requires internet access)
	-k           list "direct user request" packages. Does not create
	             a backup file.

Well, I don't know what to say other than, its done. I need people to start testing. Preferably on hardware (make sure you have the skills to recover), but if you can at least test your configuration in a VM I'm happy too.

If you want to watch: https://peertube.video/videos/watch/2b89d295-3203-4c82-b1ab-1b661d403db0

If you want to test, follow the instructions in PR1310
https://github.com/openwrt/openwrt/pull/1310

I created three testing branches:

testing-master
testing-v18.06.1
testing-v17.01.5

VM testing procedure: (no compiling needed, unless you want to)

  1. Create a VM with OpenWRT
    https://openwrt.org/docs/guide-user/virtualization/virtualbox-vm

  2. Download sysupgrade for your version ^^ and overwrite /sbin/sysupgrade

  3. Start monkeying around =)
    a) install your packages, check them (-k)
    b) set upgrade url (-U)

https://downloads.openwrt.org/releases/18.06.1/targets/x86/64/openwrt-18.06.1-x86-64-combined-squashfs.img.gz
https://downloads.openwrt.org/snapshots/targets/x86/64/openwrt-x86-64-combined-squashfs.img.gz
  1. c) check for update (-w)
    d) autoupgrade (-Zzz)

Report any issues here.

Have fun.

1 Like

Wow these look amazing, did these ever get merged? I kind of got shocked today when I had to revert to a backup and saw that the backups hadn't even been saving a list of the installed packages, which I just assumed they were, for some reason.

@stumper: Thanks for the share! I wonder what is the status of your work. This is rather interesting (I've searched for a good solution for my own routers for ages) but I saw that the pull request https://github.com/openwrt/openwrt/pull/1298 has been closed and the git branch deleted. I would be willing to test your changes actually.
Regards

See current master, including the following commit and those immediately prior

commit 5cb1dce542a6a13fd250e9ef9c8290568c610c39
Author: Luiz Angelo Daros de Luca <redacted>
Date:   Fri Aug 17 20:49:53 2018 -0300

    base-files: add sysupgrade -k to save list of pkgs
    
    When '-k' is used, sysupgrade inserts into backup a new file
    /etc/backup/installed_packages.txt which contains pkgname and origin (rom,
    overlay, unknown) without touching rootfs.
    
    It's mainly used to reinstall all extra packages:
    
     # opkg update
     # grep "\toverlay" /etc/backup/installed_packages.txt | cut -f1 | xargs -r opkg install
     # rm /etc/backup/installed_packages.txt
    
    Signed-off-by: Luiz Angelo Daros de Luca <redacted>
1 Like

I would say that this method is now pretty much obsolete. You can now use https://sysupgrade.openwrt.org/ to generate image with all your currently included packages. This is not just more convenient, but all packages that have been included in initial image are in jffs2 partition and are compressed which means after making upgrade you will actually have more free space than before. All this is done automagically by just running simple command from cli or using luci.

You can use:
opkg install luci-app-attendedsysupgrade
to manage it using luci or

if you want to change branch or have more control over it:
opkg install auc

2 Likes