Category: Linux/Unix

Installing SVN With Web Access Through Apache On Ubuntu

1 April, 2009 | Apache, Linux/Unix | 2 comments

Getting started with SVN on Ubuntu takes only a few minutes, and enabling web access to the repository is also very straightforward.

First (in order to actually serve the files) you need to install Apache, open up a terminal window and run the following command. This will ensure that Apache is installed if you unselected it for some reason during the install.

sudo apt-get install apache2

Note the use of the sudo command. This will run the command you give it as a super user as normal users will not generally have access to install software like this. When you use sudo you will be prompted for the super user password. Next, use the following command to install SVN.

sudo apt-get install subversion libapache2-svn

You can now create your subversion repository, it is best to keep all of our repositories under the same directory so that things don't get confusing in the long run. To create the SVN directory run the following.

mkdir svn

The following will create the repository in the directory /svn/myproject.

sudo svnadmin create /svn/myproject

Now we will need to edit some of the settings in our Apache SVN module. Use the following command to edit the correct file.

sudo gedit /etc/apache2/mods-enabled/dav_svn.conf

When you first open this file it is all commented out. You first need to uncomment the Location. This is the directory where subversion will be available from on the Apache side. Here I am setting this to svn so that when I navigate to http://127.0.0.1/svn I will see the correct output.

<Location /svn>

Note that you must also uncomment the closing location tag at the bottom of the document!

Uncomment the DAV line to enable the repository, this enables the DAV module.

DAV svn

If you have a single repository then then enable the SVNPath setting. However, if you have multiple repositories then enable the SVNParentPath setting. this will point to the main directory where your repository (or repositories) is stored.

SVNParentPath /svn

That's about it really, but as a further step lets enable some sort of authentication. You will need to uncomment the following lines (which are grouped together).

AuthType Basic AuthName "Subversion Repository" AuthUserFile /etc/apache2/dav_svn.passwd

And the following line.

Require valid-user

Now, before we restart our Apache server and enable everything you have done we need to setup a username and password for the authentication to work. Use the following command to create a user and assign a password.

sudo htpasswd2 -cm /etc/apache2/dav_svn.passwd user

If this doesn't work then try using htpasswd instead of htpasswd2. You should be prompted to enter your password twice and then receive a message telling you that the user has been created. Note that you should only use the -c option when you create a user for the first time because it creates the password file even if it is already there. If you use this option again in the future you will destroy any other users you have created. Instead, simply drop the -c and use -m on its own which causes the password to be MD5 encrypted, but will not recreate the file.

You can now restart the server by entering the following command.

sudo /etc/init.d/apache2 restart

You might initially try a short cut and do something like the following:

sudo apache2 restart

However, this will not work as the script in /etc/init.d/apache2 explicitly reads some environment variables that are important when starting the server.

You can now go to your subversion directory and see the following:

SVN Web Access

SVN Web Access

You will also see an authentication window appear, just use the username and password you set up before.

You now have a fully working subversion server with web access.

Written by Philip Norton.

DVD Backup With Linux

9 March, 2009 | Linux/Unix | 1 comment

If you are part of a company the chances are that you have either set up or are aware of a backup policy for your data. However, even if you are not then you might have the need to backup certain items to a DVD drive.

DVD burning is accomplished in Linux by using the mkisofs and growisofs programs. This can be run in either a two stage or a single stage process. The mkisofs program is used to create an iso file that is then written to the DVD using the growisofs program. The following will take three files and create an iso called toburn.iso, this will then be used to write the data to the DVD.

mkisofs -J -R -pad -o toburn.iso text.txt accounts.csv secret.txt growisofs -Z /dev/hdc=toburn.iso -speed=2

The growisofs program can act as a wrapper for mkisofs and so the mkisofs step can be left out, as long as the destination directory and files are given. The -Z and -speed parameters are only used in the growisofs program, every other parameter is passed onto mkisofs.

growisofs -J -R -Z /dev/hdc -speed=2 text.txt accounts.csv secret.txt

To write more than one directory to the DVD you need to define the directories like this.

growisofs -J -R -Z /dev/hdc -speed=2 -graft-points /directory1=/home/user/directory1 /directory2=/home/user/directory2

The DVD will now contain directory1 and directory2. If this is not done then the DVD would mix up any directories that have the same name.

You can also use the -dvd-compat parameter with growisofs to improve the compatibility of the media with other DVD drives. With DVD+R and DVD-R this results in a closed disk, with DVD+RW the lead-out section is explicitly burnt to the disk.

Of course, if you are writing a piece of software or creating a movie then you might want to burn a large number of DVDs in one go, if this is the case then you might be better off using some sort of DVD replication service. This saves you the time and effort of burning the DVDs and applying the labels.

Written by Philip Norton.

Find And Replace On All Files In And Below A Directory

9 October, 2008 | Linux/Unix | No comments

The following shell command uses the find function to find all files in or below the current directory that have the extension php. It then passes each file found onto a sed command which then replaces all <? with the longer &lt?php version.

find . -name '*.php' -exec sed -ie 's#<?#<?php#' {} \;

The -name argument in find will look at the base of the file name, that is, the file without any directory path. The -exec command is used to pass each file found onto another command, in this case sed is used.

Written by Philip Norton.

Using !$ To Use Last Parameter

22 July, 2008 | Linux/Unix | No comments

Much like using Alt+. to print out last parameter you can also use !$ to use the last parameter from the previous command. Here is a simple example.

# cd .. # cd !$

In this example we are moving up a directory and then doing the same action again, the !$ is a short cut to get hold of the ... This is more useful when doing things with longer parameters like directory or file names. For example here we are creating a directory and then moving into that same directory.

# mkdir /www/htdocs/directory/ # cd !$

Written by Philip Norton.

Raising Skinny Elephants Is Utterly Boring

21 July, 2008 | Linux/Unix | No comments

This might sound odd, but this is a mnemonic that helps you remember a sequence of letters that you can enter when your Linux system is locked. This is a last ditch attempt to get things up and running again and should only be used if all else fails and the only other thing that you can do it pull the plug.

If you have also tried pressing Ctrl+Alt+backspace and this does nothing then you can try using the key sequence Raising Skinny Elephants Is Utterly Boring.

Hold down the left Alt key and the SysRq key (found on the print screen button) and press each letter in turn. Make sure that you give a little time between keystrokes.

  • r
  • s
  • e
  • i
  • u
  • b

Here is a description of what you are doing.

  • The r stands for put keyboard in raw mode.
  • The s for sync the disk.
  • The e for terminate all processes.
  • The i for kill all processes.
  • The u for remount all filesystems read only.
  • The b for reboot the system.

Also, if your filesystem is Ext3 or ReiserFS and on reboot it wants you to do a filesystem check, don't touch any key when it asks you to press "Y" and let it recover the journal automatically.

Also note that for this to work you need to have the SysRq key enabled in the Linux kernel, also called CONFIG_MAGIC_SYSRQ. You can check if it is enabled by typing:

ls /proc/sys/kernel/sysrq

If this prints out a line with that word then the key is enabled.

Written by Philip Norton.