Improve how changed presets are applied on upgrade
This is related to !6120 (merged) and #3494 (closed).
(the following was copied from here: !6120 (comment 472003))
@caleb had an idea for an alternative solution that would offload this complexity to the packaging side rather than running it at install time.
Their idea would be to store the preset files in some templated format where we can keep track of which package versions enabled/disabled specific presets - similar to kconfigcheck.toml in some ways. Essentially store a sequence of diffs rather than the file in its current state.
Then at packaging time we would generate the actual preset files by applying all the changes, and additionally we can generate a .post-upgrade file from the same diff info that would run the exact preset commands needed.
something like this for postmarketos-base-systemd
["0"] # Refers to pkgver
"wpa_supplicant.service" = "enable"
["1"]
"gdm.service" = "enable"
Then when upgrading to v2 we might add:
["2"]
# We switched to IWD everywhere!
"wpa_supplicant.service" = "disable"
The APKBUILD build() step would parse this file, produce the final preset file:
gdm.service enable
wpa_supplicant.service disable
and produce a post-upgrade script that would just have:
#!/bin/sh
. /usr/lib/systemd/systemd-apk-macros.sh
for service in %CHANGED_SERVICES%; do
for type in user system; do
...
systemd_service_post_install $type $service
...
done
done
Where %CHANGED_SERVICES%
is computed based on the data in the toml file, in our example it would just be wpa_supplicant.service
.
The main benefits to this approach are:
- Simplicity on the end-user device
- Self-documenting preset file changes (since the changelog will all be there, no need to go hunting through git history)