14 Mar 2011

Emacs el-get on windows

Emacs el-get allows you to install and manage elisp code for Emacs. It supports lots of differents types of sources and is able to installupdate and remove them, but more importantly it will init them for you.
It allows you to keep up-to-date you elisp packages like cedet, emacs-w3m and hundred others. But if you tried to use it on windows you will figure out that a lot of them fail to install. It is related to the fact that most of packages are using UNIX command line tools which are not working on windows out-of-box.
Fortunately most of them could be installed on windows with slight modifications. Below small how-to:
1. Download and install cygwin tools and and cygwin/bin folder to your PATH. For the most of the packages you will need:
- curl (I'll explain later why it is necessary)
- ssh
- openssl
- bzr/git/subversion etc - it depends on which version control system has been used for package. It could be easily identified from recipe file. Below simple example of yasnippet recipe:
(:name yasnippet
      :type svn
      :url "http://yasnippet.googlecode.com/svn/trunk/"
      :features "yasnippet"
      :post-init (lambda ()
           (yas/initialize)
           (add-to-list 'yas/snippet-dirs (concat el-get-dir "yasnippet/snippets"))
            (yas/reload-all)))

Pay attention to type. It is specifying used version control system. In the given example it is subversion. So to be able to install this package you need svn client in your path. It is not mandatory to have it from cygwin but I prefer to use cygwin one as everything could be installed by its setup from one place.

- make utility

- autotools (autoconf, automake and co.)

- etc. (please check what exactly recipe is using.)

2. Open bash from cygwin installation (simply run cygwin.bat file) and enter the following commands:
$ cd /usr/ssl/certs
$ curl http://curl.haxx.se/ca/cacert.pem | awk 'split_after==1{n++;split_after=0} /-----END CERTIFICATE-----/ {split_after=1} {print > "cert" n ".pem"}'
$ c_rehash
If you won't do that you will have certificate error during installation of el-get from github. These commands will imports many certificates for different sites which are collected by curl developers team.

3. Follow the instruction specified on el-get site.

4. If your favourite package gives error check the following:

- If you've installed client for version control mentioned in recipe and is path specified in your PATH?

- If site is available by web browser.

- If it fails during installation check what kind of commands have been used. Try to run them from CMD prompt (not bash). If needed correct them.

I'll give you example of my patches to emacs-w3m and cedet.

emacs-w3m

Original recipe was:
(:name emacs-w3m
      :type cvs
      :module "emacs-w3m"
      :url ":pserver:anonymous@cvs.namazu.org:/storage/cvsroot"
      :build `("autoconf" ("./configure" ,(concat "--with-emacs=" el-get-emacs)) "make")
      :info "doc")

autoconf, ./configure commands are shell scripts hence they are not executable from CMD prompt and this build will fail. Fixed version of recipe:
(:name emacs-w3m
      :type cvs
      :module "emacs-w3m"
      :url ":pserver:anonymous@cvs.namazu.org:/storage/cvsroot"
      :build `("autoconf" ("./configure" ,(concat "--with-emacs=" el-get-emacs)) "make")
      :build/windows-nt ("sh /usr/bin/autoconf" "sh ./configure" "make")
      :info "doc")

CEDET

Original recipe was:
(:name cedet
      :type bzr
      :url "bzr://cedet.bzr.sourceforge.net/bzrroot/cedet/code/trunk"
      :build ("touch `find . -name Makefile`" "make")
      :load-path ("./common"))
Patch for this recipe was more difficult as “`” symbol is not valid for CMD and you cannot pass whole this command to shell as touch binary. Moreover Makefile for CEDET use UNIX version of find command. Below how I fixed it:
(:name cedet
      :type bzr
      :url "bzr://cedet.bzr.sourceforge.net/bzrroot/cedet/code/trunk"
      :build ("touch `find . -name Makefile`" "make")
      :build/windows-nt ("echo #!/bin/sh > tmp.sh & echo touch `/usr/bin/find . -name Makefile` >> tmp.sh & echo make FIND=/usr/bin/find >> tmp.sh" 
          "sed 's/^M$//' tmp.sh  > tmp2.sh"
          "sh ./tmp2.sh" "rm ./tmp.sh ./tmp2.sh")
      :load-path ("./common"))
By this way you can fix almost any recipe. If you do it, don’t forget to send patch to original author and share with us ;)

8 Mar 2011

Utility for calculation MIFARE Password

The ones who read my post about how to calculate MIFARE password found it very tough to calculate manually. Hence I've developed tool to automate it. The full source codes are available in github. If you don't care about source code, executable file is also there. You need .Net 4.0 and F# runtime to run it.