Thursday, December 22, 2011

Added augeas.vapi and augeas.dep.

If you have ever dreamed of using augeas from vala, your dreams have been heard - just before christmas.
The binding is nearly complete, just aug_span is missing. So dive into xml using augeas, even in relative paths.

Wednesday, December 21, 2011

Da - Presence lands in fedora

Finally, presence - that small video tool - has landed in the fedora-updates repo.

You can install it using:
$ sudo yum install presence

That's all there is to do.

Thursday, December 15, 2011

De-Duping files on BTRFS.

Brave souls can test BTRFS for a couple of Fedora releases.

Removing duplicate/redundant files on filesystems is a common thing, e.g. when creating regular backups or so. On ext4 this can be realized using traditional hardlinks.
Hardlinks all point to the same blocks on the logical drive below. So if a write happens to one of the hardlinks, this also "appears" in all other hardlinks (which point to he same - modified - block).
This is no problem in a backup scenario, as you normally don't modify backuped files.

In my case I wanted to remove redundant files that might get modified and the changes shouldn't be reflected in all other copies. So what I want to achieve is to let several links (files) point to the same block for reading, but if a write happens to one block this should be just happen to the one file (link). So, copy the file on write. Wait, don't we know that as CoW? Yep.

Luckily BTRFS allows cow files using the cp --reflink command.
The following snippet replaces all copies of a file with "light weight" aka cow copies.

#!/bin/bash
# Usage: dedup.sh PATH_TO_HIER_WITH_MANY_EXPECTED_DUPES
mkdir sums
find $@ -type f -print0 | while read -d $'\0' -r F
do
  echo -n "$F : "
  FHASH=$(sha256sum "$F" | cut -d" " -f1);
  # If hashed, it's probably a dupe, compare bytewise 
  # and create a reflink (so cow)
  if [[ -f "sums/$FHASH" ]] && cmp -s "sums/$FHASH" "$F";
  then
    echo "Dup." ;
    rm "$F" ;
    cp --reflink "sums/$FHASH" "$F" ;

  # It's a new file, create a hash entry.
  else
    echo "New." ;
    cp --reflink "$F" "sums/$FHASH" ;
  fi
done
rm sums/*
rmdir sums

And in general, btrfs didn't yet eat my data, it even survived two power losses ...
Update: Updated to handle files with special characters. This script also makes some assumptions, e.g. the files should not be modified while running this script.

Friday, December 9, 2011

OpenCL on Fedora: A quick look at building pocl.

Finally a 3.0 release candidate of llvm is packaged for Fedora and available via rawhide. Many of the current OpenCL implementations like pocl and clover depend on llvm-3.0 and with this release it is finally an easy thing to build pocl on Fedora.
pocl has some other pre-requirements besides clang/llvm, after installing them you can just build the software as usual:

$ sudo yum install --enablerepo=rawhide llvm-devel llvm clang \
libtool-ltdl

$ git clone 
$ bzr branch lp:pocl
$ bash autogen.sh
$ ./configure
$ make
$ make check

Wednesday, November 30, 2011

Another approach to modfiy structured files (like config or XML files)


Vienna (Wien) - Hofburg - Labors of Hercules (Encounter with Antaeus - Garden of the Hesperides and Killing Augeas - Augean Stables)

Have you ever wondered if there is a more convenient way to modify xml documents, beside libxml2? Sure, there is the nice dom within Firefox, but outside of that?
Well, there is augeas. AFAIK initially a project to standardize the interface to modify configuration files, in other words a common syntax for different formats.
Files are parsed trough so called lenses. Those lenses transform the actual file (e.g. httpd.conf or passwd) into a tree, which than can be modified by a set of augeas commands.
As lenses are bi-directional the same lense can be used to read a file, and to dump the (internal augeas) tree back into a valid configuration file. A nice concept, ey?

A back to the topic, one of the lenses - Xml.lns - can be used to modify XML files.
The following example creates a dummy xml file and modifies it using augtool.


$ sudo yum install augeas tidyp

$ cat > abc.xml <<EOF
<world poo="bar">
<child>Hi there.</child>
</world>
EOF

$ augtool -LA -e <<EOF
# Load XML lense
set /augeas/load/xml/lens "Xml.lns"
set /augeas/load/xml/incl "$PWD/abc.xml"
load

# Dump internal tree
print /files

# Add a note
set /files/$PWD/abc.xml/world/note/#attribute/timestamp "now"
set /files/$PWD/abc.xml/world/note/#text "Wtf"

# Change the text of a node.
set /files/$PWD/abc.xml/world/child/#text "Hello World."

# Insert a new child after the present child
ins child after /files/$PWD/abc.xml/world/child
set /files/$PWD/abc.xml/world/child[2]/#text "Hello Mars."

# Insert a new child - anywhere ..
set /files/$PWD/abc.xml/world/child[3]/#text "Hello Jupiter Jones."

# More children
set /files/$PWD/abc.xml/world/child[4]/child/child/#text "Hello Mars."

print /files/$PWD/abc.xml

save
print /augeas//error
EOF

$ tidyp -xml -i -q < abc.xml

$ unlink abc.xml

With the help from the people at #augeas on freenode, I found out that (a) there is a small bug preventing the usage of relative paths and (b) You need a little knowledge about the format you are writin to. In the (xml) example above, you need to specify attributes before specifying a #text node, because they are written first. If they were specified the other way round, augeas would fail while saving.

Tuesday, November 29, 2011

Using lokkit to handle your firewall.

Some common thing is to turn of the firewall if a freshly installed machine isn't reachable from the outside, as fidling with iptables is not everyones passion.

lokkit is another way to open some ports to the public.

Just use
$ sudo lokkit --list-services

to see what services/ports can be managed/opened using lokkit. For me it's quite common to open ports for ssh, ipsec and mdns afer a fresh installation

$ sudo lokkit -s ssh
$ sudo lokkit -s mdns
$ sudo lokkit -s ipsec

Let's see if there will be something new in the near future to handle - somtimes quite complex (see virtualization) - iptable setups.

Sunday, November 27, 2011

How to get a link to your public hardware data (smolt profile).

Smolt is a tool to gather data about your hardware in a distribution independent way. Hardware data can be interesting for a couple of reasons, e.g. developers get detailed informations about hardware involved in bugs.
When opted-in, a smolt profile is created for your hardware after the installation, on the first boot (via firstboot). There is smoltSendProfile (part of the smolt package), which can be used to re-send your hw data.
But there is no easy way to get a link to your public profile - this should be changed, but until then ..
- if you are interested - you can use the following lines, to determine the URL to your public profile:
$ python <<EOF
import sys
sys.path.append ("/usr/share/smolt/client")
import smolt 
print (smolt.get_profile_link(smolt.smoonURL, smolt.getPubUUID ()))
EOF