John Carver's picture

Around version 14.0/1, the ability to apply patches during the build was added to TKLDev.  Unfortunately, it was never properly documented, so I'm guessing that very few people know it exists.

Recently, I came across the need to apply a simple patch to correct a minor flaw in the apt-cacher-ng package in the LXC appliance.  Two table column titles in report.html are reversed resulting in a report page that doesn't make sense given the data.  I'd like to correct the problem temporarily until it gets fixed upstream.  Here's how I created the patch and added it to the TKLDev LXC appliance.

I start with a working LXC appliance running in a Proxmox VM, but this could be anywhere.  The offending code is in /usr/lib/apt-cacher-ng/report.html

    ...
                 <tr>
                         <td class="coltitle"> </td>
                         <td class="coltitle">Since startup</td>
                         <td class="coltitle">Recent history</td>
                 </tr>
    ...

The second and third column titles need to be reversed.  I copied and edited the file, then used diff to create the patch.

cp /usr/lib/apt-cacher-ng/report.html /usr/lib/apt-cacher-ng/report.html.patched
vi /usr/lib/apt-cacher-ng/report.html.patched
diff -u /usr/lib/apt-cacher-ng/report.html \
        /usr/lib/apt-cacher-ng/report.html.patched \
    > apt-cacher-ng.patch

Now move the patch to the TKLDev appliance and add it to the LXC app.  You will need to create the patches.d directory to store the patch.

cd products/lxc
mkdir patches.d
cp ~/apt-cacher-ng.patch patches.d/
make clean && make

When the TKLDev build completes, examine the screen output.  You should see the following lines which tell you the patch was applied.  You can also use fab-chroot build/root.patched and view the contents of the report.html file to verify it was changed.

# apply the product-local patches
$(call apply-patches, patches.d)
fab-apply-patch patches.d/apt-cacher-ng.patch build/root.patched
patching file usr/lib/apt-cacher-ng/report.html
# apply the product-local removelist

I hope this example can serve as temporary documentation until a better illustration is available.

[edit] I should have noted that patches applied in this manner must be created relative to /, the root directory. 

I meant to include the actual patch generated above.

--- /usr/lib/apt-cacher-ng/report.html    2018-07-02 01:22:23.153365261 +0000
+++ /usr/lib/apt-cacher-ng/report.html.patched    2018-07-03 03:53:13.488905130 +0000
@@ -16,8 +16,8 @@
          <table border=0 cellpadding=2 cellspacing=1 bgcolor="black">
                  <tr>
                          <td class="coltitle"> </td>
-                         <td class="coltitle">Since startup</td>
                          <td class="coltitle">Recent history</td>
+                         <td class="coltitle">Since startup</td>
                  </tr>
                  <tr>
                          <td class="coltitle" style="text-align:left">Data fetched:</td>
Forum: 

Add new comment