Monthly Archives: February 2013

Checkout specific patchset of FreeBSD sources

Following is a script to checkout FreeBSD sources (from its subversion repository) to specific patch-level as asked by a friend on IRC:

#!/bin/sh

if [ -z "$1" -o -z "$2" ]; then
        echo Usage: $0 release patchlevel
        echo e.g. To get 8.0-p5, $0 8.0 5

        exit 0
fi

RVER=$1
PVER=$2

SVNBASE=svn://svn.freebsd.org/base/releng
NEWVERS=sys/conf/newvers.sh
LIMIT=40
RETVAL=0

SVNLOG=$(mktemp -t $(basename $0))

if svn log -l $LIMIT $SVNBASE/$RVER/$NEWVERS >$SVNLOG; then
        BASEREV=$(awk 'BEGIN { sec=1; i=0; } /^r[[:digit:]]+/ { sec=0; revs[i++]=rev=$1; } /^(Security|Errata):/ { sec=1; } /^-+$/ { if(sec == 0) { print revs[i-'$PVER'-1]; exit 0; } }' <$SVNLOG)
        echo svn co -$BASEREV $SVNBASE/$RVER
else
        echo Error executing svn log
        RETVAL=$1
fi

rm -f $SVNLOG
exit $RETVAL

Obligatory screenshot:

chateau.d.if!abbe [~/bin] % co-freebsd-sources 7.0 4
svn co -r182740 svn://svn.freebsd.org/base/releng/7.0
chateau.d.if!abbe [~/bin] % svn cat -r 182740 svn://svn.freebsd.org/base/releng/7.0/sys/conf/newvers.sh|grep RELEASE-p
BRANCH="RELEASE-p4"
Download link: http://www.lostca.se/~abbe/scripts/co-freebsd-sources
SHA256 sum: c9958c4fd7cae5a5e9ff3fa84ba3af6adf38d9c8494b7913ad5b3a2f265a3f48

IRC proxy-ing

Sometime ago, I’ve received SSH access to a host which was quite restricted. Lots of executables are denied execution, as it was supposed to be only for learning, so no network access curl/wget/nc/socat/ssh -(L|D|R), or compilers, but then it’s got bash. Here is a tiny hack to connect to IRC from that host:

1. Create a file irc.sh on $host:

#!bash
exec 3<>/dev/tcp/irc.freenode.net/7070
cat <&3 &
cat >&3

2. Add following line to inetd/xinetd (or netcat):

sua     stream  tcp     nowait          $localuser    /usr/bin/ssh    ssh -i $privatekey -l $user $host bash irc.sh

3. Now connect your IRC client to localhost:sua (localhost:14001).

This is only a fun hack, and not something used to regularly circumvent access. 😛

ldd.sh

On numerous occasions, I need to find the direct shared library dependencies (for ELF ofcourse), and not what ldd(1) outputs. And at all those occasions, I’d to RTFM objdump(1) everytime, and now since I plan to ditch laziness, here is a script which I wrote:

#!/bin/sh

if [ -n "$1" ]; then
	objdump --all-headers $1|awk '/^[[:space:]]*NEEDED/ { print "'$1' "$2; }'
else
	echo Usage: $0 file.so
fi

Obligatory screenshot:

chateau.d.if!abbe [~] % ldd.sh /bin/ls
/bin/ls libutil.so.9
/bin/ls libncurses.so.8
/bin/ls libc.so.7

HTH