summaryrefslogtreecommitdiffstats
path: root/dev/todo/install-bb-without-bb.mdwn
blob: 4bb90ffa80420839a146702f7c8294ad1174e584 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
[[!meta title="Installing BusyBox Without BusyBox"]]

**or, Adventures in Regressions and Crazy Ideas**

---

**This work is now done.**

**The rest of this page is kept only for reference and historical purposes.**

---

Two Problems
============

`opkg-lede` and the Outsourced Inflation
----------------------------------------

`opkg-lede` [now relies][opkg-lede-dd4c78a] on an external `gzip` executable.
When upgrading a package, it tries to execute `gzip` to unpack maintainer
scripts and data files [after removing][opkg_install_pkg] the old version of the
package.  When the package being upgraded is `busybox`, which provides `gzip`,
`opkg` crashes and leaves behind a completely broken system.

To reiterate, `opkg-lede` is (and has been for as long as it has been in
ProteanOS) **currently unable to upgrade `busybox`**, due to its own design.

[opkg-lede-dd4c78a]: https://git.openwrt.org/?p=project/opkg-lede.git;a=commitdiff;h=dd4c78aa88efd3b9cf516030937c684814df7962
[opkg_install_pkg]: https://git.openwrt.org/?p=project/opkg-lede.git;a=blob;f=libopkg/opkg_install.c;hb=d4ba162#l1520

The Amazing Alternatives of `busybox`
-------------------------------------

Instead of [adding alternatives][alts-log] one at a time, [it would be
nice][bb-ua] to manage all of `busybox`'s utility links using
`update-alternatives`.  Unfortunately, the [maintainer script][bb.pi] that runs
`update-alternatives` (as well as the [`update-alternatives` script][u-a]
itself) needs a few `busybox` utilities (`/bin/sh` for a start).  Thus, after an
older version of `busybox` is deconfigured, a newer version can't be configured.
`busybox` also can't be configured when first unpacked by `prokit`.

[alts-log]: http://git.proteanos.com/pkg/busybox.git/log/alternatives
[bb-ua]: http://git.proteanos.com/pkg/busybox.git/commit/?id=1558d05c62ed90f7d93a14533541c33896b7b733
[bb.pi]: http://git.proteanos.com/pkg/busybox.git/tree/busybox.pkg/postinst
[u-a]: https://git.openwrt.org/?p=project/opkg-lede.git;a=blob;f=utils/update-alternatives.in;hb=d4ba162

One Solution
============

The next version of `src:opkg-lede` (likely 0+git20190131.d4ba162-7) already
will have a [wrapper script called `opkg`][opkg] that executes `opkg-cl` (the
actual binary executable).  The script can be extended to first save a copy of
`/bin/busybox` to an empty temporary directory, generate utility links to it in
the directory, and add the directory to `PATH`.  Until all of this setup is
complete, the wrapper script must be careful to execute utilities as `busybox
$util` (a full path to `busybox` won't be necessary, as the usual `/bin/busybox`
will be available at that point).  This includes the interpreter line, which
will need to be changed to `#!/bin/busybox sh`.  `ash` built-in utilities can be
used as usual.

The `busybox` package can't use `update-alternatives` to manage all of its
utility links until an `opkg-lede` with this wrapper script functionality is
uploaded.  This is because, even if `busybox`'s `postinst` script is modified to
use the `busybox` executable directly, other packages' maintainer scripts may be
executed first, while `busybox` is unpacked but not yet configured (and
therefore utility links are not yet created).

Once this new `opkg-lede` package is uploaded and `busybox` uses
`update-alternatives` for everything, `busybox` would need to declare that it
`Breaks` older versions of `opkg-lede`, to ensure that `opkg-lede` will preserve
a copy of the `busybox` executable and its utility links.  However, this is
still insufficient, as the version of `opkg` that is *running* must have already
set up this environment before `busybox` is upgraded.  `busybox`'s `prerm`
script will need to check for this somehow and abort the upgrade if `opkg` is
too old to have prepared for a safe upgrade.  One solution is for the `opkg`
script to set an `OPKG_BUSYBOX_SAVED` environment variable.

The `opkg` script of the `opkg-lede` package will need to read `busybox`'s list
of alternatives links.  This is currently located at
`/usr/share/busybox/alternatives`.  [The file's format][alts] will change when
`busybox` uses `update-alternatives` for everything: the last two columns (name
and priority) will be dropped.  `opkg` however can simply read the first column,
so it will maintain compatibility.

[opkg]: http://git.proteanos.com/pkg/opkg-lede.git/tree/opkg
[alts]: http://git.proteanos.com/pkg/busybox.git/tree/alternatives?id=e37f03311d934a8f33a9ff31db47b18bbf0be555