Bergen 3D
Posted by Stian | Filed under Linux, UiB
I’ve spent some time working on a virtual 3d bergen as a part of INF251 (Computer Graphics) this semester. Basically what we did was to render the terrain based on a height map (a file containing a height value at every x,y position), modeled some buildings, added textures, spline based camera paths.. etc..
Mine was developed on linux and uses Glut, GLEW, GLM, DevIL, Vmath.. etc.. You can fly around in Bergen using FPS-style controls (WASD+RF/mouselook).
See my page over at the university for som larger screenshots and a movie..
Automated offsite backup.
Posted by Stian | Filed under Linux
In order to sleep better at night I’ve decided to be better at taking backups of important data. Knowing myself it would need to be automated, and also preferably offsite. Also didn’t want to depend on my own servers (since they are down from time to time, lately I’ve been fighting an ethernet switch that stops working until someone cycles the power.. very annoying, it’s getting replaced now..).
I had a look at amazon S3, which seems to be fairly popular these days. $0.15 per gb per month of storage, and a little bit for bandwidth. That’s basically free for my storage needs, especially considering the current dollar value (when are they going to rename it american pesos?). Sounds great, cheap offsite backup. However I want to encrypt my data, since I don’t trust anyone further than I can throw them in matters like this, and it’s hard to throw someone the size of amazon..
I had a look around and found duplicity, which does encrypted incremental backups. It’s made in python and uses librsync, it supports loads of different destinations - for example scp, rsync, ftp and even S3!
So I installed the newest version of duplicity and it’s dependencies ( boto - for S3 support, the rest can be found in most distributions ) and also made a GPG-key specifically for backup use (gpg –gen-key).
And made a little script:
#!/bin/bash
# Amazon S3 keys:
export AWS_ACCESS_KEY_ID="XXXXXXXXXXXXXXXXXX"
export AWS_SECRET_ACCESS_KEY="XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# GPG passphrase and key:
export PASSPHRASE=XXXXXXXX
GPG_KEY=XXXXXXXX
# MYSQL password:
MYSQLPW=XXXXXXXX
DATE=`date +%d`
SOURCE=/
DEST="s3+http://nameofyourbackupbucket"
mysqldump --all-databases --password=$MYSQLPW > /root/mysql/mysql-backup.sql
# Force a full backup twice a month..
if (( "$DATE" % 15 == "0" )) ; then
duplicity full \
--include-globbing-filelist /root/backuplist.txt \
--encrypt-key "$GPG_KEY" \
--sign-key "$GPG_KEY" \
--exclude=/** \
$SOURCE $DEST
# Don't really need more than 2 months of backup..
duplicity remove-older-than 2M $DEST
else
duplicity \
--include-globbing-filelist /root/backuplist.txt \
--encrypt-key "$GPG_KEY" \
--sign-key "$GPG_KEY" \
--exclude=/** \
$SOURCE $DEST
fi
export AWS_ACCESS_KEY_ID=
export AWS_SECRET_ACCESS_KEY=
export PASSPHRASE=
Everything i want to backup is listed in the file backuplist.txt, and the script runs once every night using cron…. This should cover my backup needs, if I only remember to backup my GPG-key :p
Asterisk - Resolve callerid using online phone directories.
Posted by Stian | Filed under Linux, Teknologi
Here’s how to automatically resolve incoming callerids using a public online phone directory with a bit of PHP.
First you need a few packages installed.. php(4/5)-cli and php(4/5)-curl.. Copy the following code and save it as a file (’resolvnum.agi’) in your agi-bin directory, most likely /usr/share/asterisk/agi-bin. Make sure it’s executable: chmod +rx resolvnum.agi
#!/usr/bin/php -q
<?php
// Do not wait more than 4 secs..
ob_implicit_flush(false);
set_time_limit(5);
$stdin = fopen("php://stdin", "r");
$stdout = fopen("php://stdout", "w");
// Get all agi-variables from asterisk via stdin:
while (!feof($stdin)) {
$temp = fgets($stdin);
$temp = str_replace("n", "", $temp);
$s = explode(":", $temp);
$agivar[$s[0]] = trim($s[1]);
if (($temp == "") || ($temp == "n"))
break;
}
// Get callerid from agi-variables.
$callerid = $agivar['agi_callerid'];
if (!is_numeric($callerid)) exit(1);
// Set up curl:
$user_agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = @curl_init("http://www.kvasir.no/telefonkatalog/searchresult.html?q=".$callerid."&x=0&y=0/");
@curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
@curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
@curl_setopt($ch, CURLOPT_TIMEOUT,4);
// Fetch us some data...
$html = str_replace("r", "", @curl_exec($ch));
curl_close($ch);
// Got nothing? Oh, bother...
if (!$html) exit(0);
// Replace Norwegian characters..
$html = str_replace(array(chr(230), chr(248), chr(229), chr(198), chr(216), chr(197)),
array("ae", "oe", "aa", "AE", "OE", "AA"), $html);
// Try to match some names..
preg_match_all("|<h4 class=\"forste_linje\">n(.*)n</h4>|U", $html, $names, PREG_SET_ORDER);
// Yay, we found something, set calleridname.. leave number alone..
if (isset($names[0][1])) {
fputs($stdout,"SET CALLERID \"".$names[0][1]." (".$callerid.") <".$callerid.">\"n");
fflush($stdout);
}
exit(0);
?>
Then add the agi to your incoming extensions in extensions.conf. Mine is set up like this:
[from-sip] exten => 85XXXXXX,1,AGI(nummeroppslag.agi) exten => 85XXXXXX,2,Macro(dialer,101,SIP/101&SIP/102,101) exten => 85XXXXXX,3,Hangup
It should now query www.kvasir.no/telefonkatalogen and set the callerid-name (which will show up on your phone) if it finds something. Since I’m pretty sure that kvasir won’t like this (I take no responsibility for your usage), I would recommend implementing a cache if you have a lot of traffic. You can also easily adapt it to other phone directories by changing the search URL and regexp.
Cell SDK on Ubuntu (Feisty Fawn).
Posted by Stian | Filed under Linux, Teknologi
I ended up installing ubuntu on my playstation 3, pretty straight forward installation. Getting the Cell SDK up and running on ubuntu turned out to be a bit of a challenge however. There’s really not much information out there about how to do it, the closest I got was Gammel’s “Installing Cell SDK under Ubuntu” - which almost worked. Most of the following is based on his recipe.
1. Install a few needed packages:
$ apt-get install rpm freeglut3 freeglut3-dev libxmu-dev libxext-dev \ build-essential perl rsync flex byacc tk8.4 tcl8.4 libelf1 gawk bash \ libnetpbm10 libnuma1
2. Make sure sh points to bash:
$ ls -la /bin/sh lrwxrwxrwx 1 root root 9 2007-08-25 07:33 /bin/sh -> /bin/bash
if it doesn’t then replace it:
$ rm /bin/sh && ln -s /bin/bash /bin/sh
3. Replace mawk with gawk:
$ update-alternatives --set awk /usr/bin/gawk
4. Add symlinks to a couple of libs:
$ ln -s /usr/lib/libtcl8.4.so.0 /usr/lib/libtcl8.4.so $ ln -s /usr/lib/libtk8.4.so.0 /usr/lib/libtk8.4.so
5. Download the Cell SDK (v2.1 is current version). Mount it and copy out the software.
$ mkdir /media/cell && mount -o loop CellSDK21.iso /media/cell $ cp -r /media/cell/software /tmp/
6. Fix the install script, i needed to add –ignorearch since it complained about the system not beeing ppc64 for some reason. Then run it..
$ cd /tmp/software $ sed -i 's/rpm -i/rpm -i --nodeps --ignorearch/g' cellsdk $ ./cellsdk install
7. Mount up the SPU-filesystem (if you get errors like “Unable to create SPE thread: Invalid argument” or “spu_create(): No such file or directory” while running your code this is probably why).
$ mkdir /spu $ echo "none /spu spufs defaults 0 0" >> /etc/fstab $ mount -a




















