Archive for the ‘linux’ Category

mt-daapd

Saturday, January 9th, 2010

Mt-daapd is an ‘iTunes’ server that you can run on a linux system holding your music collection.
When fiddling around with configuration, I came accros the following error message in the syslog:

Error loading plugin /usr/lib/mt-daapd/plugins/ssc-script.so: plugin declined to load

I was trying to setup a custom transcoding script. That required to load the ’ssc-script.so’ plugin first.
When increasing the log level, it gave a more descriptive hint to what is going on:

No codectypes specified for script transcoder.
Error loading plugin /usr/lib/mt-daapd/plugins/ssc-script.so: plugin declined to load

After uncommenting the following line in /etc/mt-daapd.conf:

ssc_codectypes = ogg,flac,alac

…it showed no error messages anymore:

Loaded plugin /usr/lib/mt-daapd/plugins/ssc-script.so (ssc-script/svn-1696)

cakephp, user_dir and mod_rewrite

Thursday, April 2nd, 2009

Here’s a little note on getting a cakephp app working in your public_html directory. In order to get the mod_rewrite configuration working, add a RewriteBase rule to the .htaccess files in the cakephp source. If your app is located in /home/me/public_html/cakesite/ and the URL to the site is http://host/~me/cakesite you’ll need to change the following .htaccess files:

/home/me/public_html/cakesite/.htaccess
/home/me/public_html/cakesite/app/webroot/.htaccess

Add the following line to these files, just below the line stating “RewriteEnginge On”:

RewriteBase /~me/cakesite/

For example, the first .htaccess file will look like:

<ifModule mod_rewrite.c>
	RewriteEngine on
	RewriteBase /~me/cakesite/
	RewriteRule    ^$ app/webroot/    [L]
	RewriteRule    (.*) app/webroot/$1 [L]
</ifModule>

Bonus notes with instructions for Debian/Ubuntu systems
You should have mod_rewrite enabled:

$ sudo a2enmod rewrite
$ sudo /etc/init.d/apache2 force-reload

To make sure the use of .htaccess files is actually allowed. In the Directory section of your apache configuration, there should be a line like:

AllowOverride FileInfo

Also, be sure to force-reload Apache after making this change.

Two ways of generating white noise

Wednesday, January 14th, 2009

Goal: generate a white noise .wav fille of 1.5 hours
In matlab:


% create a matrix with random values:
>> noise = 2 * rand(90 * 60 * 44100, 2, 'double') - 1;

% write the wav file with a sample frequency o 44.1kHz
>> wavwrite(noise, 44100, 16, 'noise.wav');

This process takes a while and it consumes quite some of your system RAM.

More efficient, in bash:

$ dd if=/dev/urandom count=5400 bs=176400 | sox -s -c 2 -r 44100 -t raw -w - noise.wav

This took only 2 minutes!

vmcp

Monday, December 10th, 2007

Vmcp (vm-copy) is a simple script that allows you to copy/clone a VMware virtual computer image. Just specify the source directory and the destination directory. It will first just copy the wmware directory recursively en then change the configuration option ‘displayName’ in the vmx file.

#!/bin/sh

source=$1
dest=$2

echo copying virtual machine
cp -rv $source $dest

vmxsourcefile=`ls $source/*.vmx`
vmxdestfile=`ls $dest/*.vmx`

grep -v displayName $vmxsourcefile > $vmxdestfile
echo displayName = \"$dest\" >> $vmxdestfile

exit 0

Reminder: Local documentation!

Friday, September 21st, 2007

I’ve been searching for some ‘getopt’ examples on the internet. Many tutorials show the same basic tricks. I completely looked over the local documentation, which in fact has very nice examles for bash and tcsh:

#!/bin/bash

# A small example program for using the new getopt(1) program.
# This program will only work with bash(1)
# An similar program using the tcsh(1) script language can be found
# as parse.tcsh

# Example input and output (from the bash prompt):
# ./parse.bash -a par1 'another arg' --c-long 'wow!*\?' -cmore -b " very long "
# Option a
# Option c, no argument
# Option c, argument `more'
# Option b, argument ` very long '
# Remaining arguments:
# --> `par1'
# --> `another arg'
# --> `wow!*\?'

# Note that we use `"$@"' to let each command-line parameter expand to a
# separate word. The quotes around `$@' are essential!
# We need TEMP as the `eval set --' would nuke the return value of getopt.
TEMP=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \
     -n 'example.bash' -- "$@"`

if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi

# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"

while true ; do
        case "$1" in
                -a|--a-long) echo "Option a" ; shift ;;
                -b|--b-long) echo "Option b, argument \`$2'" ; shift 2 ;;
                -c|--c-long)
                        # c has an optional argument. As we are in quoted mode,
                        # an empty parameter will be generated if its optional
                        # argument is not found.
                        case "$2" in
                                "") echo "Option c, no argument"; shift 2 ;;
                                *)  echo "Option c, argument \`$2'" ; shift 2 ;;
                        esac ;;
                --) shift ; break ;;
                *) echo "Internal error!" ; exit 1 ;;
        esac
done
echo "Remaining arguments:"
for arg do echo '--> '"\`$arg'" ; done

MySQL re-installation

Saturday, August 4th, 2007

De-installation is sometimes not so easy with APT. For example when you screwed up your mysql installation or lost mysql passwords you may want to reinstall mysql and start from scratch again. You probably installed mysql server using:

$ sudo apt-get install mysql-server

Then you might think that you need this command for removal:

$ sudo apt-get remove mysql-server

However, this is not the case. The mysql-server package is a sort of meta-package that makes sure that the latest (and greatest) available mysql server version will be installed. Currently, this means that you actually installed mysql-server version 5.0. Above command will only remove the meta-package, while mysql server 5 happily continues running on your system. To de-install the mysql-server, remove the package, the meta package pulled in:

$ sudo apt-get remove mysql-server-5.0

To also remove the configuration and the binary data, use instead:

$ sudo apt-get remove --purge mysql-server-5.0
# and for ubuntu Gutsy:
$ sudo apt-get purge mysql-server-5.0

Now that mysql server is ‘really’ gone, you can start over and install the mysql-server package:

$ sudo apt-get install mysql-server

‘Compact’ bash prompt

Monday, July 30th, 2007

Especially when working with cakephp, the following line in your .bash_profile script might come in handy:

HOSTCOLOR="31m"
PS1="\u@\[\e[${HOSTCOLOR}\]\h\[\e[0m\]:\w\n\[\e[33m\]\!\[\e[0m\] \$ "

It will print out the current working directory on the first line and the actual bash prompt on the second line. Making it less likely that your command will wrap lines after the first few typed characters.
It changes the command prompt from:

command line long

….into:

command line 'short'

The login prompt now shows the following info:

  • username
  • hostname in red (in my bash script, it will print red for one group of servers and blue for other servers)
  • current working directory
  • command history number, ie: use !520 to execute the previous command

Extracting layers from a XCF (gimp) file

Saturday, July 21st, 2007

This is a script that extracts the layers of a XCF file to individual PNG files. It uses xcftools (debian/ubuntu package):

#!/bin/bash

xcffile=$1

layers=`xcfinfo $xcffile  | awk '{ print $NF }'`

destdir=`dirname $xcffile`/layers
mkdir $destdir

for layer in $layers
do
        echo saving $layer to $destdir/$layer.png
        xcf2png -o $destdir/$layer.png $xcffile $layer
done

exit 0

Wireless setup

Tuesday, December 26th, 2006

For some reason, I couldn’t get my wireless card (Linksys WMP54G pci) working under Ubuntu 6.10. Another attempt today. First without encryption: Hey! it works!. Then WEP ‘encryption’: no luck. WPA: on my access point (asus wl530g) it’s called WPA-PSK with TKIP encryption. OS X calls it “WPA personal”. Under Linux, adapting the /etc/networking/interfaces file was sufficient:

$ cat /etc/network/interfaces
auto lo
iface lo inet loopback

iface ra0 inet dhcp
pre-up iwconfig ra0 essid default
pre-up iwconfig ra0 mode managed
pre-up iwconfig ra0 channel 1
pre-up iwpriv ra0 set AuthMode=WPAPSK
pre-up iwpriv ra0 set EncrypType=TKIP
pre-up iwpriv ra0 set WPAPSK="mysecretpassphrase"

auto ra0

So, no additional drivers / modules, just choosing the right encryption was the trick to get this card working. This was one of the posts that where very helpful.

Batch conversion of images

Friday, December 15th, 2006

For batch image conversion, file renaming, etc, I usually use these kind of one-liners:

$ for i in `ls *.bmp` ; do echo convert $i ${i%.*}.png ;done
convert screendump_01.bmp screendump_01.png
convert screendump_02.bmp screendump_02.png
convert screendump_03.bmp screendump_03.png

When you’re satisfied with the result, have it executed by the shell:

$ for i in `ls *.bmp` ; do echo convert $i ${i%.*}.png ;done | sh