Preinstallation script execution order for streaming updates

448 views
Skip to first unread message

Federico Sauter

unread,
Apr 15, 2021, 7:17:42 AM4/15/21
to swupdate

Hello,


I have an update archive that contains two images, both of them are streamed (install-directly = true). One is a root FS image streaming into a partition and the other one is a simple zlib archive that is unpacked to a target directory. Everything works as expected so far, as both images are installed without issues.

Now, I added a pre- as well as a post-installation script. What I can see from the logs is that the preinstallation script is called after both images have been "streamed" to their final locations, i.e. for my personal understanding this means that both images are already installed.

I would like to inquire whether this is the intended behavior. If so, what is the rationale behind it, as this makes preinstall scripts less useful at least for my use case.

I am using swupdate in the master version of January 2020 (4383decfa61bbdbbaa6df5e54f98c0a6fa60d233).

Any information is appreciated!


Kind regards,
Federico

Dominique MARTINET

unread,
Apr 15, 2021, 7:44:56 PM4/15/21
to Federico Sauter, swupdate
Hello,

'Federico Sauter' via swupdate wrote on Thu, Apr 15, 2021 at 04:17:42AM -0700:
> I would like to inquire whether this is the intended behavior. If so, what
> is the rationale behind it, as this makes preinstall scripts less useful at
> least for my use case.

Unfortunately yes (I'm in the same case), this is a limitation of the
streaming interface used for installed-directly.

I just had brought it up to the list so if you have a bit of time could
you please read (and comment!) on:
- a patch I sent earlier this week to try to clarify docs about it[1]
[1] https://groups.google.com/g/swupdate/c/pnuKcKd0YaI/m/5KOarUDjBwAJ
- and the discussion as a whole that prompted it[2]; although it went a
bit off topic at times.
[2] https://groups.google.com/g/swupdate/c/Ih6Co_4CCq8/m/FmhCRWZtCQAJ


Long story short, you only have two ways of executing code before
installed-directly images:
- the preupdatecmd that has to reside on the device before the install
starts
- embedded lua code (and its hooks) that is part of sw-description and
is guaranteed to be downloaded first, so present before other entries in
the cpio archive, and thus executed first.
It's technically possible to thus embed a base64 tar in the
sw-decription and execute scripts from it from lua but lua process
handling is suboptimal so after quite some testing while I got such a
hack to work I wouldn't recommend it (lua5.1 io.popen doesn't even have
a way of checking return code!! and even newer versions which do can't
handle stdout/stderr nicely)


There's a third way I haven't tried yet which would be to have the
preinstall script handle installed-directly, and just have it run your
pre-script before other installed-directly images by placing the scripts
earlier in the image.
That's the direction I'm looking at right now, but I haven't started
yet, and I'm not sure Stefano would be interested in such a feature so
would probably want to discuss first.

--
Dominique
Message has been deleted
Message has been deleted

Federico Sauter

unread,
Apr 20, 2021, 12:49:03 PM4/20/21
to swupdate
Thank you very much! :-)

Dominique MARTINET

unread,
Apr 20, 2021, 8:25:21 PM4/20/21
to Federico Sauter, swupdate
'Federico Sauter' via swupdate wrote on Tue, Apr 20, 2021 at 09:45:04AM -0700:
> Sorry I just noticed the preupdatecmd is also executed after a compressed
> image has been streamed/extracted already. I'm not sure that I understand
> what phases a streaming update comprises?

That sounds odd, it runs before installing things for me?

Order is (should be as far as I understand):
- download swu
- checks sw-description signature
- runs preupdate command
- parses sw-description, which includes the execution of any lua there
(embedded-script and hooks)
- "streams" the archive, which includes the execution of handlers
supporting installed-directly if the option is set
- runs normal pre scripts embedded in the swu
- runs other non-installed-directly handlers
- runs post scripts
- runs postupdatecmd if requested

so if you want to do things like create links for a/b updates before
data is streamed to a link then preupdatecmd should be early enough for
you, although the officially recommended method is to do so from lua
hooks.

>> Do I have to enable the preupdatecmd over a build configuration option?
>> I'm specifying it in a configuration file and it is not being executed...

I don't recall it being tied to a compile option, but it looks like you
figured that part out

--
Dominique

Federico Sauter

unread,
May 3, 2021, 11:25:48 AM5/3/21
to swupdate
Thank you very much! Everything is working as expected now. I updated to 2020.11, maybe that also helped. In any case thanks a lot for your help!!! :D
Reply all
Reply to author
Forward
0 new messages