Sunday, February 17, 2013

Fail2ban-client ImportError

Fedora has proposed compacting the linux filesystem hierarchy by moving some of the top level directories to usr. I am currently in the process of upgrading my home server from Fedora 16 to 18. Recently, I encountered a problem with fail2ban-client. I get the following error
# fail2ban-client -h
Traceback (most recent call last):
  File "/bin/fail2ban-client", line 35, in 
    from common.version import version
ImportError: No module named common.version
also described here with full patch given here. Once this patch was manually applied it worked perfect. However, the changes were reseted when the next fail2ban update. Until Fedora fixes this problem, a better temporary workaround is to add the python path to sys.path by adding it to PYTHONPATH environment. Create the following file /etc/profile.d/fail2ban.sh containing:
if [ -z "${PYTHONPATH}" ]; then
   PYTHONPATH="/usr/share/fail2ban"
else
   PYTHONPATH="/usr/share/fail2ban:${PYTHONPATH}"
fi
export PYTHONPATH
Alternatively, swap the the order of /bin and /usr/bin in PATH by editing /etc/profile.

Sunday, February 3, 2013

Creating Steam Client Installer RPM for Fedora 16, 17 and 18

As you might guess, I'm a long-time Linux user at work and at home. I have a Windows partition on my laptop that I only boot to when I want to play games. I'm also a Steam user. So when I heard that Steam was coming to Linux, I was over the moon. However, I'm a veteran Fedora user since Fedora Core 3. My laptop is currently running Fedora 16 (x86_64) and I play around with different Linux distribution using VirtualBox.

So recently, I decided to port Steam's deb package to Fedora's RPM. After unpacking the debian file and looking the dependencies, I decide to build my RPM for Fedora 17 (x86_64) (from KDE spin ISO) on a VirtualBox as the dependencies required some newer versions of packages that weren't available on Fedora 16. Here is the SPEC file that I create for fedora 17 based on debian's package control file.

Here are the following steps to creating a Fedora steam rpm and installing it (tested on a virtualbox machine installed with x86_64 Fedora 16 and Fedora 17). It should work for Fedora 18, but have yet to test it.
  1. Install rpmbuild environment according to this guide:
    # sudo yum install @development-tools
    # sudo yum install fedora-packager
    # rpmdev-setuptree
  2. Download the latest steam debian package from steam's repo site:
    # mkdir steam
    # cd steam
    # wget -c "http://repo.steampowered.com/steam/archive/precise/steam_1.0.0.22_i386.deb"
  3. Unpack the debian file and the package tarball:
    # ar xv steam_1.0.0.22_i386.deb
  4. Patch and repack the tarball with the dirctory structure expected by rpmbuild:
    # mkdir steam-1.0.0.22
    # tar zxvf data.tar.gz -C steam-1.0.0.22
    # rm -rf steam-1.0.0.22/etc
    # mv -iv steam-1.0.0.22/usr/bin/steamdeps steam-1.0.0.22/usr/bin/steamdeps.orig
    # ln -s /bin/cat steam-1.0.0.22/usr/bin/steamdeps
    # tar zcvf steam-1.0.0.22.tar.gz steam-1.0.0.22
    # mv -iv steam-1.0.0.22.tar.gz ~/rpmbuild/SOURCES
  5. Create the SPEC steam-1.0.0.22-1.x86_64.fc17.spec file based on debian control specification inside control.tar.gz:
     # Don't try fancy stuff like debuginfo, which is useless on binary-only  
     # packages. Don't strip binary too  
     # Be sure buildpolicy set to do nothing  
     %define    __spec_install_post %{nil}  
     %define     debug_package %{nil}  
     %define    __os_install_post %{_dbpath}/brp-compress  
     Name: steam  
     Version: 1.0.0.22 
     Release: 1.fc17  
     Summary: Steam open beta client  
     Group: Applications/Games  
     SOURCE0: %{name}-%{version}.tar.gz  
     URL: http://store.steampowered.com/  
     Vendor: Valve Corporation <linux@steampowered.com>  
     License: Steam  
     BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root  
     Requires: libcurl%{?_isa} >= 7.16.2, mesa-dri-drivers%{?_isa}, mesa-libGL%{?_isa}, libjpeg-turbo%{?_isa}, libogg%{?_isa} >= 1.0rc3, pixman%{?_isa} >= 0.24.4, SDL%{?_isa} >= 1.2.10-1, libtheora%{?_isa} >= 1.0, libudev%{?_isa} >= 175, libvorbis%{?_isa} >= 1.1.2, zenity >= 3.4.0, alsa-lib%{?_isa} >= 1.0.23, glibc%{?_isa} >= 2.15, cairo%{?_isa} >= 1.6.0, cups >= 1.4.0, dbus >= 1.2.14, fontconfig >= 2.8.0, freetype >= 2.3.9, gcc >= 4.1.1, libgcrypt%{?_isa} >= 1.4.5, gdk-pixbuf2%{?_isa} >= 2.22.0, glib2%{?_isa} >= 2.14.0, gtk2%{?_isa} >= 2.24.0, nspr%{?_isa}, nss%{?_isa} >= 3.12.3, openal-soft%{?_isa} >= 1.13, pango%{?_isa} >= 1.22.0, libpng-compat%{?_isa} >= 1.2.13, pulseaudio >= 0.99.1, pulseaudio-libs%{?_isa} >= 0.99.1, libstdc++%{?_isa} >= 4.6, libX11%{?_isa} >= 1.4.99.1, libXext%{?_isa}, libXfixes%{?_isa}, libXi%{?_isa} >= 1.2.99.4, libXinerama%{?_isa}, libXrandr%{?_isa} >= 1.2.99.3, libXrender%{?_isa}, zlib%{?_isa} >= 1.2.3.3  
     %description  
      cut and paste steam's license here or write your own description.
    
     %prep  
     %setup -q  
     %build  
     # Empty section  
     %install  
     rm -rf %{buildroot}  
     mkdir -p %{buildroot}  
     # in builddir  
     cp -a * %{buildroot}  
     %post  
     %postun  
     %clean  
     rm -rf %{buildroot}  
     %changelog  
     %files  
     %defattr(-,root,root,-)  
     %{_bindir}/*  
     %{_libdir}/*  
     %{_datadir}/*  
    
    Remember to edit the version number to match the tarball version number (i.e. Edit line label "Version:" and "Release:"). Copy the spec file into the ~/rpmbuild/SPECS directory. (Fedora 16) Since fc16 is quite old, the packages version numbers need to be shifted back. Replace the "Requires: ..." line with the following.
     Requires: libcurl%{?_isa} >= 7.16.2, mesa-dri-drivers%{?_isa}, mesa-libGL%{?_isa}, libjpeg-turbo%{?_isa}, libogg%{?_isa} >= 1.0rc3, pixman%{?_isa} >= 0.24.4, SDL%{?_isa} >= 1.2.10-1, libtheora%{?_isa} >= 1.0, libudev%{?_isa} >= 173, libvorbis%{?_isa} >= 1.1.2, zenity >= 3.2.0, alsa-lib%{?_isa} >= 1.0.23, glibc%{?_isa} >= 2.14, cairo%{?_isa} >= 1.6.0, cups >= 1.4.0, dbus >= 1.2.14, fontconfig >= 2.8.0, freetype >= 2.3.9, gcc >= 4.1.1, libgcrypt%{?_isa} >= 1.4.5, gdk-pixbuf2%{?_isa} >= 2.22.0, glib2%{?_isa} >= 2.14.0, gtk2%{?_isa} >= 2.24.0, nspr%{?_isa}, nss%{?_isa} >= 3.12.3, openal-soft%{?_isa} >= 1.12, pango%{?_isa} >= 1.22.0, libpng%{?_isa} >= 1.2.13, pulseaudio >= 0.9.23, pulseaudio-libs%{?_isa} >= 0.9.23, libstdc++%{?_isa} >= 4.6, libX11%{?_isa} >= 1.4.3, libXext%{?_isa}, libXfixes%{?_isa}, libXi%{?_isa} >= 1.2.99.4, libXinerama%{?_isa}, libXrandr%{?_isa} >= 1.2.99.3, libXrender%{?_isa}, zlib%{?_isa} >= 1.2.3.3, libgpg-error%{?_isa} >= 1.10, PackageKit-gtk-module%{?_isa}, libcanberra-gtk2%{?_isa}, libtxc_dxtn%{?_isa}, gtk2-engines%{?_isa}, xorg-x11-drv-nvidia-libs%{?_isa}   
    
    Note: the last package xorg-x11-drv-nvidia-libs is specific to my laptop which has a nvidia graphics card. Remove or modify this if this does not match your system.
  6. Build the rpm package.
    # cd ~/rpmbuild
    # rpmbuild --target  i686 -bb SPECS/steam-1.0.0.22-1.fc17.i686.spec
    The rpm should have been created in RPMS/i686 directory.
  7. (Fedora 16) Back port libX11 from F17 or F18.
    # wget -c "http://dl.fedoraproject.org/pub/fedora/linux/releases/17/Fedora/source/SRPMS/l/libX11-1.4.99.901-2.fc17.src.rpm"
    # rpm -ihv libX11-1.4.99.901-2.fc17.src.rpm
    # sudo yum install libXau-devel libXdmcp-devel libxcb-devel xorg-x11-proto-devel xorg-x11-util-macros xorg-11-xtrans-devel
    # sudo yum install libXau-devel.i686 libXdmcp-devel.i686 libxcb-devel.i686
    # sudo yum install glibc.i686 glibc-devel.i686 libgcc.i686 libstdc++.i686
    # rpmbuild --target i686 -ba SPECS/libX11.spec
    # rpmbuild -ba SPECS/libX11.spec # make for x86_64
    # sudo yum localinstall RPMS/i686/libX11-1.4.99.901-2.fc17.i686.rpm RPMS/i686/libX11-devel-1.4.99.901-2.fc17.i686.rpm RPMS/x86_64/libX11-1.4.99.901-2.fc17.x86_64.rpm RPMS/x86_64/libX11-devel-1.4.99.901-2.fc17.x86_64.rpm RPMS/noarch/libX11-common-1.4.99.901-2.fc17.noarch.rpm
  8. Everything so far has been using Fedora's repository. However, the steam client requires s3tc texture compression algorithm libraries which isn't available on Fedora's repo. You will need to add a third party repo such as rpmfusion:
    # su -c "yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-17.noarch.rpm http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-17.noarch.rpm"
    # sudo yum install libtxc_dxtn libtxc_dxtn.i686
    Adjust the first URL to match the fedora version number (FC17 is assumed in this example).
  9. And finally, install steam rpm (and libX11 if using Fedora 16).
    sudo yum localinstall RPMS/i686/steam-1.0.0.22-1.fc17.i686.rpm RPMS/i686/libX11-1.4.99.901-2.fc17.i686.rpm
  10. If you have been blessed, steam should be installed at this point. You can start up steam by typing:
    steam
    If you are behind a firewall, the steam client respects proxy environment variables: http_proxy, https_proxy, and all_proxy. The steam binary installed by rpm is really just a client downloader. You'll need to be connected to internet for the really client binary to be downloaded and installed.

Good gaming.

Remark: The code for steamdeps is probably a bad way to test dependencies as it is very debian-specific. A more distro agnostic way is required.