Tuesday, October 30, 2012

Wubi development and customisation

Wubi is managed by the Ubuntu-installer team. But you can still fix bugs and submit it to them to review, approve and merge. Or if you just want to create your own version of Wubi... how do you go about it?

To start off I am using a vanilla install (so I don't miss any steps). It happens to be a Wubi install, but this doesn't matter.

1. Preparing your machine

Install some packages that you'll need to get started:
sudo apt-get install packaging-dev

2. Launchpad setup

This involves registering on launchpad.net, signing their code of conduct (which involves creation of a GnuPG key), adding an SSH key (which you'll need if you want to push your code back to launchpad). You can find help for this on launchpad itself.

3. Identifying yourself

You should now have GnuPG and SSH key setup. Identify yourself to the debian packaging tools by adding the following lines to your .bashrc:
export DEBFULLNAME='bcbc'
export DEBEMAIL='openbcbc@gmail.com'

To make the change take effect run:

source ~/.bashrc

4. Download the code for Wubi

First identify yourself to bzr (and launchpad):
bzr launchpad-login bcbc
bzr whoami "bcbc <openbcbc@gmail.com>"

If you're working on the development release you can download it using:
bzr branch lp:wubi

If you want a production release e.g. precise, instead use:
bzr branch lp:~ubuntu-installer/wubi/precise

This will confirm the RSA fingerprint on the server and ask you to unlock your own SSH key; then download the code. Now you should review the README and compile wubi.exe because the first time you do it, it installs and configures wine and other software you require (there is a lot to install, when prompted accept the defaults except for a few things like accepting the EULA):


6. Make your changes
So in this case I'm going to fix a really easy bug. This affects 12.04.1 wubi.exe (but I'm fixing it in the dev branch 13.04). It doesn't matter, it will have to go in there as well. The problem is that with long term releases, not all flavours of Ubuntu get updates. So while there is a 12.04.1 release of Ubuntu/Kubuntu/Edubuntu etc., there isn't one for Lubuntu. And the 12.04.1 version of wubi.exe won't install a 12.04 version of Lubuntu.

There is a check that allows a 12.04 version of wubi.exe to install a 12.04.1 release, but I believe that's an error - it should be the other way round.

So, let's find the bug and the affected code. Here's the bug: https://bugs.launchpad.net/wubi/+bug/1043607 and here's the relevant output:

08-29 21:38 DEBUG CommonBackend: Checking C:\ubuntu\install\lubuntu-12.04-desktop-i386.iso
08-29 21:38 DEBUG Distro: checking Lubuntu ISO C:\ubuntu\install\lubuntu-12.04-desktop-i386.iso
08-29 21:38 DEBUG Distro: wrong version: 12.04 != 12.04.1

The highlighted part shows you where to find the code: its in distro.py which happens to be in src/wubi/backends/common (search on "wrong version" since the release numbers are variables...) and then make the fix. Here's the diff after fixing.:

=== modified file 'src/wubi/backends/common/distro.py'
--- src/wubi/backends/common/distro.py 2012-04-24 15:57:38 +0000
+++ src/wubi/backends/common/distro.py 2012-10-30 21:17:02 +0000
@@ -166,7 +166,7 @@
         if self.name and name != self.name:
             log.debug('wrong name: %s != %s' % (name, self.name))
             return False
-        if self.version and not (version == self.version or version.startswith(self.version + '.')):
+        if self.version and not (version == self.version or self.version.startswith(version + '.')):
             log.debug('wrong version: %s != %s' % (version, self.version))
             return False
         if check_arch and self.arch and arch != self.arch:

7. Edit the changelog
You can use dch -i to add a changelog entry. It does some automatic stuff for you, but make sure you correct the release number or it names it 12.10ubuntu1. Otherwise just use your favourite editor. Note: I'm not really sure of the convention here - but only the Ubuntu-installer team can merge changes to the main Wubi branch, so they'll sort that out if they have the time to look at it.

So here's what mine looks like:

wubi (13.04) UNRELEASED; urgency=low

  [ bcbc ]
  * Allow Wubi to install earlier release ISOs on LTS (LP: #1043607)

 -- bcbc <openbcbc@gmail.com>  Tue, 30 Oct 2012 14:41:50 -0700

8. Commit the changes

bcbc@ubuntu:~/wubi$ bzr commit -m 'Allow Wubi to install earlier release ISOs on LTS - LP 1043607'Committing to: /home/bcbc/wubi/                                                                  
modified debian/changelog
modified src/wubi/backends/common/distro.py
Committed revision 274. 

If you messed up, run bzr uncommit and you can change and recommit. It doesn't remove your changes, just the commit.

9. Push to a new branch

bcbc@ubuntu:~/wubi$ bzr push lp:~bcbc/wubi/lp1043607
Using default stacking branch /+branch-id/30119 at chroot-74436368:///~bcbc/wubi/
Created new stacked branch referring to /+branch-id/30119.    

10. Link it to the bug
Go to the page for the branch you just pushed: https://code.launchpad.net/~bcbc/wubi/lp1043607
Now you can link the bug report and open a merge request.

11. Final comment
You probably noticed I forgot to test my patch. That's not a good idea. So once you have made you changes you should run make again to build wubi.exe. You can find it in the build directory. You can copy that to your Windows machine and test it - or view the README for other test options.

PS. If you want to build a custom Wubi for your own ISO, review the README as well. It tells you what you need to change.

No comments:

Post a Comment