Τετάρτη, 4 Μαΐου 2011

Compiling latest versions of NetworkManager and nm-applet on Natty

You might want to play with the new support for WiMax devices in NetworkManager, or you may even want to hack it to support a feature that you always wanted. But it would also be nice if this can be done without disrupting your current well-maintained ubuntu system. When you are done playing with the new versions, you should be able to return back to the system-provided ones and things should be as if nothing ever happened.

The following is the process I used for achieving these goals, in case it is useful to someone else as well: The key is to install under a different prefix (e.g., /opt/nm.git) and modify all the "attachment points" of NM to the system to pick the alternative version. Using dpkg-divert we can ensure that this won't break our system and updates to the system-versions will keep being applied undisturbed (to the renamed files instead of the original ones).

When we are done hacking NetworkManager, we can just remove the diversions and delete the extra prefix and we are done, back to the system versions as if nothing happened :)

This process assumes you have an existing installation of ubuntu Natty because in the previous versions there will be annoying build-dependency problems that no one probably wants to waste time dealing with.

First of all, if your development system isn't also a security-critical one (that would be a bad choice anyway), we can just remove apparmor and save ourselves from
the trouble of configuring it for our compiled stuff:

sudo apt-get remove apparmor &&
sudo shutdown -r now


Then, we install whatever build/editing tools we need:

sudo apt-get install git build-essential quilt vim-nox ssh


Then, install the build dependencies of the existing versions of nm and nm-applet
(because most are common for the new versions as well):


sudo apt-get build-dep network-manager &&
sudo apt-get build-dep network-manager-gnome


And now, let's add the extra build and run dependencies:


sudo apt-get install autopoint autoconf2.64 && # NM build-deps
sudo apt-get install libgtk-3-dev libnotify4-dev && # NM-applet build-deps
sudo apt-get install libcanberra-gtk3-0 # NM-applet runtime dep


Now, let's get the source:


mkdir nm-workspace && cd nm-workspace
git clone git://anongit.freedesktop.org/NetworkManager/NetworkManager.git
git clone git://git.gnome.org/network-manager-applet


It is best to set and export the alternative prefix where we are going to
install our stuff:


export PREFIX=/opt/nmgit


now we can compile/install NM right away since we have all its build deps:


pushd NetworkManager
./autogen.sh --prefix=${PREFIX} &&
make &&
sudo make install
popd


Now, let's edit the pkgconfig files for NetworkManager, to make sure that
nm-applet will be built against the new versions instead of the system ones:


pushd /usr/lib/pkgconfig/
for file in NetworkManager.pc libnm-util.pc libnm-glib.pc \
libnm-glib-vpn.pc
do
sudo dpkg-divert --add --rename --divert ${PWD}/${file}{.dist,}
sudo ln -sf ${PREFIX}/lib/pkgconfig/${file} .
done
popd


Now, we can build the applet as well. Because gnome-bluetooth in natty by default is still gtk+2.0 while the applet itself is gtk+3.0 and I didn't need bluetooth anyway for this version of NM, I decided just to build without it. If you would like to have it, you can find a gtk+3.0 version of it and then there will probably be no problem:


pushd network-manager-applet
./autogen.sh --prefix=${PREFIX} --without-bluetooth &&
make &&
sudo make install
popd


Now, we will modify the several "attachment points" of NetworkManager/nm-applet in
the system to make sure that our compiled versions will be used but we will use dpkg-divert to save the "upgradeability" of the system and to be able to "return" back to the system versions after we are done hacking:

First the init script:

export NMFILE=/etc/init/network-manager.conf
sudo dpkg-divert --add --rename --divert ${NMFILE}{.dist,}
sudo cp ${NMFILE}{.dist,}
sudo sed -i "s,^exec NetworkManager,exec ${PREFIX}/sbin/NetworkManager," ${NMFILE}


Then, the DBUS files:

for file in NetworkManager.conf nm-avahi-autoipd.conf \
nm-dhcp-client.conf nm-dispatcher.conf
do
sudo dpkg-divert --add --rename --divert /etc/dbus-1/system.d/${file}{.dist,}
sudo ln -sf {${PREFIX},}/etc/dbus-1/system.d/${file}
done


Then PolicyKit:

pushd /usr/share/polkit-1/actions/
sudo dpkg-divert --add --rename --divert \
${PWD}/org.freedesktop.NetworkManager.policy{.dist,}
sudo ln -sf ${PREFIX}/share/polkit-1/actions/org.freedesktop.NetworkManager.policy .
popd



Then, the .desktop files for the menus and autostart, so that they point to our
version of the applet:

export NMAPPLET=/etc/xdg/autostart/nm-applet.desktop
sudo dpkg-divert --add --rename --divert ${NMAPPLET}{.dist,}
sudo cp ${NMAPPLET}{.dist,}
sudo sed "s,Exec=nm-applet,Exec=${PREFIX}/bin/nm-applet," -i ${NMAPPLET}
unset NMAPPLET

pushd /usr/share/applications/
sudo dpkg-divert --add --rename --divert ${PWD}/nm-connection-editor.desktop{.dist,}
sudo cp ${PWD}/nm-connection-editor.desktop{.dist,}
sudo sed "s,^Exec=nm-connection-editor,Exec=${PREFIX}/bin/nm-connection-editor," \
-i nm-connection-editor.desktop
popd


Now, we can reboot and if all goes well you should notice the new (ugly due to gtk3 not having been themed prettily yet in ubuntu) applet sitting in your notification area :) Let the hacking begin :)

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου