2011-12-08

P4 and return codes

This just hit me.


>cat test.sh
#!/bin/sh
/usr/local/bin/p4 sync -n
rc=$?
echo "Returncode $rc"

>cat test2
#!/bin/sh
# \
exec tclsh "$0" "$@"
set rc [catch {exec -- /usr/local/bin/p4 sync -n} out]
puts "Return code: \"$rc\""
puts "out: \"$out\""


 >./test2
Return code: "1"
out: "File(s) up-to-date."

 >./test.sh
File(s) up-to-date.
Returncode 0

>/usr/local/bin/p4 sync -n
File(s) up-to-date.
>echo $?
0

>/usr/local/bin/p4 -s sync -n
error: File(s) up-to-date.
exit: 0

P4 knowledge base article regarding this:

"In general, you should not rely on a command exiting non-zero on "failure". Instead, use the global -s flag to help interpret the command output -- and parse that output in your scripts. Possible tags with the -s flag include info:, info1:, info2:, error:, and text:"

My kangaroo rating for this:
 [x] not funny!

2011-11-19

FreeBSD 9.0RC1 to RC2 upgrade

Finally had a little bit of time to deal with my laptop at home. As FreeBSD 9.0RC is out, I thought I'd give this a try by updating from 9.0 RC1.
Normally this works quite easily on FreeBSD by running the freebsd-update utility, but this time it failed.

So to get it work, see here.

In short:
# sed -i '' -e 's/=_/=%@_/' /usr/sbin/freebsd-update
# freebsd-update upgrade -r 9.0-RC2
 



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
}

2011-09-24

Upgrading the sheevaplug

Upgrading the sheevaplug
Had to upgrade my parents plug.
The whole thing, uboot, distro, etc.
Thanks to this awesome guide everything went very smoothly.

2011-09-23

flexget + transmission + tvtorrents + CentOS 5

flexget + transmission + tvtorrents + CentOS 5
Part I: Get transmission installed

Add repository

in /etc/yum.repos.d/geekery,repo add:
[geekery]
name = geekery repository
baseurl = http://geekery.altervista.org/geekery/el5/$basearch
enabled = 1
protect = 0
gpgkey = http://geekery.altervista.org/download.php?filename=GEEKERY-GPG-KEY
gpgcheck = 1

install packages

sudo yum install transmission transmission-daemon transmission-cli transmission-common

Config

  • in /etc/sysconfig/transmission-daemon add the following line: (Change IP, passwords and path to what fit:s your need)
DAEMON_ARGS="-b -t -a \"192.168.*.*\" -e /var/log/transmission/transmission.log -u user -v password -w /incoming"
  • setup correct permissions for the download directory (/incoming)
$ sudo mkdir /incoming
$ sudo chown transmission:users /incoming
$ sudo chmod 770 /incoming
  • start the daemon
$ sudo service transmission-daemon start

Access through browser

Remote GUI

  • Get the binary here.
  • extract and run.

Alternatively Java GUI


Part II: Configure flexget
See the previous post to see how to get it installed on CentOS.

Requirements

I had to manually update the version of transmissionrpc:
sudo easy_install-2.6 transmissionrpc

Configuration

As the feeds on tvtorrent are already limited to the series you select, it is OK, to just get everything in the feed. Flexget will take care of not downloading duplicates (different quality). By default it will prefer the better quality.
Add the following to ~/.flexget/config.yml
feeds:
  feed_name:
    rss: <Your rss feed here>
    download: ~/torrents
    all_series: yes
    transmission:
      host: 192.168.0.5
      port: 9091
      username: bon
      password: <password>

Testing

You can check your settings for syntax by running:
flexget -v --check
For a dry-run, run:
flexget -v --test
If everything works OK, just put it in a cron-job to run every now and then.

2011-09-22

Install flexget on Centos 5.x

Install flexget on Centos 5.x
I want to play with flexget a bit on CentOS 5.x. Since it requires python 2.6 (well 2.5 is also OK), It's a bit tricky. Mostly resolving dependencies.
So in case anybody want's to do the same, maybe this saves a few clicks.

As I am also lazy, I just paste this from my bash history:

sudo yum install python26 python26-devel
cd ~/downloads/
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
cd ~/tmp/
tar xvf ~/downloads/setuptools-0.6c11.tar.gz
cd setuptools-0.6c11/
sudo python26 setup.py install
cd ~/downloads/
sudo easy_install-2.6 http://download.cherrypy.org/cherrypy/3.2.0/CherryPy-3.2.0-py2.6.egg
wget http://pypi.python.org/packages/source/F/Flask/Flask-0.7.2.tar.gz
cd ~/tmp/
tar xvf ~/downloads/Flask-0.7.2.tar.gz
cd Flask-0.7.2/
sudo python26 setup.py install
cd ~/downloads/
wget http://pypi.python.org/packages/source/p/progressbar/progressbar-2.2.tar.gz
cd ~/tmp/
tar xvf ~/downloads/progressbar-2.2.tar.gz
cd progressbar-2.2/
sudo python26 setup.py install
cd ~/downloads/
wget http://pypi.python.org/packages/source/p/pynzb/pynzb-0.1.0.tar.gz
cd ~/tmp/
tar xvf ~/downloads/pynzb-0.1.0.tar.gz
cd pynzb-0.1.0/
sudo python26 setup.py install
cd ~/downloads/
wget http://www.dalkescientific.com/Python/PyRSS2Gen-1.0.0.tar.gz
cd ~/tmp/
tar xvf ~/downloads/PyRSS2Gen-1.0.0.tar.gz
cd PyRSS2Gen-1.0.0/
sudo python26 setup.py install
cd ~/downloads/
wget https://html5lib.googlecode.com/files/html5lib-0.90.zip
cd ~/tmp/
unzip ~/downloads/html5lib-0.90.zip
cd html5lib-0.90/
sudo python26 setup.py install
cd ~/downloads/
wget http://www.crummy.com/software/BeautifulSoup/download/3.x/BeautifulSoup-3.2.0.tar.gz
cd ~/tmp/
tar xvf ~/downloads/BeautifulSoup-3.2.0.tar.gz
cd BeautifulSoup-3.2.0/
sudo python26 setup.py install
cd ~/downloads/
wget http://pyyaml.org/download/pyyaml/PyYAML-3.10.tar.gz
cd ~/tmp/
tar xvf ~/downloads/PyYAML-3.10.tar.gz
cd PyYAML-3.10/
sudo python26 setup.py install
cd ~/downloads/
wget http://prdownloads.sourceforge.net/sqlalchemy/SQLAlchemy-0.7.2.tar.gz?download
cd ~/tmp/
tar xvf ~/downloads/SQLAlchemy-0.7.2.tar.gz
cd SQLAlchemy-0.7.2/
sudo python26 setup.py install
cd ~/downloads/
wget https://feedparser.googlecode.com/files/feedparser-5.0.1.tar.bz2
cd ~/tmp/
tar xvf ~/downloads/feedparser-5.0.1.tar.bz2
cd feedparser-5.0.1/
sudo python26 setup.py install


2011-09-21

special ssh config file with git remote

special ssh config file with git remote


For complicated reasons (nfs mounts, permissions, etc) I need a special ssh config file to use with git remote. This is actually done quite easily by using a wrapper script:
#!/bin/bash
/usr/bin/ssh -F /path/to/ssh/config $@

Then just export the variable GIT_SSH to point to the wrapper script.
export GIT_SSH='/path/to/ssh_wrap'

2011-09-14

Setting shell in crontab

I didn't know until now, that you can set a shell in crontab, ignoring whatever shell is set for the crontab's user.
SHELL=/bin/bash
This can be useful, if you have to rely on a certain shell or environment for whatever reason.

2011-09-11

Japanese pdfs & fonts

I don't know why it's not installed by default, but to get Japanese PDFs in Ubuntu  11.04 displayed correctly you need to install the package 'poppler-data' .Quite easy, once you know what the problem is

2011-08-08

xrdp - rdesktop server in Linux

Normally I use ssh for everything, but sometimes I need a GUI to run stuff and remote X11 over ssh does not really work for me.
So normally I use VNC, but then you need a client and in the corporate universe you will not have it (or get it easily). Sure, there is the java-version you can run in your browser, but I'm not fan of that either.
Solution: xrdp
Comes with ubuntu and not much to configure. And the client (Remote Desktop Connection) comes with Windows.

2011-05-19

Removing quotes

One great program I have to use returns values quoted like this: `bla'
So to be able to process it's output in a pipe easier, I use tr. The command just looks too beautiful to not mention it:

tr -d '`'"'"

2011-04-20

Weird locales

Sometimes I wonder who comes up with installations like these:
> locale -a
C
POSIX
de_LU.UTF-8
en_GB
en_GB.ISO8859-1
en_GB.ISO8859-15
en_GB.ISO8859-15@euro
en_GB.UTF-8
en_IE
en_IE.ISO8859-1
en_IE.ISO8859-15
en_IE.ISO8859-15@euro
en_IE.UTF-8
fr.ISO8859-15
fr.UTF-8
fr_BE
fr_BE.ISO8859-1
fr_BE.ISO8859-15
fr_BE.ISO8859-15@euro
fr_BE.UTF-8
fr_BE.UTF-8@euro
fr_FR.ISO8859-15
fr_FR.ISO8859-15@euro
fr_FR.UTF-8
fr_FR.UTF-8@euro
fr_LU.UTF-8
iso_8859_1
nl
nl.ISO8859-15
nl_BE
nl_BE.ISO8859-1
nl_BE.ISO8859-15
nl_BE.ISO8859-15@euro
nl_BE.UTF-8
nl_NL
nl_NL.ISO8859-1
nl_NL.ISO8859-15
nl_NL.ISO8859-15@euro
nl_NL.UTF-8
Well, at least they have the french French. IMHO It should be taken out for consistency. :-)

My DWTF

Just found myself writing the following in a Doku-Wiki page:

[..]<html><br></html>[..]
Really horrible stuff, but I see no alternative (beside upgrading/installing new Wiki).

2011-04-01

Shot yourself in the foot with carriage return.

Just today somebody had a problem with a file that he "could not cat",
but less worked. The reason was that the file had only a carriage
return at the end of the only line.

Here's an example how to reproduce:
> echo -en "bla\r" > bla2
> cat bla2
> od -c bla2
0000000 b l a \r
0000004