Archive for category fun with Linux

Installing Litmus

Litmus is cool. It is a testing framework for users. It manages the test cases and test results. But it is no automatic testing.

Resources:

However, it was somehow mainly built for mozilla by mozilla, so the only really supported working version is litmus.mozilla.org. You can download and install it, but its not that easy.

I needed to install the following perl packages, most are also listed in INSTALL (I had a centos4):
yum install perl-Getopt-Long perl-Encode perl-Data-Page perl-Params-Util perl-Clone perl-version perl-Time-Piece perl-UNIVERSAL-moniker perl-XML-Parser perl-Class-Trigger perl-Class-DBI perl-HTML-Strip perl-JSON-XS perl-Test-Harness perl-Class-DBI-Pager perl-Date-Manip perl-Class-DBI-mysql perl-Data-Dumper perl-Data-JavaScript-Anon perl-JSON perl-Time-Piece-MySQL perl-XML-XPath perl-Time-HiRes perl-Class-DBI-Plugin-RetrieveAll perl-DBD-mysql perl-DBD-MySQL perl-DBIx-ContextualFetch perl-Class-Data-Inheritable perl-Class-Accessor perl-Ima-DBI perl-Digest-SHA1 perl-Apache-DBI perl-Class-Accessor-Chained perl-Sys-Hostname-Long perl-HTML-Template perl-Text-Template perl-Text-Template-Simple perl-Apache-DBILogin perl-Email-MIME-Encodings perl-Email-Simple perl-Email-MIME-ContentType perl-Email-MIME perl-Email-Address perl-Email-MessageID perl-Module-Pluggable perl-Return-Value perl-Email-MIME-Modifier perl-Email-Send perl-Params-Validate perl-List-MoreUtils perl-DateTime-Locale perl-Class-Singleton perl-Email-Date-Format perl-DateTime perl-DateTime-Format-HTTP perl-DateTime-Format-Mail perl-DateTime-TimeZone perl-PatchReader

Maybe you need not all of those, and some are dependencies of the others, but then on the other hand, having them makes it work…

I installed those from source (CPAN) for more updated versions:
Class-DBI Data-JavaScript HTML-Parser HTML-StripScripts HTML-StripScripts-Parser JSON JSON-XS Template-Toolkit Text-Markdown

Do it like this:
/usr/bin/perl -MCPAN -e ‘install “JSON::XS”‘
CPAN is useful: http://search.cpan.org/~makamaka/JSON-2.12/lib/JSON.pm

Litmus code itself:

In populatedb.sql, you have to say edit the line USE `litmus`; if you want a different database name.

You have to edit localconfig: Important: Set $bugzilla_auth_enabled = 0;
Bugzilla-auth probably never worked.

You need to setup your Webserver to work with Perl, see some other documentation (resources above). Do what INSTALL says. The tests are outdated, 56 fail here, don’t cry.

At the end I ran into the problem that (using litespeed/lsws as a webserver) the login cookie is not set, and you are logged out all the time. Workaround: write a php script that accepts the login and sets the cookie. Suboptimal, but WFM.

EDIT: As a good open source community member, I just wrote some bug reports. With patches. Woohoo!

No Comments

Maven: OutOfMemory in surefire tests

Or how to pass Xmx712M or Xmx1024m parameter to maven2 test runs:
In your pom, add the argLine parameter.

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.3</version>
<configuration>
<argLine>-Xmx712M</argLine>
</configuration>
</plugin>

No Comments

NoScript

NoScript opens its own page on every update, which I find very annoying. You can turn that off by the noscript.firstRunRedirection config option (go to about:config).

No Comments

Join/Merge PDF files together

Just found this wonderful command here for ghostscript to produce one pdf out of many:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf

3 Comments

Backup compression

I compressed a backup with various tools:

1606M original tarfile
1226M bzip2 –best
1.3G gzip –best (sorry, no exact MB)
1152M lzma -7 (default)
1131M lzma -8

LZMA (7-zip) is definitly a algorithm heavy on cpu and memory, but achieved great compression.
This shouldn’t be a benchmark (as I didn’t measure time), only a perception in this specific use case.

No Comments

SVN up

If you do a svn up, you want to know what happened in between, right?

Log entries, Files changed. You can either go step by step through the revisions or let this bash script do the svn up for you:

#!/bin/bash
oldrev=$(svn info |grep '^Revision: '|sed 's/Revision: //g')
svn up
newrev=$(svn info |grep '^Revision: '|sed 's/Revision: //g')
[ "$oldrev" == "$newrev" ] || {
echo "Made the step from $oldrev to $newrev; Log: "
for i in $(seq $oldrev $newrev); do
svn log -r $i
echo Files:
svn diff --diff-cmd diff -x -q -c $i | grep '^Index:' | sed 's/^Index://g'
echo
done
}

2 Comments

run Firefox as another user

Firefox is a big application and thus has security-related issues. NoScript can help a little, but not all bugs are necessarily script related.

Here I let firefox run as another user “kiosk”:
I access the normal user’s Xauthority file to be able to write to the X server. Note that firefox will not be able to write to your users home directory (which is the whole point), but to kiosk’s home, from which you can grab the files.

File /home/user/bin/firefox.sh

#!/bin/bash
cp -f /home/user/.Xauthority /home/kiosk/
chown kiosk:kiosk /home/kiosk/.Xauthority # you can also do this with xhost.
su -c "XAUTHORITY=/home/kiosk/.Xauthority DISPLAY=:0.0 /opt/firefox/firefox" kiosk

Then, as user, call

sudo bash bin/firefox.sh

And firefox should pop up.

There is also a howto for creating a chroot (for various distros).
However, su didn’t compile, so I didn’t use it. Jailkit might also be something to look into.

No Comments

HOWTO: Samba share with virus scanning

This explains how to install a windows share that is scanned when files are uploaded or changed there.

We use:

  • clamav
  • inotify-tools

Install those.

I presume you have setup already:

  • /etc/clamd.conf
  • freshclam works.
  • The samba share already exists and works.

What the script does is:

  1. find all files in the share $SHARE
  2. listen on changes using inotify
  3. output from those two is given clam(d)scan, which analyses the $FILE
  4. If the $FILE contains a virus, it is moved to $VIRUSDIR, and $FILE.txt is created containing a report

What to do? How to install?

  1. Save the script below to something in your $PATH, like /usr/local/bin/scanshares
  2. (Set the variables according to your setup)
  3. Make sure $SHARE and $VIRUSDIR is owned by the user “nobody”
  4. Call it using
    sudo -u nobody scanshares >/var/log/scanshares
  5. Watch /var/log/scanshares while you put a test virus file from EICAR into your share. After some seconds, it should be replaced by a text file.

#!/bin/bash
# if you manage to create a file containing a virus,
# which filename signatures a virus, you will send this script
# in a infinite loop ;-)
TMPFILE=/tmp/lastscanresult.txt
SHARE=/srv/samba/
VIRUSDIR=/srv/samba/hasvirus/
VIRUSDB=/var/clamav/
#INOTIFYWAIT=/home/johannes/inotify-tools-3.13/src/inotifywait
INOTIFYWAIT=inotifywait
# if you have no clamd
CLAMSCAN="clamscan --database $VIRUSDB --block-encrypted -i"
# if you have clamd (faster)
CLAMSCAN="clamdscan"
{
# initial check
find $SHARE -type f | while read line; do echo "$line|CLOSE_WRITE"; done;
# await changes
# we need to listen to create, otherwise inotifywait doesn't follow in subdirs :-(
$INOTIFYWAIT -q -m -r -e create -e close_write "$SHARE" --format '%w%f|%e';
} |
grep '|CLOSE_WRITE' --line-buffered | sed -u 's/|.*//g' | # remove create events again
grep -v --line-buffered  $VIRUSDIR | # we know THOSE have virus
while read file; do
echo "scanning $file"
$CLAMSCAN --no-summary "$file" > $TMPFILE
if [ "$?" == "1" ]; then
mv "$file" $VIRUSDIR
{
echo 'The file contained a virus and was therefore removed.'
cat $TMPFILE
} > "$file.txt"
fi
echo "scanning $file done."
done

This manual is also available on gentoo-wiki.

No Comments

Linux: Hostname change break X apps

There exists a really lame problem on X (X11,XFree86,Xorg,…): The authentification or identification mechanism when a new application wants to connect to the X server (read: show a window) works over the hostname.

This is fine if you live in 1990, but wireless network have dhcp and dhcp server can send a hostname to your machine making your X session stop working: You can’t start any programs anymore.

NetworkManager (what also make the little icon on GNOME/KDE desktops, pre-installed on Ubuntus et.al., developed by RedHat) uses dhclient to retrieve a hostname.

The magic words to add to your dhclient.conf are:

send host-name "hoot";
supersede host-name "hoot";

If you use pump (instead of dhclient), you shouldn’t have this problem, as it doesn’t set the hostname (see the man page).

A mailing list entry on this topic starts here: http://lists.freedesktop.org/archives/xorg/2004-August/002772.html

No Comments

Current calendar week on Desktop

This should say all:

Calendar-Desktop
Your next week calendar as Desktop background.

This is a hack. The script opens Sunbird (which you configured before), takes a screen shot of the window, closes Sunbird, cuts away the borders of the image and sets it as GNOME desktop background.

You will have to edit the pixels to cut off (depending on your theme).

#!/bin/bash
#TEXT="2 Friday"
TEXT="Friday" # next friday, so on saturday we see the next week
TOP=176   # in px
LEFT=112
BOTTOM=26
RIGHT=18
BACKGROUND='#76848F'
DATE=$(date --date="$TEXT" "+%m/%d/%Y")
WEEK=$(date --date="$TEXT" "+%-V")
FILENAME="$HOME/current-calendar.png"
TITLE="Week $WEEK - Sunbird"
killall sunbird-bin 2>/dev/null
sunbird -showdate "$DATE" 2>&1 &
# mozilla is slooow...
sleep 20
#import -crop "+$TOP+$LEFT" -window "$TITLE" $FILENAME
#import -crop "+$TOP+$LEFT" -rotate 10 -window "$TITLE" $FILENAME
#import -crop "+$TOP+$LEFT" -rotate 10 -monochrome -window "$TITLE" $FILENAME
import -crop "+$TOP+$LEFT" -window "$TITLE" - |
convert - -gravity NorthWest -crop "-$RIGHT-$BOTTOM" -colorspace Gray - |
convert - -colorspace RGB -background "$BACKGROUND" -rotate -10 $FILENAME
killall sunbird-bin
which gconftool   2>/dev/null >/dev/null && GCT=gconftool
which gconftool-2 2>/dev/null >/dev/null && GCT=gconftool-2
$GCT --type=string --set /desktop/gnome/background/picture_filename "$FILENAME"
wait 

Also see MDC Command Line Options

No Comments