2011-10-27

Import git to perforce

Import git to perforce

At work I have to use painforce, although I don't like it. So I decided to use it as kind of  a master repository for my git stuff. git-p4 is a python script that does most of what I want, however I wanted to keep the original commit date and hash. So here's a little patch to achieve this.
 
--- /usr/local/home/bjoern.henkel/git-p4.org    2011-10-27 11:56:05.351331262 +0900
+++ /usr/libexec/git-core/git-p4        2011-10-27 16:24:12.623302361 +0900
@@ -413,6 +413,14 @@
            continue

        logMessage += log
+
+    # I want to keep the original date when importing from git
+    logMessage += "\n"
+    logMessage += "Original commit date: "
+    cmd = 'git show -s --pretty="%ai (%ar) " ' + commit
+    logMessage += read_pipe(cmd)
+    logMessage += "commit: %s" % commit
+
     return logMessage

 def extractSettingsFromNotes(commit):

gitk in cygwin (with cygwin-ports)

gitk in cygwin (with cygwin-ports)

Recently I had problems with gitk not working. Turns out the fix for this is rather easy, see the diff below:

--- /home/bjoern.henkel/gitk.org        2011-10-26 15:44:27.096698500 +0900
+++ /usr/bin/gitk       2011-10-26 15:44:57.143573500 +0900
@@ -2367,7 +2367,7 @@
        }
     }

-    if {[info exists geometry(state)] && $geometry(state) eq "zoomed"} {
+    if {[info exists geometry(state)] && $geometry(state) eq "normal"} {
         wm state . $geometry(state)
     }

2011-10-18

Changing /etc/fstab with puppet and augeas

Changing /etc/fstab with puppet and augeas

Puppet Augeas documentation

My case: Add tmpfs

Trying with augtool, and breaking my head on how to add an entry at the end of the file, I realized eventually figured out, that you don't have to care at all with augeas, just add a 01 prefixed value and it will be added to the end.

So to add I use:

defvar fstab /files/etc/fstab
set $fstab/01/spec tmpfs
set $fstab/01/file /dev/shm
set $fstab/01/vfstype tmpfs
set $fstab/01/opt defaults
set $fstab/01/dump 0
set $fstab/01/passno 0
save

But what if the entry already exists?
Since in fstab the entries are just numbered, it took a while to figure out how to use the last() function.

This should work (e.g. change option)

set $fstab/*[spec = 'tmpfs'][file = '/dev/shm']/opt size
set $fstab/*[spec = 'tmpfs'][file = '/dev/shm']/opt/value 12G

This will only change/add the option size=12G, where spec equals 'tmpfs' AND file equals '/dev/shm'.

Then, all left to do was finding a rule for puppet to not add a new line on each run, that's done quite easily with 'match':

match *[spec='tmpfs'][file = '/dev/shm']

So in puppet it looks like this:

    augeas{"Add tmpfs for case ${caseusername}@${hostname}":
        context => "/files/etc/fstab",
        changes => [
            "set 01/spec tmpfs",
            "set 01/file /dev/shm",
            "set 01/vfstype tmpfs",
            "set 01/opt size",
            "set 01/opt value ${shmem}",
            "set 01/dump 0",
            "set 01/passno 0",
            ],
        onlyif => "match *[spec='tmpfs'][file = '/dev/shm'] size == 0",
    }

    augeas{"change tmpfs size for ${caseusername}@${hostname} to ${shmem}":
        context => "/files/etc/fstab",
        changes => [
            "set *[spec = 'tmpfs'][file = '/dev/shm']/opt size",
            "set *[spec = 'tmpfs'][file = '/dev/shm']/opt/value ${shmem}",
            ],
        require => Augeas["Add tmpfs for case ${caseusername}@${hostname}"],
    }

2011-10-11

64-bit or not

Creative way of figuring out if a system is 64-bit or not, for people who don't believe in "uname".
have_64bit_userland() {
  file -L /bin/sh | grep -q 64-bit
}