Friday, 1 July 2011

Firefox 5 from Source

These are the instructions for installing FF5 from source on the LFS system I built in earlier posts, assuming that you have not installed any version.

wget http://ftp.gnome.org/pub/gnome/sources/libIDL/0.8/libIDL-0.8.14.tar.bz2
tar -xjvf /sources/extras/libIDL-0.8.14.tar.bz2
cd libIDL-0.8.14
./configure --prefix=/usr &&
make
make install
cd ..
rm -rvf libIDL-0.8.14

wget http://www.python.org/ftp/python/2.6.4/Python-2.6.4.tar.bz2
wget http://www.linuxfromscratch.org/patches/blfs/svn/Python-2.6.4-bdb_4.8-1.patch
wget http://docs.python.org/ftp/python/doc/2.6/python-2.6-docs-html.tar.bz2
tar -xjvf /sources/extras/Python-2.6.4.tar.bz2
cd Python-2.6.4
sed -i "s/ndbm_libs = \[\]/ndbm_libs = ['gdbm', 'gdbm_compat']/" setup.py
patch -Np1 -i /sources/extras/Python-2.6.4-bdb_4.8-1.patch
./configure --prefix=/usr --enable-shared
make
make test
make install
chmod -v 755 /usr/lib/libpython2.6.so.1.0
install -v -m755 -d /usr/share/doc/Python-2.6.4/html
tar --strip-components=1 --no-same-owner --no-same-permissions -C /usr/share/doc/Python-2.6.4/html -xvf /sources/extras/python-2.6-docs-html.tar.bz2
cat >> /etc/profile << "EOF"
export PYTHONDOCS=/usr/share/doc/Python-2.6.4/html
EOF
cd ..
rm -rvf Python-2.6.4
wget http://www.tortall.net/projects/yasm/releases/yasm-1.0.1.tar.gz
cd /dev/shm
tar -xzvf /sources/extras/yasm-1.0.1.tar.gz
cd yasm-1.0.1
CC="gcc -fPIC" ./configure --prefix=/usr
time make $CORES_TO_USE
make install
wget http://cairographics.org/releases/cairo-1.10.2.tar.gz
cd /dev/shm
tar -xzvf /sources/desktop/cairo-1.10.2.tar.gz
cd cairo-1.10.2
./configure --prefix=/usr --enable-tee=yes
make $CORES_TO_USE
make install
cd ..
rm -rvf cairo-1.10.2
wget ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/5.0/source/firefox-5.0.source.tar.bz2
tar -xjvf /sources/extras/firefox-5.0.source.tar.bz2
cd moz*
cat > .mozconfig << "EOF"
ac_add_options --enable-application=browser
. $topsrcdir/browser/config/mozconfig
mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/../firefox-build
mk_add_options MOZ_MAKE_FLAGS="-j2"
ac_add_options --prefix=/opt/firefox5
ac_add_options --enable-optimize
ac_add_options --enable-system-cairo
ac_add_options --with-system-jpeg
#ac_add_options --with-system-png
ac_add_options --with-pthreads
ac_add_options --with-system-zlib
ac_add_options --disable-accessibility
ac_add_options --disable-crashreporter
ac_add_options --disable-dbus
ac_add_options --disable-gnomevfs
ac_add_options --disable-necko-wifi
ac_add_options --disable-installer
ac_add_options --disable-javaxpcom
ac_add_options --disable-tests
ac_add_options --disable-updater
ac_add_options --disable-libnotify
ac_add_options --enable-official-branding
ac_add_options --enable-safe-browsing
ac_add_options --enable-strip
EOF
time make -f client.mk build
make -f client.mk install
cd ..
rm -rvf moz*
cat >> /etc/ld.so.conf << "EOF"
# Extra Path so Firefox's libraries can be used by Flash10
/opt/firefox5/lib/firefox-5.0
# End of Extra Path.
EOF
wget http://curl.haxx.se/download/curl-7.20.0.tar.bz2
cd /dev/shm
tar -xjvf /sources/extras/curl-7.20.0.tar.bz2
cd curl-7.20.0
./configure --prefix=/usr
make $CORES_TO_USE
make install
find docs -name "Makefile*" -o -name "*.1" -o -name "*.3" | xargs rm
install -v -d -m755 /usr/share/doc/curl-7.20.0
cp -v -R docs/* /usr/share/doc/curl-7.20.0
wget http://fpdownload.macromedia.com/get/flashplayer/current/install_flash_player_10_linux.tar.gz
tar -xzvf install_flash_player_10_linux.tar.gz
mkdir -v /opt/firefox5/lib/firefox-5.0/plugins
cp -v libflashplayer.so /opt/firefox5/lib/firefox-5.0/plugins
cp -v ./usr/bin/flash-player-properties /usr/bin/
Add this to the openbox menu.xml file:
<item label="flash player properties">
<action name="Execute">
<execute>
/usr/bin/flash-player-properties
</execute>
</action>
</item>
Download Java from here. OR:
wget http://download.oracle.com/otn-pub/java/jdk/6u26-b03/jdk-6u26-linux-i586.bin
mv jdk-6u26-linux-i586.bin* jdk-6u26-linux-i586.bin
chmod +x /sources/extras/jdk-6u26-linux-i586.bin
cd /dev/shm
/sources/extras/jdk-6u26-linux-i586.bin
cd jdk1.6.0_26
install -v -m755 -d /opt/jdk-6u26
mv -v * /opt/jdk-6u26
chown -v -R root:root /opt/jdk-6u26
ln -v -sf xawt/libmawt.so /opt/jdk-6u26/jre/lib/i386/
cd ..
sed -i 's@XINERAMA@FAKEEXTN@g' /opt/jdk-6u26/jre/lib/i386/xawt/libmawt.so
ln -v -nsf jdk-6u26 /opt/jdk
ln -sv /opt/jdk/jre/lib/i386/libnpjp2.so /opt/firefox5/lib/firefox-5.0/plugins
cat >> /etc/profile.d/30-jdk.sh << "EOF"
# Begin /etc/profile.d/30-jdk.sh

# Set JAVA_HOME directory
JAVA_HOME=/opt/jdk

# Adjust PATH
pathappend ${JAVA_HOME}/bin PATH

# Auto Java CLASSPATH
# Copy jar files to, or create symlinks in this directory
AUTO_CLASSPATH_DIR=/usr/lib/classpath
pathprepend . CLASSPATH
for dir in `find ${AUTO_CLASSPATH_DIR} -type d 2>/dev/null`; do
pathappend $dir CLASSPATH
done

export JAVA_HOME CLASSPATH
unset AUTO_CLASSPATH_DIR
unset dir

# End /etc/profile.d/30-jdk.sh
EOF
source /etc/profile
If you have installed openoffice:
ln -sv /opt/openoffice-3.2.1/program/libnpsoplugin.so /opt/firefox5/lib/firefox-5.0/plugins

Friday, 24 June 2011

Parameter Substitution

That is a bloody boring title for a blog post. AAAAAnyway, it means that when you are farting around with variables holding filenames in bash scripts, or single commands, you may want to edit the file name. For instance, remember in the PDF compression script we strip the file extension off the filename and add .pdf to create the output filename. Very useful.

This post was prompted by trying to compress a 1000+ page pdf document. The pain was that the pdfimage command only switches to 4 digit file names at 1000. So for 1-999 you get 001 etc instead of 0001. This has the potential to screw everything up when you come to compile your final pdf. You do not want page 1000 to be before page 200, just because it starts with a lower number.

So how do we insert the missing 0?

for file in imageroot-???.*; do mv $file  imageroot-0${file#imageroot-}; echo $file; done

Friday, 17 June 2011

Gnuplot

If you are using the last LTS of Ubuntu, then your Gnuplot version will be out of date. You can't get fancy stuff like transparent surface plots. To download and install the latest version you need to run these commands:

cvs -d:pserver:anonymous@gnuplot.cvs.sourceforge.net:/cvsroot/gnuplot login
cvs -z3 -d:pserver:anonymous@gnuplot.cvs.sourceforge.net:/cvsroot/gnuplot co -P gnuplot
cd gnuplot
./prepare
./configure --with-readline=gnu
make
sudo make install

This will break your Ubuntu packaging system though - so be careful.

Friday, 10 June 2011

Ktikz

If you are doing quite a bit of Latex work with the Tikz graphical librarys then you will probably like to use a wysiwyg program so that you can tweak your wonderful creations. Such a program for Ubuntu is ktikz.

To install it you need to install the latest version of TexLive. If using Ubuntu Natty or later then I think you get the latest version by:

sudo apt-get install texlive

With Maverick or earlier, you need to install the latest version manually to get all the bells and whistles:

wget http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz
tar -xzvf install-tl-unx.tar.gz 
cd install-tl-20110526/
sudo ./install-tl

The install will then run through - takes about an hour to download the stuff. You can also download the DVD image via torrent, which would be a good way to have a backup for quick reinstall. Once installed, you need to make sure you update your path:

PATH=/usr/local/texlive/2010/bin/i386-linux:$PATH

Installing the ktikz software is a bit easier. You just run the following commands to grab the dependencies in case you do not have them. BTW this is for Lucid only. There isn't a package for Maverick or Natty yet, but you could roll your own.

sudo apt-get install build-essential cmake libqt4-dev qt4-dev-tools libpoppler-qt4-dev kdelibs5-dev pgf preview-latex-style
wget http://www.hackenberger.at/ktikz/ubuntu_lucid/ktikz_0.10-1_i386.deb
sudo dkpg -i ./ktikz_0.10-1_i386.deb


You may need to preface some of the scripts with libraries to load:

\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}
\usetikzlibrary{through}

Friday, 3 June 2011

Compressing PDF files

If you have got a hold of a PDF file which comprises lots and lots of images and nothing else it may well be huge if the images are not compressed. You can fix this at the command line in ubuntu. You do this as follows:

You will need:

sudo apt-get install pdftk imagemagik

First you need to unpack the images from the PDF. Start this from a blank directory because we are going to automatically do things to all the files in this directory with a specific name.

pdfimages /path/to/filename.pdf imageroot

You get lots of:

imageroot-[three digit number].somethings

These somethings are either a ppm or a pbm filetype. These are very, very, basic graphic image dumps - like a bmp image. One is for texty stuff, and the other is for imagy stuff. I therefore use these filetypes as wildcards in the next command, but you would need to replace these with the correct image types that are generated by this command if your results are different. Such as if you choose to try and output jpeg files by using the [-j] option.

Next you compress each image to a pdf, one page long. This will not work properly if you did not start with a blank directory because we are going to command changes to be made to EVERY file in this directory with the extensions produced by the last command.

For colour sources, you need jpg compression:

for file in *.{ppm,pbm}; do convert -compress jpeg -quality 50 $file  ${file%.???}.pdf; echo $file; done

That applies the commands between the [do] and the [done] bits to all [file]s with the extension of either [{,}] [ppm] or [pbm]. The commands in the middle [convert] the image files into pdf files using [jpeg] [compress]ion with [quality] [50]%. You can obviously change the quality percentage to get the best results depending on your source material. The result is sent to a file whose name is constructed from the input [file] variable [$] less whatever three letter [???] extension [.] it has, plus the characters [.pdf]. The next bit just prints out the last filename processed so you can make sure it is doing something if you are processing LOTS of files.

For black and white sources you need fax compression:

for file in *.{ppm,pbm}; do convert -alpha off -monochrome -compress Group4 -quality 100 $file  ${file%.???}.pdf; echo $file; done

This is basically the same approach as last time, just with a change to the [convert] command. This time the [jpeg] stuff is gone, and we have the [-alpha off -monochrome -compress Group4 -quality 100] bit instead. I can't get the quality setting to do anything here. The Group4 refers to the particular brand of fax compression which is applied.

Finally we take all of those individual pdfs and we combine them into one big one. Again, this will not work properly if you did not start with a blank directory. This copies EVERY pdf which matches the search string (the imageroot*.pdf bit where * means anything) into the final pdf. The classic error here would be making your image root name too similar to your original pdf name, with the result that the built pdf incorporates the original - hardly reducing the file size!

pdftk imageroot*.pdf cat output name_of_final_file.pdf

That uses the [pdf] [t]ool[k]it program to take every [*] file that starts with [imageroot] and ends with [.pdf] and con[cat]enates them into the [output] file named [name_of_final_file.pdf].

Simples.

Friday, 27 May 2011

Testing Natty on Nvidia Hardware

The BIG THING about the Natty version of Ubuntu is that it comes with a prettified GUI. It has a pop out panel on the left hand side of the screen containing your launcher icons. This is absolutely NOT the same as Windows 7's task bar icons OR OSX's panel'o'icons because both of them are on the BOTTOM of the screen. Ahem.

Want to see what this looks like with the live cd? Have nvidia hardware? Tough shit. The nvidia driver installed on the live cd is a) open source (yay!) and b) does not support all the bells and whistles that this flashy new panel needs (boo!). So you will have to install the proper nvidia drivers. Which means rebooting. Which is pointless on a live cd.

Oh dear. This is going to be a pain in the fucking arse isn't it? Yes, yes it is.

For a start a couple of useful commands for this kind of fiddling are:

sudo service gdm stop

This stops dead the GUI leaving you to happily fiddle with graphics driver settings.

To restart the GUI you would just restart the gdm service yes? Yes.

sudo service gdm start

OK. So we have shut down the GUI. Now we want to download the nvidia drivers. I am presuming you have internet access from the LiveCD. If not, see my earlier posts on that hilarious situation. Download the drivers with this command:

wget http://uk.download.nvidia.com/XFree86/Linux-x86/270.41.19/NVIDIA-Linux-x86-270.41.19.run

Make the driver file executable:

sudo chmod +x NVIDIA-Linux-x86-270.41.19.run

And run it:

./NVIDIA-Linux-x86-270.41.19.run

You will now get some whining messages about nouveau bollicksing up the whole plan. This is the open source nvidia software we are trying to replace. So lets just [r]e[m]ove the nouveau [mod]ule:

rmmod nouveau

Doesn't fucking work.

sudo rmmod nouveau

Still doesn't fucking work. Google.

sudo rmmod --force nouveau

Oh for fucks sake. It still doesn't fucking work. It turns out the nouveau driver is deeply embedded in the OS. It ain't possible to just remove it. It has taken over something called the framebuffer. Without getting horrendously technical (shorthand for I have no fucking clue) this is the thing that gives you the text command line that you are using. So ubuntu is trying to stop you doing the I.T. equivalent of sawing off the branch you are standing on. If you turn off the framebuffer you will get a blank screen. Which is not great as far as user interfaces go, but still probably a better experience than Windows ME.

At this point you have two choices. First you can disable the in-depth use of nouveau, which will then allow you to remove it without fucking up the framebuffer. This needs to be done at boot time, each and every time you boot the LiveCD. Secondly, you can write a script that forces ubuntu to remove nouveau (fucking up the framebuffer in the process) and then immediately installs the nvidia drivers with the least input necessary.

The benefit with the first option is that you never get left with a blank screen, but it is a pain. The benefit with the second option is that it can all be scripted, but leaves you with a blank screen for several minutes while it installs the drivers. If it fails for any reason during the blank screen period, you're fucked.

So, option one first. Copy your downloaded driver file somewhere safe (USB Key). Or just download it again next time, what do I care. If you are using a LiveCD, reboot your LiveCD. When it starts back up it flashes up a symbol of a keyboard and a hand. Hit any key at that stage and you will get a boot menu. You want to chose to Test Ubuntu. You then want to hit F6 for other boot options.

If you are using the LiveCD image from a USB Key via UNetbootin, then just highlight the "Test..." option and hit the tab key to edit the boot command.

You should now be able to edit the boot command (it is a long string of options. See the joys of grub elsewhere in this blog for info on what this does). At the end of the boot command type in:

nomodeset

Now complete the boot as normal. Copy back, or re-download the nvidia driver to the home directory. Now, hit CTRL+ALT+F1 to get to a text interface, and make sure the driver file is executable:

sudo chmod +x NVIDIA-Linux-x86-270.41.19.run

:and shut down the GUI:

sudo service gdm stop

:and run:

sudo rmmod nouveau

It should now work. You can now install the driver:

sudo ./NVIDIA-Linux-x86-270.41.19.run

And it should eventually install happily. Answer the questions sensibly, ignoring any errors. Then just run this command to restart the GUI:

sudo service gdm start

Bask in the awe of the flashy bar.

Option 2 is handled like this. Boot as normal - no need for any fancy boot commands. Copy back, or re-download the nvidia driver to the home directory. Open a terminal window and paste this code into it to set up your script:

sudo cat > inst_nv.sh << "EOF"
echo 0 > /sys/class/vtconsole/vtcon1/bind
rmmod nouveau
/etc/init.d/consolefont restart
rmmod ttm
rmmod drm_kms_helper
rmmod drm
chmod +x ./NVIDIA-Linux-x86-270.41.19.run
./NVIDIA-Linux-x86-270.41.19.run --accept-license --no-questions --no-nouveau-check --run-nvidia-xconfig --ui=none
service gdm start
EOF
chmod +x ./inst_nv.sh

(What does this script do? Well, the first line is a command which disconnects the frame buffer from the graphics driver. I think. The second command removes the graphics driver. The third command attempts, but I think fails, to restore some sort of text interface. The next three commands remove more unneeded modules connected with the graphics driver. The [chmod] command makes sure that the nvidia file is executable, and the command after that executes it. All the options added onto the execution of the driver package are designed so that it should just install without asking any stupid questions which you will be unable to read. The last command restarts the GUI.)

You now shut down gdm as before from the CTRL+ALT+F1 text interface:

sudo service gdm stop

:and run the script from the text command prompt:

sudo ./inst_nv.sh

Your screen will go blank. Your cd/dvd drive will hopefully spin up and down. After 5 minutes or so, hopefully, you will get a GUI. If it doesn't work, reboot and try option 1.

And hey fucking presto, there is the snazzy new bar.

Admittedly, after all that, it may be a touch underwhelming.

Friday, 20 May 2011

Manually Add DNS Servers

My work machine is an Ubuntu machine on a Microsoft Small Business Server network. It gets all of its network settings by way of DHCP from the SBS Server. Sometimes the SBS Server has to be restarted. Most of the software I use can run offline, so that is nor normally a problem.

What is a problem is that I immediately lose internet access because the SBS Server operates as a [DNS]. This is frustrating. Helpfully, Ubuntu has an option to manually add some extra DNS's which SHOULD take over the burden from the SBS Server if it goes down.

To achieve this (in Lucid), go System -> Administration -> Network.

From the program that pops up, select the Network Device drop down menu. Choose your network device. This will be ethX if you are connected by a wired connection. Then click on the Configure button next to the device name. From the new window that pops up, choose the DNS tab. You then need to click on the button between the Help and Close buttons at the bottom of the window, and putin your admin password to allow you to change the settings.

Now, just click on Add, and type in your new DNS IP address.

Hopefully this change means that the next time the server goes offline, I can still use the internet.