Aug 25, 2011

How to Install the Nullsoft Installer - NSIS on Linux

I recently had to create Windows EXE installer packages for a software solution.   The installer solution chosen was the Nullsoft Installer System.  It can be downloaded fromhttp://nsis.sourceforge.net/Download.  NSIS (Nullsoft Scriptable Install System) is a free, open source system used to create Windows installer packages.   It is widely used and a tested solution (see the NSIS website for software packages that use this program).  Now, anyone who has worked with Windows Installer systems knows that they are meant to be ran on Windows machines.  The problem with this is that in today's technology world, Linux can be widely used as a company's main server technology.  In my case, the files needing to be packaged were located on a Linux box.  The goal was to automate the packaging of this software on the Linux server.   The users did now want to have to move the files from the Linux server, to a Windows desktop, and create the installer package.   And they shouldn't have to!  
The NSIS program is an excellent tool.  In addition to running on Windows systems, it can compile packages on a POSIX compliant system as well.  This includes Linux, Unix, etc.  The steps that follow are what I did to get the NSIS working properly on a Linux box.  As always, do consult the documentation for installing NSIS that comes with the program.  The documentation provides excellent information on using and installing the software.  However, the instuctions can be a little vague for installing on a Linux box.  If you are like me, someitmes you would like to see a step-by-step page.  Some of the steps below come directly from the documentation for NSIS, and some are from what I ran into while installing the software.   The software was installed on both a Fedora Core 3 and Unbuntu 7.04 box.
Step 1.)  In order to install the software on Linux, you will need two packages.  First, you need the source code for NSIS.  Second, you will need a ZIP package of the NSIS software.  You will want to make sure you download the same verison numbers.  Both packages can be downloaded from the following link:  http://sourceforge.net/project/showfiles.php?group_id=22049 (the software is a project on SourceForge).   Download these files to your Linux box. 
                    As of this writing, the current version numbers of the packages you will download are:  nsis-2.34-src.tar.bz2 (source) and nsis-2.34.zip (zip package).
Step 2.) After downloading the two packages, I created a directory named 'nsis' in /usr/local.   You can create this diretcory wherever you want, as long as the users who will need it have permissions to access it.  Move the two packages you have just downloaded into the directory 'nsis' that you just have created.  The commands to do this are below. 
                    In the /usr/local directory, issue a 'mkdir nsis' command.
                    Move (or copy) the files into /usr/local/nsis with these commands (execute these commands from inside the directory where you downloaded the packages) : 
                                   a.   mv nsis-2.34-src.tar.bz2 /usr/local/nsis/ 
                                   b.   mv nsis-2.34.zip /usr/local/nsis/
Step 3.) After moving the files into /usr/local/nsis , extract the two packages.  The commands I used are below:
                                 a.    cd /usr/local/nsis (if you are not there already)
                                 b.    tar -jxvf nsis-2.34-src.tar.bz2 
                                 c.    unzip nsis-2.34.zip
Step 4.) After you have extracted the two packages, you will have two directories in/usr/local/nsis.  With the versions I had downloaded above, the two directories were nsis-2.34-src and nsis-2.34.   The nsis-2.34-src diretory contains the source code for the NSIS package.  You will compile the Installer from inside this folder.  The nsis-2.34 directory contains a pre-compiled package of the software for Windows.   Inside the nsis-2.34-src directory will be an INSTALL file.  Read this file!  It contains information to assist you with your installation in Linux.  Your system will need to meet the requirements section of the Install file.  Basically, you just need to make sure your Linux system has the three software tools needed to compile and run NSIS. 
                   The three tools you need are:
                           a. Python version 1.6 and above
                           b. Scons version 0.96.93 or above.  (this is a program similiar to 'make').   You can install your distro's version or install from the source located at: http://www.scons.org.
                           c. A 'C' Compiler (gcc and g++ packages)
Depending on your Linux installtion, these programs may already be installed.  If not, they are fairly standard and can easily be installed from your distro's package installation program (apt-get, yum, etc.).   My box did not have the 'scons' program, so I needed to install the RPM package for this program.    If you need help finding and installing the packages, a simple Google query on the program name and your distro name will point you in the right direction.
Step 5.)  After meeting the requirements section, you now need to build the NSIS compiler for Linux.  The program you will be building is called 'makensis'.  This is what will actually build the Installer Package on a Linux box.  I chose not to use a cross-compiler for this installation, since I only needed to create Installer packages for Windows systems.  The process to create this 'makensis' program is described below:
                              a.) Inside the nsis-2.34-src directory isssue the following command (also mentioned in the INSTALL file):  
scons SKIPSTUBS=all SKIPPLUGINS=all SKIPUTILS=all SKIPMISC=all NSIS_CONFIG_CONST_DATA=no PREFIX=/path/to/your/extracted/zip/directory install-compiler
So for my setup the command was:
scons SKIPSTUBS=all SKIPPLUGINS=all SKIPUTILS=all SKIPMISC=all NSIS_CONFIG_CONST_DATA=no PREFIX=/usr/local/nsis/nsis-2.34 install-compiler
 The option "install-compiler" at the end of the command is an actual option you must use!  It is not part of the PREFIX parameter.
This command will build the 'makensis' program and place it into the /usr/local/nsis/nsis-2.34 directory (or whatever the path is to the directory that you extracted your zip file to; it also may place the 'makensis' file in the 'bin' dir within your PREFIX).
NOTE:  If you issue this command and while it is running you receive 'sh: o: command not found' errors, this means that you do not have the C compiler packages installed (gcc, g++). 
(For my system, I needed to install the rpm packages for g++ and libstdc++.  G++ can also be the gcc-c++ RPM package on your system.). 

Step 6.) After the makensis program is built, you can begin createing installer packages for Windows inside a Linux box.  You will need to create Installer scripts and have the makensis program execute them to create the installer packages.   For example, if you have a script named 'software_install.nsi' you would create the package by issuing the following command inside the /usr/local/nsis/nsis-2.34 directory: 
                                 ./makensis software_install.nsi
 UPDATE: After Installing the compiler on a CentOS 5 system, when I ran 'makensis' the first time I received this error message:
Error: opening stub "/usr/local/nsis/nsis-2.34/share/nsis/Stubs/zlib
Error initalizing CEXEBuild: error setting default stub
To correct this problem, create a symlink.  From inside of the /usr/local/nsis/nsis-2.34 directory, first 'mkdir share'.  The inside of the 'share' directory issue: 'ln -s /usr/local/nsis/nsis-2.34 nsis' .  This will create the symlink back to the folder where it can then find the 'Stubs' directory (which lies in the top level of the nsis-2.34 directory).
Step 7.) At this point, you have successfully installed the NSIS software on Linux and are able to create Windows Installer packages on a Linux box.  The EXE packages will reside on a Linux box and can be downlaoed via a Website, FTP, or any other method that you choose to provide.  I set up a script that was executed by a cron job to build packages automatically every night and placed them in a deployment directory.  You may want to create symlinks to the makensis program, or include the /usr/local/nsis/nsis-2.34 directory in your PATH to make things easier for you.  Remember, the installer scripts that you create for use on Linux should contain absolute paths to the source files needed to create the package on the Linux box, while the destination paths during install are Windows based.  Good luck.