Simple Installer for BE based on NSIS

Feb 25, 2009 at 9:02 AM

Hi all !
First I would like to thank all the contributers for this great peace of software !!

I wrote a small simple installer for BE ( which installs the source code not dll deployment .. )
This install script  assumes that you have the latest version of NSIS + the time module

The installer assumes that you might have 3 different servers ... DEV , TEST , PROD , which you would have to configure in the ini file also pasted bellow ...

If somebody is interested to collaborate on the creation of full installers - both for production and development ( full meaning from configuring IIS and creating web site to creation of database + option to have separate installer for different database , please respond here ...

So here is the code ( there might be some bugs .. ) , Any comments ( even negative ones ; ) are appreciated !

;==============================================================COPY PASTE Install_Script_BE_site.nsi START
;BESITE_INSTALL.nsi
; THIS INSTALLER INSTALLS THE APPLICATION LAYER OF THE BE-Tool
;Company
;date  author
;Purpose: This NSI script packs all the nessessary source files for running the BE site
;in diffent environemnts .
;--------------------------------
!include "FileFunc.nsh"
!include "MUI2.nsh"
!include "WordFunc.nsh"
!include "Time.nsh"
!include "Sections.nsh"
!insertmacro WordFind

 

!insertmacro MUI_LANGUAGE "English"
!define /date MYDATE "%Y%b%d.%H%M%S" ;not really needed but yet
!define SERVER $R0 ;Temp variable for holding the option chosen for server
!define CHOSENSERVER $R9 ;Temp variable for holding the NOTE :

LangString MUI_TEXT_INSTALLING_TITLE ${LANG_ENGLISH} "BE SITE Installation"
LangString MUI_TEXT_INSTALLING_SUBTITLE ${LANG_ENGLISH} "Installing BE SITE"
LangString MUI_TEXT_FINISH_TITLE ${LANG_ENGLISH} "BE SITE Ready"
LangString MUI_TEXT_FINISH_SUBTITLE ${LANG_ENGLISH} "BE SITE Installed"
LangString MUI_TEXT_ABORT_TITLE ${LANG_ENGLISH} "Abort BE SITE Installation ?!"
LangString MUI_TEXT_ABORT_SUBTITLE ${LANG_ENGLISH} "Abort BE SITE Installation ?!"

XPStyle On
AutoCloseWindow false
ShowInstDetails show

;Things that need to be extracted on startup (keep these lines before any File command!)
;Only useful for BZIP2 compression
;Use ReserveFile for your own InstallOptions INI files too!

ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll"
ReserveFile "be_site_conf.ini"

  Name "BE-Tool Application Layer installer for Any Environment"
  ; THIS IS THE SETUP.EXE FILE PRODUCED BY THE SCRIPT
  OutFile "G:\Setup_BE.exe"

 
  InstallDir "D:\SOME_SITE\be_dev"
;Prompt for Vista Admin Rights  
  RequestExecutionLevel admin
 
;--------------------------------

  ;Pages
  ;Order of pages
 Page custom SetCustom ValidateCustom "Choose the right server to install t" ;Custom page.
  Page directory
  Page instfiles
  Page custom CustomPage
 

 
 
  UninstPage uninstConfirm
  UninstPage instfiles

;--------------------------------
; Declaration of user variables (Var command), allowed charaters for variables names : [a-z][A-Z][0-9] and copy_'
Var "Info"
Var "InfoOK"

;--------------------------------
; Installer

 

;**************************************************************************************************
Section "Components"

  ;Get Install Options dialog user input

  ReadINIStr ${SERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 2" "State"
  DetailPrint "Install option=${SERVER}"
  ReadINIStr ${SERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 3" "State"
  DetailPrint "Install option=${SERVER}"
  ReadINIStr ${SERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 4" "State"
  DetailPrint "Install option=${SERVER}"
  ReadINIStr ${SERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 5" "Text"
  DetailPrint "Info=${SERVER}"
 
  DetailPrint "CHOSENSERVER=${CHOSENSERVER}"
SectionEnd
;**************************************************************************************************

Section
;CREATE BACKUP OF THE EXISTING SITE IF ANY

${time::GetLocalTime} $R0
${time::TimeString} "$R0" $0 $1 $2 $3 $4 $5
/*
0 - date
1 - month
2 - year
3 - hour
4 - minute
5 - seconds
*/

;CREATE THE BACKUP DIRECTORY BASED ON THE TIMESTAMP
Rename $INSTDIR "$INSTDIR.$2$1$0.$3$4$5"

 
SectionEnd
;**************************************************************************************************
;**************************************************************************************************

Section "Unpacking" SecDummy

;   MessageBox MB_OK "The installation directory you choosed is $INSTDIR . Press OK to proceed"
    

 
CreateDirectory $INSTDIR
SetOutPath $INSTDIR
; HERE UNZIP ACTUALLY THE FILES (ADD *.js files if needed )
; DO NOT INCLUDE FILES CONTAINING "test"  *.MDF *.ldf
File /r  /x *.MDF /x *.exclude /x *.ldf /x *.pl /x *.nsis /x *.cmd *.cs  *.aspx *.ascx *.aspx.cs *.dll *.xml *.css *.resx *.config *.dll *.pdb *.gif *.jpg *.png *.master *.master.cs *.asax *.txt *.htm *.txt *.sitemap *.js *.ini *.sql
   
SectionEnd
;**************************************************************************************************

;Just an example how one can call external executable
;Section "NsExec"
;nsExec::ExecToLog /OEM /TIMEOUT=4 "C:\Program Files\Opera\Opera.exe" "www.google.fi"
;SectionEnd

;**************************************************************************************************
Section
;FIND OUT WHICH APPLICATION ARE WE INSTALLING
;NOTE THIS ASSUMES INSTALLATION IN THE D:\folder path
;SO LETS ASSUME INSTALLING D:\SOME_SITE\be

StrCpy $R0 "$INSTDIR"
 ${WordFind} $R0 "\" "-02" $R1
DetailPrint "I saw R1  $R1"

WriteUninstaller "$R1\Uninstall_BESITE.exe"
SectionEnd
;$R1=D:
; if D:\SOME_SITE = D: if D:\SOME_SITE\SOME_SITE_dev R1=SOME_SITE

Section
StrCpy $R2 "$INSTDIR"
 ${WordFind} $R2 "\" "-01" $R3
DetailPrint "I saw R3  $R3"
SectionEnd
;$R3=be_dev

Section "SETUPCONNECTION ENVIRONMENT"

;INFORM THE STARTING OF THE COPY
DetailPrint "Setting up the resource file for the server "
;COPY THE SERVER CONFIG FILES FOR THIS APPLICATION
;COPY THE SERVER FILE AS FROM SERVER.FILE TO FILE
;Delete the Web.config file from the development
Delete "$INSTDIR\Web.config"
;server = heitv156lab.devlab.nokia.com
DetailPrint "I saw CHOSENSERVER  ${CHOSENSERVER} Followed by space"
CopyFiles "$INSTDIR\INSTALL\${CHOSENSERVER}.$R3.Web.config" "$INSTDIR\BlogEngine.Web\Web.config"
;${CHOSENSERVER}
;COPY THE App_GlobalResources folder
;Delete the App_GlobalResources from the development
;Delete "$INSTDIR\App_GlobalResources\*.*"
;Copy the server.app.App_GlobalResources to it's correct place
;CopyFiles "$INSTDIR\INSTALL\${CHOSENSERVER}.$R3.App_GlobalResources\*.*" "$INSTDIR\App_GlobalResources\"
;NOW DELETE THE INSTALL DIRECTORY CONTAINING THE DIFFERENT SETUP FILES

;BOOM BOOM BOOM NOT IN PRODUCTION USE !!!!

;COPY THE CONFIG FILES FOR VIEWING INTO THE ADMIN DATA DIRECTORY
;CopyFiles "$INSTDIR\INSTALL\${CHOSENSERVER}.$R3.App_GlobalResources\*.*" "$INSTDIR\admin\DATA\"
;NOW RENAME ALL RESX FILES TO XML EXTENSION
;Rename $INSTDIR\admin\DATA\GV.resx $INSTDIR\admin\DATA\GV.xml
;NOW COPY THE WEB.CONFIG FILE
;CopyFiles "$INSTDIR\INSTALL\${CHOSENSERVER}.$R3.Web.config" "$INSTDIR\admin\DATA\Web.config"
;AND RENAME IT AS A SIMPLE XML FILE SO THAT IT WILL BE VISIBLE
;Rename "$INSTDIR\admin\DATA\Web.config" "$INSTDIR\admin\DATA\Web.config.xml"
;COPY THE VERSION.txt file also
;CopyFiles "$INSTDIR\Version.txt" "$INSTDIR\admin\DATA\"

 

;     Var /GLOBAL "AnotherVar"

;     StrCpy $AnotherVar "test"

SectionEnd

 

;--------------------------------
; Uninstaller

Section "Uninstall"

     StrCpy $Info "BE SITE uninstalled successfully."
     Delete "$R1\Uninst.exe"
     RmDir $INSTDIR

SectionEnd

Function un.OnUninstSuccess

     HideWindow
     MessageBox MB_OK "$Info"
    
FunctionEnd

Function OnInstSuccess

  StrCpy $Info "BE SITE installed !!!"
     HideWindow
     MessageBox MB_OK "$InfoOK"
    
FunctionEnd

;------------------------------------------------------------------------------------
 Function CustomPage
 
   SectionGetFlags ${Section_Name} $R0
   IntOp $R0 $R0 & ${SF_SELECTED}
   IntCmp $R0 ${SF_SELECTED} show
 
   Abort
   show:
FunctionEnd

Function .onInit

  ;Extract InstallOptions files
  ;$PLUGINSDIR will automatically be removed when the installer closes
 
  InitPluginsDir
  File /oname=$PLUGINSDIR\be_site_conf.ini "be_site_conf.ini"
 
FunctionEnd

Function SetCustom

  ;Display the InstallOptions dialog

  Push ${SERVER}

    InstallOptions::dialog "$PLUGINSDIR\be_site_conf.ini"
    Pop ${SERVER}
 
  Pop ${SERVER}

FunctionEnd

Function ValidateCustom

  ReadINIStr ${SERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 2" "State"
 ReadINIStr ${CHOSENSERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 2" "Text"
  StrCmp ${SERVER} 1 done
 
  ReadINIStr ${SERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 3" "State"
  ReadINIStr ${CHOSENSERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 3" "Text"
  StrCmp ${SERVER} 1 done

  ReadINIStr ${SERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 4" "State"
  ReadINIStr ${CHOSENSERVER} "$PLUGINSDIR\be_site_conf.ini" "Field 4" "Text"
  StrCmp ${SERVER} 1 done
    MessageBox MB_ICONEXCLAMATION|MB_OK "You must select at least one install option!"
    Abort

  done:
 
FunctionEnd

  Function .onInstSuccess
        MessageBox MB_OK "BE site installed "
  FunctionEnd

  Function un.onUserAbort
    MessageBox MB_YESNO "Abort uninstall?" IDYES NoCancelAbort
      Abort ; causes uninstaller to not quit.
    NoCancelAbort:
  FunctionEnd

  Function un.onInit
    MessageBox MB_YESNO "This will uninstall. Continue?" IDYES NoAbort
      Abort ; causes uninstaller to quit.
    NoAbort:
  FunctionEnd

;==============================================================COPY PASTE Install_Script_BE_site.nsi


;==============================================================COPY PASTE be_site_conf.ini START
[Settings]
NumFields=5

[Field 1]
Type=GroupBox
Left=0
Right=-1
Top=0
Bottom=-5
Text=" Choose destination server by checking the available options"

[Field 2]
Type=radiobutton
Text=heitv156lab.devlab.nokia.com
Left=10
Right=-10
Top=17
Bottom=25
State=1
Flags=GROUP

[Field 3]
Type=radiobutton
Text=ESTAXWDBQ001
Left=10
Right=-10
Top=30
Bottom=38
State=0
Flags=NOTABSTOP

[Field 4]
Type=radiobutton
Text=ESTAXWDBP001
Left=10
Right=-10
Top=43
Bottom=51
State=0
Flags=NOTABSTOP

[Field 5]
Type=Label
Left=10
Right=-10
Top=90
Bottom=98
Text=Choose at least one server to install the POC site to

;==============================================================COPY PASTE be_site_conf.ini END