Building a Windows Installer

by @jehiah on 2006-06-02 18:35UTC
Filed under: All , Python , SysAdmin , Windows

It’s easier than you thought.

I wanted to deploy some software (python,mysql,webware…) onto a several windows machines, and I wanted installation to be easy. Really easy, so I decided to give the open source NSIS installer (from nullsoft) a try.

The installers goal is simple. Package up files from one directory, allowing you to specify where they should end up. Enable you to run simple commands at install time. Enable you to edit the registry as needed. There is a learning curve, but it isn’t to bad. Follow along and i’ll show you what I’ve learned.

First we need to get the general concept of how NSIS (or any installer package) works. First you setup your install script. Then you use the installer package to make an installable executable based on the instructions from your script. Then your done =)

I’ve been happy with the HM NIS Editor for editing my scripts. Just load your “.nsi” file, or us the wiziard that is included.

My setup below copies/extracts the files to a spot under program files where it will run the installer from. The location isn’t important for this usage, but would matter if you were installing code instead of other installers.

In my case i wanted an installer which packaged up a few other installers (python,mysql,webware…). My directory tree looks like this:

buid
|- pkgs/  (other installers)
|  |- python-2.4.3.msi
|  |- mysql-essential-5.0.22-win32.msi
|  |- pywin32-208.win32-py2.4.exe
|  `- MySQL-python.exe-1.2.0.win32-py2.4.exe
|- src/ (src packages)
| `-Webware-0.9.1/
|- setup.exe (the generated executable)
`- install.nsi

install.nsi !define PRODUCT_NAME “Jehiah base developer install” !define PRODUCT_VERSION “0.1” !define PRODUCT_PUBLISHER “Jehiah” !define PRODUCT_WEB_SITE “http://jehiah.com/projects”

; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "setup.exe"
InstallDir "$PROGRAMFILES\JEHIAH\base_python_install"

Section "MainSection" SEC01
  SetOutPath "$INSTDIR"
  SetOverwrite ifnewer
  File /r "src"
  File /r "pkgs"
SectionEnd

Section "Python" SEC02
  ExecWait 'msiexec /package "$INSTDIR\pkgs\python-2.4.3.msi" /quiet '
  ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "path"
  WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "path" "$0;c:\python24"
SectionEnd

Section "Mysql" SEC03
  ExecWait 'msiexec /package "$INSTDIR\pkgs\mysql-essential-5.0.22-win32.msi" /quiet'
SectionEnd

Section "PyWin32" SEC04
  ; this is not a "quiet" install
  ExecWait '$INSTDIR\pkgs\pywin32-208.win32-py2.4.exe'
SectionEnd

Section "Mysqld-python" SEC05
  ; this is not a "quiet" install
  ExecWait '$INSTDIR\pkgs\MySQL-python.exe-1.2.0.win32-py2.4.exe'
SectionEnd

Section "Webware" SEC06
  ; the "\n" is because it prompts for a password
  ExecWait 'c:\python2.4\python "$INSTDIR\src\Webware-0.9.1\install.py" < "\n"'
SectionEnd

Hit compile, and poof I have a 32 meg executable which will install Python 2.4, Mysql 5.0, and a few python additions.

Subscribe via RSS ı Email
© 2023 - Jehiah Czebotar