Record of some of the computer tech I deal with so that it's documented at least somewhere.

Tuesday, 17 August 2010

Backing up Venti

This code cycles through the arenas and if it's not sealed, dump it to dvd formatted iso

#!/usr/local/plan9/bin/rc

path=(/usr/local/plan9/bin $path)
cd /home/venti/dumps

fn arenas {
wget -O - -q http://127.0.0.1:808/index | awk '
BEGIN { FS=" | |="}
/^arena/ { printf "%s", $2}
$2 == "score" { printf " %s", $3 }
$2 == "indexed:" { printf "\n" }
'
}

fn extract {
venti/rdarena /home/venti/arenas $1 | gpg --homedir /home/maht/.gnupg -e -r maht@maht0x0r.net > $1/$2
mkisofs -udf -o $1.$2.iso $1
}

fn process_arenas {
ifs = '
'
for(a in `{arenas}) {
ifs=' '
i = `{echo -n $a}
mkdir $i(1)
if(~ $#i 2) {
rm -f $i(1) ^.unsealed.iso
if(! test -e $i(1) ^. ^$i(2) ^.iso)
extract $i(1) $i(2)

}
if not {
extract $i(1) unsealed
}
rm -rf $i(1)
}
}

process_arenas

Wednesday, 11 August 2010

Importing BASH style config files into rc

So you're got some config in a bash style, something like this
% cat /usr/local/courier/etc/imapd
ADDRESS=0
PORT=143
MAXDAEMONS=80
MAXPERIP=25
PIDFILE=/var/run/imapd.pid
TCPDOPTS="-nodnslookup -noidentlookup"
LOGGEROPTS="-name=imapd"
IMAP_CAPABILITY="IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE"
IMAP_KEYWORDS=1
IMAP_ACL=1
IMAP_CAPABILITY_ORIG="IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA AUTH=CR
AM-MD5 AUTH=CRAM-SHA1 AUTH=CRAM-SHA256 IDLE"
IMAP_PROXY=0
IMAP_PROXY_FOREIGN=0
IMAP_IDLE_TIMEOUT=60
IMAP_MAILBOX_SANITY_CHECK=1
IMAP_CAPABILITY_TLS="$IMAP_CAPABILITY AUTH=PLAIN"
IMAP_CAPABILITY_TLS_ORIG="$IMAP_CAPABILITY_ORIG AUTH=PLAIN"
IMAP_DISABLETHREADSORT=0
IMAP_CHECK_ALL_FOLDERS=0
IMAP_OBSOLETE_CLIENT=0
IMAP_UMASK=022
IMAP_ULIMITD=65536
IMAP_USELOCKS=1
IMAP_SHAREDINDEXFILE=/usr/lib/courier-imap/etc/shared/index
IMAP_ENHANCEDIDLE=0
IMAP_TRASHFOLDERNAME=Trash
IMAP_EMPTYTRASH=Trash:7
IMAP_MOVE_EXPUNGE_TO_TRASH=0
SENDMAIL=/usr/sbin/sendmail
HEADERFROM=X-IMAP-Sender
IMAPDSTART=YES
MAILDIRPATH=Maildir


and you want to import it into rc

I give you

fn import_bash {
. <{ 9 sed -e 's/"//g' -e 's/=/=(''/' -e 's/(.)$/&'')/' \
-e 's/''(\$[^ ]+) /\1 ''/' -e 's/''(\$[^ ]+) ''/\1/' \
| awk ' /OPTS/ && / / { gsub(/ /, "'' ''") } { print } ' }
}


the bit inside the . <{} turns the bash into

ADDRESS=('0')
PORT=('143')
MAXDAEMONS=('80')
MAXPERIP=('25')
PIDFILE=('/var/run/imapd.pid')
TCPDOPTS=('-nodnslookup' '-noidentlookup')
LOGGEROPTS=('-name=imapd')
IMAP_CAPABILITY=('IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE')
IMAP_KEYWORDS=('1')
IMAP_ACL=('1')
IMAP_CAPABILITY_ORIG=('IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA AUTH=C
RAM-MD5 AUTH=CRAM-SHA1 AUTH=CRAM-SHA256 IDLE')
IMAP_PROXY=('0')
IMAP_PROXY_FOREIGN=('0')
IMAP_IDLE_TIMEOUT=('60')
IMAP_MAILBOX_SANITY_CHECK=('1')
IMAP_CAPABILITY_TLS=($IMAP_CAPABILITY 'AUTH=PLAIN')
IMAP_CAPABILITY_TLS_ORIG=($IMAP_CAPABILITY_ORIG 'AUTH=PLAIN')
IMAP_DISABLETHREADSORT=('0')
IMAP_CHECK_ALL_FOLDERS=('0')
IMAP_OBSOLETE_CLIENT=('0')
IMAP_UMASK=('022')
IMAP_ULIMITD=('65536')
IMAP_USELOCKS=('1')
IMAP_SHAREDINDEXFILE=('/usr/lib/courier-imap/etc/shared/index')
IMAP_ENHANCEDIDLE=('0')
IMAP_TRASHFOLDERNAME=('Trash')
IMAP_EMPTYTRASH=('Trash:7')
IMAP_MOVE_EXPUNGE_TO_TRASH=('0')
SENDMAIL=('/usr/sbin/sendmail')
HEADERFROM=('X-IMAP-Sender')
IMAPDSTART=('YES')
MAILDIRPATH=('Maildir')



The tricky part was the OPTS, they need to be passed individually not as one string.
Sadly that means keeping an eye on when such things are needed and changing the awk guard appropriately.

Monday, 2 August 2010

UvesaFB

just a mirror of

http://dev.gentoo.org/~spock/projects/uvesafb/

in case it ever disappears

projects::uvesafb

uvesafb is a generic framebuffer driver for Linux systems and the direct successor of vesafb-tng. Its main features are:

* works on non-x86 systems,
* the Video BIOS code is run in userspace by a helper application,
* can be compiled as a module,
* adjustable refresh rates with VBE 3.0-compliant graphic cards.

uvesafb has been available as a part of the mainline Linux kernel since 2.6.24.
uvesafb::v86d

v86d is the userspace helper that runs x86 code in an emulated environment. uvesafb will not work without v86d. v86d currently supports the x86 and amd64 (x86-64) architectures.
Latest version v86d-0.1.9.tar.bz2
GIT repository v86d.git
uvesafb::installation instructions

uvesafb is included in gentoo-sources >= 2.6.23 and from 2.6.24 onwards also in the mainline kernel. If you happen to be using any of these, you don't have to patch your kernel manually. Otherwise, just download the patch using the link above and run cd /usr/src/linux ; cat uvesafb-0.1-rc3-2.6.23-rc3.patch | patch -p1

The guide below assumes you're using Gentoo Linux. If you happen do be using another distro, replace all emerge steps with unpack ; ./configure ; make ; make install or similar.

1. cd /usr/src/linux
2. configure the kernel; in the "Device Drivers" section select:
Connector - unified userspace <-> kernelspace linker and
Graphics support ---> Support for frame buffer devices ---> Userspace VESA VGA graphics support
(that's CONFIG_CONNECTOR=y and CONFIG_FB_UVESA=y)
3. build the kernel: make
4. remerge klibc: emerge klibc
note: This step is necessary because klibc has to be compiled against a kernel tree that includes uvesafb. You only need to do this once, i.e. you won't have to remerge klibc every time you install a new kernel or a new kernel module.
5. install v86d: emerge v86d
6. reconfigure your kernel; in the "General Setup" section select:
Initial RAM filesystem and RAM disk (initramfs/initrd) support
and use /usr/share/v86d/initramfs in Initramfs source file(s).
(that's CONFIG_INITRAMFS_SOURCE="/usr/share/v86d/initramfs")
7. rebuild the kernel: make, and install it
8. add video=uvesafb:1024x768-32,mtrr:3,ywrap (or similar) to your kernel command line
9. reboot and enjoy uvesafb :)

NOTE: The older versions of klibc seem to have problems with the new unified arches in the kernel (2.6.24). To avoid these issues, use klibc-1.5.8 or newer. Thanks to David Raison for pointing this out.