Archive

Archive for the ‘System Admin’ Category

Trac-BZR: installing on Ubuntu/Debian

September 15th, 2009 admin No comments

A project I’m working on recently switched from Subversion (SVN) to Bazaar (BZR) for its Version Control System (VCS). Of the many things we didn’t like about Subversion (merging, line-ending conflicts, etc..), there were some things we’d grown to like, primarily the mature 3rd party ecosystem and its bread-winner Trac.Thankfully there are projects to extend Trac’s reach to other VCSs.

Of interest to me was trac-bzr. Since Bazzar has the power of Canonical behind it, a cursory glance at the “universe” repository shows a package named “trac-bzr”. However a closer look reveals that this package is quite outdated:

>apt-cache show trac-bzr
Package: trac-bzr
Priority: optional
Section: universe/python
Installed-Size: 156
Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
Original-Maintainer: Chris Lamb <chris@chris-lamb.co.uk>
Architecture: all
Version: 0.2+bzr31-3
...

This seemed like a bad idea, seeing as the main branch was already at r69.

Here are the instructions on installing the latest version:

1. Make sure you have bzr installed

sudo apt-get install bzr

2. Get the latest version of trac

sudo apt-get install trac

3. Get the latest version of trac-bzr, and put it in a revisioned directory.

bzr export ./trac-bzr-r`bzr revno lp:trac-bzr` lp:trac-bzr

4. Install the plugin

cd trac-bzr-r*
python setup.py install

5. Configure trac to use the plugin as described in the trac-bzr README

Categories: System Admin, Ubuntu Tags:

svn2bzr and symlinks

August 26th, 2009 admin No comments

I used svn2bzr to import an Subversion repository (via dump file) to a Bazaar repository. My code has some places where symlinks are used. After the import, the symlinks were converted from links to files with the contents:

link ../path/to/link

I ran this snippet to find all locations of this event so I could fix them:

find . -size 1k -exec grep -E "^link" '{}' \; -print

Hope that helps.

Update: Wrote a script that will remove the old links and replace them for you.

#!/bin/bash

if [ $# -eq 1 ]
then
DIRNAME=$1
else
DIRNAME=`pwd`
fi

broken_links=`find $DIRNAME -size 1k -exec grep -Es "^link" '{}' \; -print \
| xargs -l2 echo -e "" | awk '{print $2 " " $3}'`

echo -e "$broken_links" | while read line; do
link=`echo "$line" | cut -d ' ' -f2`;
target=`echo "$line" | cut -d ' ' -f1`;
relative_dir=`dirname $link`

cd $relative_dir; rm $link; ln -s $target $link
done
Categories: System Admin Tags:

Finding Out Your External IP Address from the Shell

October 11th, 2008 admin No comments

I’m writing a script that needs to know the external IP address of the current machine (ifconfig only gives the local network address)

wget -q -O - http://checkip.dyndns.org | html2text \
| sed s/Current\ IP\ Address\:\ //

What this does is:

  1. hit http://checkip.dyndns.org, silencing wget’s output and redirecting the downloaded file to stdout
  2. parse the html page as text
  3. get rid of the cruft (I was thinking about using a complex regex here, but the IP address prefix seems less of a dependency concern than the actual dyndns service)
Categories: System Admin Tags:

The closest thing to piping a password to SSH

February 26th, 2008 admin No comments

There are a few cases in life where you want to connect to SSH without having to type in the password by hand. Most of the times you can use ssh-keygen and use private (or public) keys.

However, for the 0.5% of the time where you cannot use keys, you can use a little program called expect.

BTW, this does not, and should NEVER work:
echo 'mypassword' | ssh user@server

Installing Expect:
sudo apt-get install expect

Create the expect script:
nano connect.sh

Paste the basic code:

#!/usr/bin/expect
set timeout 60
spawn ssh -l username server
expect "password: $"
send "password\n"
expect "$ $"
interact

Replace ‘username’ and ’server’ on line 3 and ‘password’ on line 5.
The second to last line, ‘expect “$ $”‘ is for a bash shell. Replace the first ‘$’ with whatever your prompt is.

Save ( ctrl + o ) and Exit ( ctrl + x )
Make the script executable
chmod +x connect.sh

Credits

Categories: System Admin, Ubuntu Tags: