This is a short script i use to switch between my VDR-frontend (softhddevice) and XBMC.

Sure there is a lot of space for improvement.

#!/bin/bash
DEFAULT=run_softhd
LOCKFILE="/var/lock/switchtv.lock"
 
if [ -f $LOCKFILE ];then
   logger "switchtv: running or stale lockfile $LOCKFILE..."
   exit 1
fi
 
 
 
 
lock() {
    touch $LOCKFILE
}
unlock() {
    rm $LOCKFILE
}
 
run_frontend() {
    $DEFAULT
}
 
run_softhd() {
    svdrpsend.pl PLUG softhddevice ATTA
    wmctrl -r softhddevice -b toggle,fullscreen
    wmctrl -r softhddevice -e 0,0,0,1920,1080
    wmctrl -r softhddevice -b toggle,fullscreen
}
 
run_xbmc() {
    if [ -f /usr/bin/xbmc ];then
        su - -c '/usr/bin/xbmc -fs -l /var/run/lirc/lircd $@ &'
    fi
}
 
kill_apps() {
        svdrpsend.pl PLUG softhddevice DETA
        killall -w  xbmc
        killall -w  xbmc.bin
        killall /usr/bin/dbus-daemon
}
 
lock
 
if [ "$1" = "xbmc" ];then
     kill_apps
     /usr/bin/amixer sset Master 100%
     /usr/bin/amixer sset PCM 100%
     export DISPLAY=":0.0"
     run_xbmc
     sleep 2
     unlock
elif [ "$1" = "vdr" ];then
     logger "switchtv: switching to VDR..."
     kill_apps
     /usr/bin/amixer sset Master 80%
     /usr/bin/amixer sset PCM 80%
     export DISPLAY=":0.0"
     run_frontend
     sleep 2
     unlock
     logger "switchtv: switching to VDR...done"
elif [ "$1" = "kill" ];then
     logger "switchtv: killing all frontends..."
     kill_apps
     sleep 2
     unlock
     logger "switchtv: killing all frontends...done"
elif [ -z "$1" ];then
     kill_apps
     export DISPLAY=":0.0"
     run_frontend
     sleep 2
     unlock
fi
 
exit 0

This is the first timelapse i did using my new GoPro Hero2.
It’s set up of about 2000 photos taken in ~2:30h.

Happy Birthday, Franz!

Download HQ (~180MB)

Assembly Process (slight commenting)

Tools used:

  • ffmpeg
  • mencoder
  • kdenlive
  • MP4Box (Archlinux package: gpac)
Sorting input images

ffmpeg expects the input images to have incremental  numbers without offset. so one can get them in this format with whatever tool of choice. gqview e.g. allows series renaming and would do that job fine. or just use the cmdline(shell + perl) like i did:

cd ~/inputfiles; mkdir order;find . -maxdepth 1 -iname "*.jpg"; | sort | perl -MFile::Copy -ne 'BEGIN{$i = 0};chomp;copy($_, "order/".sprintf("img_%04d.jpg", $i)); $i++'

~inputfiles/order/ now holds images as ffmpeg expects them.

Creating the timelapse
ffmpeg -i /inputfiles/order/img_%04d.jpg -r 25 -s 1280x960 -vcodec libx264 -b:v 30000k Flapse_25fps.mp4

now, this creates a timelapse video of 25 frames per second. this might fit well in a lot of situations. but in my case the timelapse seemed to be a bit to fast rushing by.

Using mencoder to slow it down
mencoder -speed 0.5 -ofps 25 -ovc copy Flapse_25fps.mp4 -o slow.mp4

play with the -speed value a bit.

once i was satisfied with the result i pushed slow.mp4 into a kdenlive project, added some music, fade in/out effects and rendered to mp4.
note to myself: investigate further on how this step be done with ffmpeg/(cmdl)

Converting for online playback

For my embedded wordpress player i wanted to resize the video, lower the bitrate and create streaming compatible metadata:

MP4
ffmpeg -i slow_and_audio.mp4 -strict experimental -vcodec libx264 -acodec aac -b:v 1500k -b:a 128k -s 640x480 slow_and_audio_resized.mp4
MP4Box -inter 500 slow_and_audio_resized.mp4 -out final.mp4
WEBM
ffmpeg -i slow_and_audio.mp4 -acodec libvorbis -b:v 1000k -b:a 128k slow_and_audio_resized.webm
OGV
ffmpeg -i slow_and_audio.mp4 -acodec libvorbis -b:v 1000k -b:a 128k  slow_and_audio_resized.ogv

i finally sold my asus eee pad transformer after ~8 months of “usage”.

after two months of playing around with roms, tweaking, tuning, tooling etc and another 4 months of carrying it around thinking i will use it on my daily routine for sure somewhen, it just took me about another 2 months to admit to myself that i am not the typical tablet user and i will not find the 650€ purpose i’d been looking for.

roughly speaking: it is a nice looking device. they for sure hit a big target audience. but for smbd using terminals most of the time and hardly watching videos abroad it’s not the first device of choice. one might call me stupid, ever thinking that a tablet would fit that needs. okay, can we arrange to call it “naive”?

out with the new – in with the old

before asus jumped on the shiny new tablet train they also manufactured some netbooks. i checked back on asus websites and stores and found that they still do netbooks. i spotted the Asus EEE PC x101 equipped with a weak single core ATOM CPU, 1G of RAM, 32GB SSD, only ~920g weight and a fantastic slim look for the price of ~250€.

so, i read some reviews. they reach from “a god-made device” to “good enough for kids but you can’t do any serious work”.

however, this device sounded like it would be the kind of thing i could use. its lightweight enough to carry it around in a shoulder bag all day, install ArchLinux on ui, fire up mutt, irssi, etc quickly. and finally i do have a device holding my whole toolbox.

summing-up i’d say this device is not a toy for kids – sure, it could be one – but for ppl who have a working flow like resume from suspend --> ssh <somehost> --> screen -r 'my_screensession' --> read mail/newsgroups; IRC; work; etc etc;
it is the perfect daily companion. well, at least for me it is.

image

imageimage
image

  1. Get youtube-dl
    1. Source: see http://rg3.github.com/youtube-dl/
    2. Debian: see Debians pkg search
    3. ArchLinux: pacman -S youtube-dl #community
  2. Run:
  3.  youtube-dl --extract-audio --audio-format mp3  -o 'RRR_%(stitle)s.%(ext)s' 'youtubeurl1' 'youtubeurl2'

    this will extract the audio from the downloaded video convert it to mp3 (ffmpeg with mp3 encode support needed) and name the outputfile RRR_title.mp3.

A commonly asked question by sysadmins is how to list all perl modules – installed and known to perl – on a system.

This is how i do it:

perl -MFile::Find=find -MFile::Spec::Functions -Tlwe 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC;'

* I took this somewhere from perlmonks a long time ago.

This is how i converted old config style ldap schemata to openldap’s 2.4.x cn=config style.

Create an output directory:

$ mkdir /tmp/ldif_output

create a file to include all the schemas needed (and dependencies)

$ vim /tmp/schema_convert.cfg
include /etc/ldap/schema/corba.schema
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/duaconf.schema
include /etc/ldap/schema/dyngroup.schema
include /etc/ldap/schema/inetorgperson.schema
include /etc/ldap/schema/java.schema
include /etc/ldap/schema/misc.schema
include /etc/ldap/schema/nis.schema
include /etc/ldap/schema/openldap.schema
include /etc/ldap/schema/pmi.schema
include /etc/ldap/schema/ppolicy.schema
include	/tmp/ldapns.schema

run the conversation:

$ slaptest -f schema_convert.cfg -F /tmp/ldif_output
you might see error messages like this one:
/tmp/ldapns.schema: line 22 objectclass: AttributeType not found: "host"

in this case, make sure to include all schemata that your new one depends on. this is because your new schema uses an attribute type you did not define upfront. you could either define it yourself in your .schema file. but i recommmend to rather have a look at /etc/ldap/schema/*.schema and find which schema defines that attribute.

if the slaptest command finished successfully you should find a directory structure like this in /tmp/ldif_output:

$ ls -lR /tmp/ldif_output/
/tmp/ldif_output/:
total 8
drwxr-x--- 3 root root 4096 Nov 30 10:37 cn=config
-rw------- 1 root root  875 Nov 30 10:37 cn=config.ldif
 
/tmp/ldif_output/cn=config:
total 48
drwxr-x--- 2 root root  4096 Nov 30 10:39 cn=schema
-rw------- 1 root root 33583 Nov 30 10:37 cn=schema.ldif
-rw------- 1 root root   513 Nov 30 10:37 olcDatabase={0}config.ldif
-rw------- 1 root root   525 Nov 30 10:37 olcDatabase={-1}frontend.ldif
 
/tmp/ldif_output/cn=config/cn=schema:
total 84
-rw------- 1 root root  1212 Nov 30 10:37 cn={0}corba.ldif
-rw------- 1 root root  6375 Nov 30 10:37 cn={10}pmi.ldif
-rw------- 1 root root  3236 Nov 30 10:37 cn={11}ppolicy.ldif
-rw------- 1 root root   850 Nov 30 10:37 cn={12}ldapns.ldif
-rw------- 1 root root 15428 Nov 30 10:37 cn={1}core.ldif
-rw------- 1 root root 11290 Nov 30 10:37 cn={2}cosine.ldif
-rw------- 1 root root  4414 Nov 30 10:37 cn={3}duaconf.ldif
-rw------- 1 root root  1622 Nov 30 10:37 cn={4}dyngroup.ldif
-rw------- 1 root root  2784 Nov 30 10:37 cn={5}inetorgperson.ldif
-rw------- 1 root root  2518 Nov 30 10:37 cn={6}java.ldif
-rw------- 1 root root  1448 Nov 30 10:37 cn={7}misc.ldif
-rw------- 1 root root  6420 Nov 30 10:37 cn={8}nis.ldif
-rw------- 1 root root  1252 Nov 30 10:37 cn={9}openldap.ldif

now feel free to edit the newly create ldif file you are after.

once done you can just use ldapadd to add the new schema:
for example like this

ldapadd -x -D cn=admin,cn=config -f /tmp/ldif_output/cn\=config/cn\=schema/cn\=\{12\}ldapns.ldif

Thats it.

A quick shell script to in/decrease (and mute) my pulseaudio device.

#!/bin/bash
 
SINK_NAME="alsa_output.pci-0000_00_1b.0.analog-stereo"
VOL_STEP="0x01000"
 
VOL_NOW=`pacmd dump | grep -P "^set-sink-volume $SINK_NAME\s+" | perl -p -i -e 's/.+\s(.x.+)$/$1/'`
 
case "$1" in
	plus)
	VOL_NEW=$((VOL_NOW + VOL_STEP))
	if [ $VOL_NEW -gt $((0x10000)) ]
	then
		VOL_NEW=$((0x10000))
	fi
	pactl set-sink-volume $SINK_NAME `printf "0x%X" $VOL_NEW`
 
	;;
	minus)
	VOL_NEW=$((VOL_NOW - VOL_STEP))
	if [ $(($VOL_NEW)) -lt $((0x00000)) ]
	then
		VOL_NEW=$((0x00000))
	fi
	pactl set-sink-volume $SINK_NAME `printf "0x%X" $VOL_NEW`
	;;
	mute)
 
	MUTE_STATE=`pacmd dump | grep -P "^set-sink-mute $SINK_NAME\s+" | perl -p -i -e 's/.+\s(yes|no)$/$1/'`
	if [ $MUTE_STATE = no ]
	then
	        pactl set-sink-mute $SINK_NAME 1
	elif [ $MUTE_STATE = yes ]
	then
		pactl set-sink-mute $SINK_NAME 0
	fi
esac

Usage:

copy and paste it to pa-vol.sh
chmod it executeable.
change the SINK_NAME to your device name.

#increase volume by $VOL_STEP

./pa-vol.sh plus

#decrease volume by $VOL_STEP

./pa-vol.sh minus

#mute

./pa-vol.sh mute

I had to reset the password of an account on a system running windows 7. There is a wonderfull linux live CD to do the job really easy.
Go to http://www.sysresccd.org/Download and download the according ISO image. Burn it and boot your windows machine.

After sysresccd has booted mount your windows partition:

ntfs-3g /dev/sda1 /mnt/windows

Change directory:

cd /mnt/windows/Windows/System32/config

In there you should find a file named SAM.
List users by running:

chntpw -l SAM

Clear password:

chntpw -u  SAM

Chose 1 to clear the users password.
Write this changes to disk by pressing Y.

Taddaaa. Reboot. Easy as can be.

I presume that you do have some basic linux know-how. e.g. how to find partition types. If you do have problems doing this leave a comment.

With Debian Squeeze came version 1.2.0.5-2 of phpldapadmin. Since that release (or maybe an earlier 1.2*) it wants you to “Select a template to edit the entry”. Which _is_ annoying. I’d not been able to find much on a quick google query so i went with a – i guess – rather dirty solution.

for file in /etc/phpldapadmin/templates/modification/*.xml; do mv $file $file.unused; done

Now phpldapadmin is using the ‘default’ template for every edit. Easy as it was before version 1.2.

Update 1:

According to the comment from dizzy and the link provided you can just set:
$config->custom->appearance['custom_templates_only'] = true; in your config.php
This will disable all the default templates. But be aware that this will disable the templates for editing entries and those for ‘createing new entries’. (Thanks to dizzy)

Introduction

First of all it should be said that encrypting the /home partition only is not recommended. This does not nearly give you the same security as e.g. encrypting all your partitions. I missed doing this task on my laptop during installation and i am too lazy to copy all my data + OS to some external location, encrypt all partations and move them back. This is why i decided to encrypt my /home partition only.

The following procedure had been done on Arch Linux using dm-crypt and LUKS.

Procedure

Before we start we need to backup our whole data to some destination outside the partition in question.

cd /home; find . -xdev | cpio -pvm /outside/destination/

The /home filesystem we are going to encrypt resides on /dev/sda3. Before the actual encryption we should overwrite our data with random bit patterns a few times. Therefore i used a little handy tool named shred. Sure, you can dd if=/dev/urandom of=/dev/yourpartition a couple of times as well.

shred -v /dev/sda3

Now we can start with the encryption of my partition.

cryptsetup luksFormat /dev/sda3 --cipher aes-cbc-essiv:sha256 --verify-passphrase --key-size 256

We decided to go with the default cipher but specified it on the cmdline for documentation purposes. --verify-passphrase just instructs cryptsetup to ask the password twice. A key size of 256bit(--key-size 256) is also the default. A smaller value might increase performace but take care to use a multiple of 8bits.

Opening the device…from the users perspective means asking the passphrase and creating a device-mapper pseudo device we can use for example to create a filesystem or VGs/LVs on top, etc etc.

[root@chill ~]# cryptsetup luksOpen /dev/sda3 sda3_crypt
Enter passphrase for /dev/sda3:
[root@chill ~]# ls -l /dev/mapper/sda3_crypt
lrwxrwxrwx 1 root root 7 Mar 23 11:55 /dev/mapper/sda3_crypt -&gt; ../dm-0
[root@chill ~]#

We could now simply create a filesystem of our choice on /dev/mapper/sda3_crypt.
But we want our home-filesystem to reside on a Logical Volume.

[root@chill ~]# pvcreate /dev/mapper/sda3_crypt
Physical volume "/dev/mapper/sda3_crypt" successfully created
[root@chill ~]# vgcreate local0 /dev/mapper/sda3_crypt
Volume group "local0" successfully created
[root@chill ~]# vgs
VG     #PV #LV #SN Attr   VSize   VFree
local0   1   0   0 wz--n- 437.81g 437.81g
[root@chill ~]# lvcreate -n home0 -L 300G local0
Logical volume "home0" created
[root@chill ~]# lvs
LV    VG     Attr   LSize   Origin Snap%  Move Log Copy%  Convert
home0 local0 -wi-a- 300.00g
[root@chill ~]# mkfs.ext4 /dev/local0/home0
[root@chill ~]# mount /dev/local0/home0 /home/


Thats mainly it with the basics. We can now just add /dev/local0/home0 to our fstab and the OS will ask us for the passphrase at boot time.

Using a keyfile

I totally hate the fact to type my ‘superstrongpassword’ every time my machine boots up. So i decided to create a keyfile and add it to my sda3_crypt slot:

dd if=/dev/urandom of=/tmp/my_home.key bs=1k count=2

Add the key to a free slot on sda3:

cryptsetup luksAddKey /dev/sda3 /tmp/my_home.key

Testing opening the device with our key:

cryptsetup luksOpen /dev/sda3 sda3_crypt --key-file /tmp/my_home.key

Important: /tmp/my_home.key must not stay on any of your unencrypted partitions or do you stick the key to your house to the front door?!

Storing the keyfile on a usb-stick

We want to store our keyfile on an usb stick so that we can just plug it in, boot, open and mount our home partition.

Preperation

Create a persistent name for the usbstick using udev:

lsusb -v | grep -A 5 Vendor

Note your USB-sticks serial number and replace it with _serial_ in the next command.

echo 'KERNEL=="sd*", ATTRS{serial}=="_serial_", SYMLINK+="usblock%n"' > /etc/udev/rules.d/8-usbstick.rules

Test.

udevadm trigger
ls -l /dev/usblock* 

In the next step we store our key in between the MBR and the first partition on our usb-stick. Make sure you backup the data on the stick upfront because this might destroy it.

Check, to see if the first 64sectors are free:

dd if=/dev/usblock of=64sectors bs=512 count=64
xxd 64sectors | less

Free? Good. Write the key to our stick.
Attention: A potentially existing bootloader on the USB-stick will be overwritten.

dd if=my_home.key of=/dev/usblock bs=512 seek=4

Add the keylocation to crypttab:

echo "sda3_crypt /dev/sda3 /dev/usblock:2048:2048" >> /etc/crypttab 

Since this is not the root-partition we do not need dm_crypt in our initrd. But we need usb support in the initrd. Otherwise it might happen that the usb-device is not recognized by the system the moment udev is initialized. Therefore we need to create a new initrd.
On ArchLinux simply add usb to the HOOKS in /etc/mkinitcpio.conf and create a mew image.

mkinitcpio -v -g /boot/ourinitrd.img

Reboot with your usb-stick pluged in and enjoy.

Usefull little commands

Closing a Device

Above we used luksOpen to open a device manually. Clearly, luksClose is the thing to achieve the opposite.

cryptsetup luksClose sda3_crypt

Again, closing the device also removes the device-mapper pseudo device.

Changing the key/passphrase

This involves two steps:

  1. adding a new passphrase
  2. cryptsetup luksAddKey /dev/sda3
  3. deleting the old passphrase
  4. cryptsetup luksRemoveKey /dev/sda3

References

Feedback is highly appreciated.

Introduction

At least once a year we go for holiday together with some friends. No question, they all bring their digital cameras and take a load of pictures.

Right after we get back home they send me their images to upload them to our gallery.

The Problem

Then i usually end up with a directory structure looking smthg like:

.
├── philipp
│   └── S8000
│       ├── DSC_0700.JPG
│       ├── DSC_0701.JPG
│       └── DSC_0709.JPG
├── iris
│   ├── C5600
│   │   ├── DSCN4664.JPG
│   │   ├── DSCN4666.JPG
│   │   └── DSCN4667.JPG
│   └── D80
│       ├── DSC_0830.JPG
│       ├── DSC_0837.JPG
│       ├── DSC_0838.JPG
│       └── DSC_0839.JPG
├── nina
│   └── S3000
│       ├── DSCN4610.JPG
│       ├── DSCN4616.JPG
│       └── DSCN4617.JPG
└── tom
    ├── D70
    │   ├── DSC_4040.JPG
    │   ├── DSC_4048.JPG
    │   └── DSC_4049.JPG
    └── iphone
        ├── IMG_0104.JPG
        └── IMG_0105.JPG

First of all, there might be duplicate filenames as in the example above. But the major problem is that these photos are not sorted by the date they’d been taken which makes it hard to just browse them all and sort out the ones we dislike.

The Script

This is far from being perfect. Actually it’s just a quick hack, but it does the job for me.
It sorts all images given according to its EXIF CreateDate, copies/moves the files and prefixes them with an incrementing number.

Prerequisites:
  • Image::Exiftool
#!/usr/bin/perl -w
##################################################
#Move or copy images and rename them to be sorted by EXIF-CreateDate
#cmdline options:
#./cmd -move <list of images>
#./cmd -copy -dest <destination directory>  <list of images>
##################################################
 
use strict;
use Image::ExifTool;
use Time::Local;
use Getopt::Long;
use File::Basename;
use File::Copy;
 
our $dest;
our $copy;
our $move;
my %Info;
 
GetOptions ('dest=s' => \$dest,
            'copy' => \$copy,
            'move' => \$move           
);
 
 
foreach (@ARGV) {
  GetDateAndTime($_, \%Info);
}
SortAndMove(\%Info);
 
 
sub GetDateAndTime {
  my ($srcfile, $Info_ref) = @_;
  my $srcfileExif = new Image::ExifTool;
  my $info = $srcfileExif->ImageInfo($srcfile,"CreateDate");
  $$info{'CreateDate'} =~ s/\s+/:/g;
  my ($year,$mon,$mday,$hour,$min,$sec) = split(/:/, $$info{'CreateDate'}); 
  $mon = $mon-1;
  $$Info_ref{$srcfile} = timelocal($sec,$min,$hour,$mday,$mon,$year);
}
 
sub SortAndMove {
  my ($Info_ref) = @_;
  my $count = sprintf("%0".length(keys %$Info_ref)."d",0);
  foreach (sort {$$Info_ref{$a} cmp $$Info_ref{$b}} keys %$Info_ref) {
    move("$_",dirname($_) . "/" . $count . "_" . basename($_)) if $move;
    copy("$_",$dest . "/" . $count . "_" . basename($_)) if $copy;
    $count++;
  }
}
Tested on:
  • ArchLinux
  • Debian GNU/Linux Squeeze
Cameras tested with:
  • Nikon D70s
  • Nikon D80
  • Nikon Coolpix 5600
  • Apple Iphone 3GS

Example 1: Sort on Copy

Input Filenames: $ find a/ -xdev -iname "*.jpg*"

a/iris/D80/DSC_0838.JPG
a/iris/C5600/DSCN4665.JPG
a/philipp/S8000/DSC_0700.JPG
a/philipp/S8000/DSC_0705.JPG
a/nina/S3000/DSCN4613.JPG
a/nina/S3000/DSCN4614.JPG
a/tom/iphone/IMG_0102.JPG
a/tom/D70/DSC_4043.JPG
a/tom/D70/DSC_4048.JPG

Copy and sort:
$ NameByExifDate.pl -c -d b/ `find a/ -xdev -iname "*jpg*"`

Resulting Filenames: $ find b/ -xdev -iname "*.jpg*"

b/0_DSC_0700.JPG
b/1_DSCN4613.JPG
b/2_DSCN4614.JPG
b/3_DSC_0705.JPG
b/4_IMG_0102.JPG
b/5_DSCN4665.JPG
b/6_DSC_0838.JPG
b/7_DSC_4043.JPG
b/8_DSC_4048.JPG

Example 2: Sort on Move

Input Filenames: $ find a/ -xdev -iname "*.jpg*"

a/iris/D80/DSC_0838.JPG
a/iris/C5600/DSCN4665.JPG
a/philipp/S8000/DSC_0700.JPG
a/philipp/S8000/DSC_0705.JPG
a/nina/S3000/DSCN4613.JPG
a/nina/S3000/DSCN4614.JPG
a/tom/iphone/IMG_0102.JPG
a/tom/D70/DSC_4043.JPG
a/tom/D70/DSC_4048.JPG

Move and sort:
$ NameByExifDate.pl -m `find a/ -xdev -iname "*jpg*"`

Resulting Filenames: $ find a/ -xdev -iname "*.jpg*"

a/iris/D80/6_DSC_0838.JPG
a/iris/C5600/5_DSCN4665.JPG
a/philipp/S8000/0_DSC_0700.JPG
a/philipp/S8000/3_DSC_0705.JPG
a/nina/S3000/1_DSCN4613.JPG
a/nina/S3000/2_DSCN4614.JPG
a/tom/iphone/4_IMG_0102.JPG
a/tom/D70/7_DSC_4043.JPG
a/tom/D70/8_DSC_4048.JPG

The sort on move routine preserves the original directory structure while the sort on copy routine flattens the hierarchy to a single destination directory.

I highly appreciate feedback of any kind.