2008. 7. 2. 18:30

NSIS Installer

1. 개요
 NSIS(Nullsoft Scriptable Install System)는 스크립트로 작성하는 Windows용 installer이다.

2. 특정
 상업적인 용도로 사용 가능하다.
 overhead 가 작다( 설치 파일의 크기가 작다)

3. 사용기
 프로젝트 때문에 사용했었다.
 아주 간단한 기능만을 사용했기 때문에 평가를 내리기는 어렵지만, 간단한 배포인 경우에는 sample을 이용하면 빠르게 제작할 수 있고 installer 프로그램 자체도 가볍고 nsi 파일 하나만 관리하면 되니깐 상업용 installer 보다 낳을 수 있다는 판단이 들었다.
 전용의 editor가 몇가지 존재하는 것 같았지만 사용해 보지는 않아서 평가를 내리기는 어렵다.

 4. 관련 사이트
  http://nsis.sourceforge.net

 5. sample 분석(2개의 com object를 배포하는 예제이다. NSIS site에는 많은 종류의 예제가 존재한다.)

  ; 은 주석이다.
; ----------------------------------------------------------------------------------------------

 ; setup.nsi
;
; This script is based on example1.nsi, but it remember the directory,
; has uninstall support and (optionally) installs start menu shortcuts.
;
; It will install example2.nsi into a directory that the user selects,

;--------------------------------

; 이름을 지정한다.
; The name of the installer
Name "Setup"

; 생성되는 설치 파일 이름을 지정한다.
; The file to write
OutFile "SetupU.exe"

; 설치될 디렉토리를 지정한다.
; The default installation directory
InstallDir $PROGRAMFILES\RegSvrHelpU

; 레지스트리를 만든다. ( 설치 시 아래 레지스트리의 key에 현재 설치된 위치를 넣었놓고, 이후 재 설치가 이루어지면 기본 설치 디렉토리를 레지스트리에 저장된 경로로 설정한다.)
; Registry key to check for directory (so if you install again, it will
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\RegSvrHelpU" "Install_Dir"


; Vista인 경우 admin 권한으로 실행되게 한다.( component 등록 작업과 admin 권한이 필요한 파일과 레지스터리 access 때문)
; Request application privileges for Windows Vista
RequestExecutionLevel admin


; install, uninstall 시 상세 정보를 보이게 한다.( 설치 되는 목록들이 UI 상에 나타난다)
; Set ShowInstDetails
ShowInstDetails show

; Set ShowUninstDetails
ShowUninstDetails show

;--------------------------------

; 페이지를 설정한다.
; component는 설치 시 설치 항목이 여러개 있고 사용자가 설치 할 항목등을 선택/비 선택 할 수 있는 페이지를 의미한다.
; directory는 설치 시 사용자가 설치될 디렉토리를 변경할 수 있는 페이지를 의미한다.
; instfiles는 설치 시 progress bar가 진행되면서 위의 ShowInstDetails show가 주어진 경우 설치되는 작업이 각각 텍스트로 표시된다.
; Pages

;Page components
Page directory
Page instfiles

; uninstConfirm uninstall시 사용자에게 uninstall에 대한 confirm을 받는 페이지이다.
; insttfiles 는 설치시와 동일하다.

UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------

; Section은 여러개의 instruction으로 이루어 졌으면 원 예제는 2개의 Section으로 구성되어 있고 component 페이지에서 설치 할 항목을 선택할 수 있었다.

; The stuff to install
Section "RegSvrHelpU"

  SectionIn RO
 
  ; INSTDIR은 실제로 설치되는 디렉토리 위치이다. 사용자가 변경을 하였다면 변경 된 최종 디렉토리 path가 저정되어 있다.
  ; Set output path to the installation directory.
  SetOutPath $INSTDIR
 
  ; 설치될 파일 목록이며 installer를 만드는 PC에서의 상대경로가 지원된다.
  ; Put file there
  File "..\RegCom\RegCom\Release_U\RegComU.exe"
  File "..\RegSvrHelp\Release_U\RegSvrHelpU.dll"


  ; 파일이 설치되고 등록 작업을 수행한다.
  ; Register component file
  Exec '"$INSTDIR\RegComU.exe" /regserver'
  RegDLL $INSTDIR\RegSvrHelpU.dll
 
  ; 재 설치 시를 위해  현재 설치된 위치를 위에서 만든 레지스터리에 저장한다.
  ; Write the installation path into the registry
  WriteRegStr HKLM SOFTWARE\RegSvrHelpU "Install_Dir" "$INSTDIR"

  ; 프로그램 추가 제거 에서 UnInstall을 할 수 있도록 setting한다.
 
  ; Write the uninstall keys for Windows
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegSvrHelpU" "DisplayName" "RegSvrHelpU"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegSvrHelpU" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegSvrHelpU" "NoModify" 1
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegSvrHelpU" "NoRepair" 1
  WriteUninstaller "uninstall.exe"
 
SectionEnd

; Optional section (can be disabled by the user)
;Section "Start Menu Shortcuts"

;  CreateDirectory "$SMPROGRAMS\Example2"
;  CreateShortCut "$SMPROGRAMS\Example2\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
;  CreateShortCut "$SMPROGRAMS\Example2\Example2 (MakeNSISW).lnk" "$INSTDIR\example2.nsi" "" "$INSTDIR\example2.nsi" 0
 
;SectionEnd

;--------------------------------

; Uninstaller

Section "Uninstall"m
 

  ; UnInstall 관련 부분 및 재 설치 관련 레지스터리를 지운다.
  ; Remove registry keys
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\RegSvrHelpU"
  DeleteRegKey HKLM SOFTWARE\RegSvrHelpU


  ; UnRegister component file
  ; 등록 해제 한다.
  UnRegDLL $INSTDIR\RegSvrHelpU.dll
  Exec '"$INSTDIR\RegComU.exe" /unregserver'

  ; 파일을 지운다.
  ; Remove files and uninstaller
  Delete $INSTDIR\RegSvrHelpU.dll
  Sleep  1000   ; Wait Unload RegComU process
  Delete $INSTDIR\RegComU.exe

  Delete $INSTDIR\uninstall.exe

  ; Remove shortcuts, if any
  ;Delete "$SMPROGRAMS\Example2\*.*"

  ; Remove directories used
  ;RMDir "$SMPROGRAMS\Example2"

  ; 설치 폴더를 지운다.
  RMDir "$INSTDIR"

SectionEnd