Monday, 23 June 2014

Editing files using bash scripts and sed

Sometimes you need to edit a setting in a conf file from a bash script.
Here's a little script that installs ntp, and edits configuration files using the sed command.

First this script removes any previous ntp servers from /etc/ntp.conf
    #remove ntp server lines
    sed -i".bak" '/^server/d' /etc/ntp.conf
the -i".bak" creates a backup of the file before changing it.
the caret ^ symbol means the start of the line. So ^server means any lines starting with "server"
the d at the end means delete the line

with all these lines removed we can add the ntp server line back in. We use >> to append the new "server" line to the end of the conf file.
    #add the local ntp server
    echo "server iburst" >> /etc/ntp.conf
Another way to edit files can be like a search and replace.
    sed -i 's/^UTC$/LOCAL/' /etc/adjtime
so we search for ^UTC$
^ means the start of a line, $ means the end of a line
^UTC$ matches lines that contain UTC and nothing else
We then specify some text to replace UTC with, in this case it's LOCAL.

Here's the complete script.

Wednesday, 18 June 2014

Installing netbeans 8.0 on debian wheezy

We provide over 200 debian wheezy desktops in student labs and are currently getting another desktop image ready for the next academic year. Here's the steps we took to install netbeans 8.0 along with a script to add some post install tweaks. These desktops are multi-user, running the Mate desktop. To do a multi-user install of netbeans, you need to run the installer as root.
  1. log in as a normal user.
  2. download the netbeans installer from
  3. su to root in a terminal.
  4. run the netbeans installer from the command line at the root prompt.
  5. click the customize button to install glassfish and tomcat.
  6. change the install path for each package to /opt/<name of package>
Once done, we needed to perform some post-install tweaks.
  • We needed to fix permissions to the installed files and directories.
  • The netbeans menuitem did not appear and so that needed to be added.
  • And the third tweak was a workaround with the mouse focus not matching the mouse pointer and disappearing menus as described in this bug
To make things easy, here's a bash script to do the above tweaks.

We run the Mate desktop environment and so this script sets the DESKTOP_SESSION variable to mate for the netbeans process. If you use gnome3 then DESKTOP_SESSION=gnome-shell is what you want. Edit the script accordingly. This environment variable is used to get around the disappearing menus/mouse pointer bug.

Thursday, 5 June 2014

Modifying Dependencies in a deb

I recently needed to install evoluspencil onto debian wheezy, but the deb install fails because of unmet dependencies. The deb is looking for firefox, but the debian project renames firefox to iceweasel and so the dependency cannot be met. One solution is to modify the evoluspencil debian package to allow iceweasel to satisfy the dependency. Here's a video of the steps, which are laid out in comment #5 of this bug report.
mkdir pencil
dpkg-deb -x evoluspencil_2.0.5_all.deb pencil/
dpkg-deb --control evoluspencil_2.0.5_all.deb pencil/DEBIAN
nano pencil/DEBIAN/control  # edit -> Depends: firefox|iceweasel
dpkg -b pencil/ evoluspencil_2.0.5_debian.deb
sudo dpkg -i evoluspencil_2.0.5_debian.deb