; MyCompanyName Federation script. ; Creator : MRagothaman@MyCompanyName ;Compression options ; Please do not change the compressor options, Other compressor do not work with all version of Windows CRCCheck on SetCompressor /SOLID lzma !define AppName "MyCompanyName Federation" !define AppVersion "1.0" !define VersionBuild "100" !define ShortName "MyCompanyName Federation" !define CompanyName "MyCompanyName" Name "MyCompanyName Federation" ;Product information VIAddVersionKey ProductName "MyCompanyName Federation" VIAddVersionKey CompanyName "MyCompanyName" VIAddVersionKey LegalCopyright "Copyright (c) 2013-@YEAR@ MyCompanyName" VIAddVersionKey FileDescription "MyCompanyName Federation Installer" VIAddVersionKey FileVersion "1.0" VIAddVersionKey ProductVersion "1.0" VIAddVersionKey Comments "MyCompanyName Federation" VIAddVersionKey InternalName "federation.exe" VIProductVersion "1.0.0.0" !include "MUI2.nsh" !include "nsDialogs.nsh" !include "StrFunc.nsh" !include "LogicLib.nsh" !include "FileFunc.nsh" !include "WordFunc.nsh" ${StrRep} Var JavaHome Var JavaExe Var JvmDll Var Arch Var ResetInstDir Var TomcatPortShutdown Var TomcatPortHttp Var TomcatMenuEntriesEnable Var TomcatShortcutAllUsers Var TomcatServiceName Var TomcatServiceDefaultName Var TomcatServiceFileName Var TomcatServiceManagerFileName Var TomcatAdminEnable Var TomcatAdminUsername Var TomcatAdminPassword Var TomcatAdminRoles Var TomcatPortAjp InstallDir "$PROGRAMFILES32\${SHORTNAME}" ;Get installation folder from registry if available InstallDirRegKey HKLM "SOFTWARE\${CompanyName}\${ShortName}" "" ;Request application privileges for Windows Vista RequestExecutionLevel Admin ; Variables that store handles of dialog controls Var CtlJavaHome Var CtlTomcatPortShutdown Var CtlTomcatPortHttp Var CtlTomcatServiceName Var CtlTomcatShortcutAllUsers Var CtlTomcatAdminUsername Var CtlTomcatAdminPassword Var CtlTomcatAdminRoles Var CtlTomcatPortAjp ; Handle of the service-install.log file ; It is opened in "Core" section and closed in "-post" Var ServiceInstallLog ;-------------------------------- ;Configuration !define MUI_HEADERIMAGE "" !define MUI_HEADERIMAGE_RIGHT "" !define MUI_FINISHPAGE_RUN "" !define MUI_FINISHPAGE_RUN_FUNCTION "startService" !define MUI_FINISHPAGE_NOREBOOTSUPPORT "" !define MUI_ABORTWARNING "" ;!define JRE_VERSION_6 "1.6" !define JRE_VERSION_7 "1.7" ; How to find the bundleID ?? It took 3 days to figure this non sense ;Get the Latest all time from here http://www.java.com/en/download/manual.jsp !define JRE_URL http://javadl.sun.com/webapps/download/AutoDL?BundleId=83385 ;!define MUI_ICON "C:\Users\bangalik\Downloads\tomcat.ico" ;!define MUI_UNICON "C:\Users\bangalik\Downloads\tomcat.ico" ;General OutFile MyCompanyNameFed-MasterInstaller.exe ;Install Options pages LangString TEXT_JVM_TITLE ${LANG_ENGLISH} "Java Virtual Machine" LangString TEXT_JVM_SUBTITLE ${LANG_ENGLISH} "Java Virtual Machine path selection." LangString TEXT_JVM_PAGETITLE ${LANG_ENGLISH} ": Java Virtual Machine path selection" LangString TEXT_INSTDIR_NOT_EMPTY ${LANG_ENGLISH} "The specified installation directory is not empty. Do you wish to continue?" LangString TEXT_CONF_TITLE ${LANG_ENGLISH} "Configuration" LangString TEXT_CONF_SUBTITLE ${LANG_ENGLISH} "Tomcat basic configuration." LangString TEXT_CONF_PAGETITLE ${LANG_ENGLISH} ": Configuration Options" LangString TEXT_JVM_LABEL1 ${LANG_ENGLISH} "Please select the path of a Java SE 6.0 or later JRE installed on your system." LangString TEXT_CONF_LABEL_PORT_SHUTDOWN ${LANG_ENGLISH} "Server Shutdown Port" LangString TEXT_CONF_LABEL_PORT_HTTP ${LANG_ENGLISH} "HTTP/1.1 Connector Port" LangString TEXT_CONF_LABEL_PORT_AJP ${LANG_ENGLISH} "AJP/1.3 Connector Port" LangString TEXT_CONF_LABEL_SERVICE_NAME ${LANG_ENGLISH} "Windows Service Name" LangString TEXT_CONF_LABEL_SHORTCUT_ALL_USERS ${LANG_ENGLISH} "Create shortcuts for all users" LangString TEXT_CONF_LABEL_ADMIN ${LANG_ENGLISH} "Tomcat Administrator Login (optional)" LangString TEXT_CONF_LABEL_ADMINUSERNAME ${LANG_ENGLISH} "User Name" LangString TEXT_CONF_LABEL_ADMINPASSWORD ${LANG_ENGLISH} "Password" LangString TEXT_CONF_LABEL_ADMINROLES ${LANG_ENGLISH} "Roles" ;Install Page order !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt" !insertmacro MUI_PAGE_DIRECTORY ;!insertmacro MUI_PAGE_COMPONENTS Page custom pageConfiguration pageConfigurationLeave "$(TEXT_CONF_PAGETITLE)" ; Page custom pageChooseJVM pageChooseJVMLeave "$(TEXT_JVM_PAGETITLE)" !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH ;Uninstall Page order !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES ;Component-selection page ;Descriptions LangString DESC_SecTomcat ${LANG_ENGLISH} "Install the Tomcat Servlet container as a Windows service." LangString DESC_SecTomcatCore ${LANG_ENGLISH} "Install the Tomcat Servlet container core and create the Windows service." LangString DESC_SecTomcatService ${LANG_ENGLISH} "Automatically start the Tomcat service when the computer is started." LangString DESC_SecTomcatNative ${LANG_ENGLISH} "Install APR based Tomcat native .dll for better performance and scalability in production environments." LangString DESC_SecMenu ${LANG_ENGLISH} "Create a Start Menu program group for Tomcat." LangString DESC_SecDocs ${LANG_ENGLISH} "Install the Tomcat documentation bundle. This includes documentation on the servlet container and its configuration options, on the Jasper JSP page compiler, as well as on the native webserver connectors." LangString DESC_SecManager ${LANG_ENGLISH} "Install the Tomcat Manager administrative web application." LangString DESC_SecHostManager ${LANG_ENGLISH} "Install the Tomcat Host Manager administrative web application." LangString DESC_SecExamples ${LANG_ENGLISH} "Install the Servlet and JSP examples web application." ;Language !insertmacro MUI_LANGUAGE English ReserveFile "${NSISDIR}\Plugins\System.dll" ReserveFile "${NSISDIR}\Plugins\nsDialogs.dll" ; ReserveFile confinstall\tomcat-users_1.xml ; ReserveFile confinstall\tomcat-users_2.xml ;-------------------------------- ;Installer Sections Section "Federation Service" SecTomcat ;MessageBox MB_OK "Detecting JRE..." ;Call CheckUserType ;Call checkIfInstalled Call GetJRE Call checkJava /* ${If} ${Silent} Call checkJava ${EndIf} */ SetOutPath $INSTDIR ;File C:\Federation\NSiS\apache-tomcat-7.0.47\tomcat.ico ;File LICENSE ; File NOTICE SetOutPath $INSTDIR\lib File /r C:\Federation\NSiS\apache-tomcat-7.0.47\lib\*.* ; Note: just calling 'SetOutPath' will create the empty folders for us SetOutPath $INSTDIR\logs SetOutPath $INSTDIR\work SetOutPath $INSTDIR\temp SetOutPath $INSTDIR\bin SetOutPath $INSTDIR\MyCompanyNamelicense SetOutPath $INSTDIR\maintenancescripts SetOutPath $INSTDIR\troubleshootscripts File C:\Federation\NSiS\apache-tomcat-7.0.47\bin\bootstrap.jar File C:\Federation\NSiS\apache-tomcat-7.0.47\bin\tomcat-juli.jar SetOutPath $INSTDIR\conf ;File C:\Federation\NSiS\apache-tomcat-7.0.47\conf\Catalina\MyCompanyNamefed\*.* SetOutPath $INSTDIR\webapps\ROOT ;File /r webapps\ROOT\*.* Call configure DetailPrint "Using Jvm: $JavaHome" StrCpy $R0 $TomcatServiceName StrCpy $TomcatServiceFileName $R0.exe StrCpy $TomcatServiceManagerFileName $R0w.exe SetOutPath $INSTDIR\bin File C:\Federation\NSiS\apache-tomcat-7.0.47\bin\*.bat File /oname=$TomcatServiceManagerFileName C:\Federation\NSiS\apache-tomcat-7.0.47\bin\tomcat7w.exe ; Get the current platform x86 / AMD64 / IA64 ${If} $Arch == "x86" File /oname=$TomcatServiceFileName C:\Federation\NSiS\apache-tomcat-7.0.47\bin\tomcat7.exe ${ElseIf} $Arch == "x64" File /oname=$TomcatServiceFileName C:\Federation\NSiS\apache-tomcat-7.0.47\bin\tomcat7.exe ${ElseIf} $Arch == "i64" File /oname=$TomcatServiceFileName C:\Federation\NSiS\apache-tomcat-7.0.47\bin\tomcat7.exe ${EndIf} FileOpen $ServiceInstallLog "$INSTDIR\logs\service-install.log" a FileSeek $ServiceInstallLog 0 END InstallRetry: FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //IS//$TomcatServiceName --DisplayName "Apache Tomcat 7.0 $TomcatServiceName" --Description "Apache Tomcat 7.0.35 Server - http://tomcat.apache.org/" --LogPath "$INSTDIR\logs" --Install "$INSTDIR\bin\$TomcatServiceFileName" --Jvm "$JvmDll" --StartPath "$INSTDIR" --StopPath "$INSTDIR"' FileWrite $ServiceInstallLog "$\r$\n" ClearErrors DetailPrint "Installing $TomcatServiceName service" nsExec::ExecToStack '"$INSTDIR\bin\$TomcatServiceFileName" //IS//$TomcatServiceName --DisplayName "Apache Tomcat 7.0 $TomcatServiceName" --Description "Apache Tomcat 7.0.35 Server - http://tomcat.apache.org/" --LogPath "$INSTDIR\logs" --Install "$INSTDIR\bin\$TomcatServiceFileName" --Jvm "$JvmDll" --StartPath "$INSTDIR" --StopPath "$INSTDIR"' Pop $0 Pop $1 StrCmp $0 "0" InstallOk FileWrite $ServiceInstallLog "Install failed: $0 $1$\r$\n" MessageBox MB_ABORTRETRYIGNORE|MB_ICONSTOP \ "Failed to install $TomcatServiceName service.$\r$\nCheck your settings and permissions.$\r$\nIgnore and continue anyway (not recommended)?" \ /SD IDIGNORE IDIGNORE InstallOk IDRETRY InstallRetry Quit InstallOk: ClearErrors ; Will be closed in "-post" section ; FileClose $ServiceInstallLog ${If} $ServiceInstallLog != "" FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --Startup auto' FileWrite $ServiceInstallLog "$\r$\n" ${EndIf} DetailPrint "Configuring $TomcatServiceName service" ; nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --Startup auto' Pop $0 ; returns an errorcode (<>0) otherwise success (0) ClearErrors SectionEnd Section "Federation Tool" SecFederation SetOutPath $INSTDIR\webapps File /r C:\Federation\NSiS\apache-tomcat-7.0.47\webapps\*.* ;AccessControl::GrantOnFile "$INSTDIR\webapps\*" "(S-1-5-32-545)" "ReadControl" SectionEnd Section -post ${If} $ServiceInstallLog != "" FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --Classpath "$INSTDIR\bin\bootstrap.jar;$INSTDIR\bin\tomcat-juli.jar" --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop --StartMode jvm --StopMode jvm' FileWrite $ServiceInstallLog "$\r$\n" FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --JvmOptions "-Dcatalina.home=$INSTDIR#-Dcatalina.base=$INSTDIR#-Djava.endorsed.dirs=$INSTDIR\endorsed#-Djava.io.tmpdir=$INSTDIR\temp#-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager#-Djava.util.logging.config.file=$INSTDIR\conf\logging.properties"' FileWrite $ServiceInstallLog "$\r$\n" FileWrite $ServiceInstallLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --StdOutput auto --StdError auto' FileWrite $ServiceInstallLog "$\r$\n" FileClose $ServiceInstallLog ${EndIf} DetailPrint "Configuring $TomcatServiceName service" nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --Classpath "$INSTDIR\bin\bootstrap.jar;$INSTDIR\bin\tomcat-juli.jar" --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop --StartMode jvm --StopMode jvm' nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --JvmOptions "-Dcatalina.home=$INSTDIR#-Dcatalina.base=$INSTDIR#-Djava.endorsed.dirs=$INSTDIR\endorsed#-Djava.io.tmpdir=$INSTDIR\temp#-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager#-Djava.util.logging.config.file=$INSTDIR\conf\logging.properties"' nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //US//$TomcatServiceName --StdOutput auto --StdError auto' ${If} $TomcatShortcutAllUsers == "1" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor7.0_$TomcatServiceName" '"$INSTDIR\bin\$TomcatServiceManagerFileName" //MS//$TomcatServiceName' ${Else} WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor7.0_$TomcatServiceName" '"$INSTDIR\bin\$TomcatServiceManagerFileName" //MS//$TomcatServiceName' ${EndIf} ;${If} $TomcatMenuEntriesEnable == "1" Call createShortcuts ; ${EndIf} SetRegView 32 WriteUninstaller "$INSTDIR\Uninstall.exe" SetRegView 32 WriteRegStr HKLM "SOFTWARE\Apache Software Foundation\Tomcat\7.0\$TomcatServiceName" "InstallPath" $INSTDIR WriteRegStr HKLM "SOFTWARE\Apache Software Foundation\Tomcat\7.0\$TomcatServiceName" "Version" 7.0.35 WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat 7.0 $TomcatServiceName" \ "DisplayName" "Apache Tomcat 7.0 $TomcatServiceName (remove only)" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat 7.0 $TomcatServiceName" \ "DisplayIcon" "$\"$INSTDIR\tomcat.ico$\"" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat 7.0 $TomcatServiceName" \ "UninstallString" "$\"$INSTDIR\Uninstall.exe$\" -ServiceName=$\"$TomcatServiceName$\"" SectionEnd Function .onInit Call CheckUserType ${GetParameters} $R0 ClearErrors ${GetOptions} "$R0" "/?" $R1 ${IfNot} ${Errors} MessageBox MB_OK|MB_ICONINFORMATION 'Available options:$\r$\n\ /S - Silent install.$\r$\n\ /D=INSTDIR - Specify installation directory.' Abort ${EndIf} ClearErrors ;StrCpy $ResetInstDir "$INSTDIR" ;Initialize default values StrCpy $JavaHome "" StrCpy $TomcatPortShutdown "8005" StrCpy $TomcatPortHttp "8080" StrCpy $TomcatPortAjp "8009" StrCpy $TomcatMenuEntriesEnable "0" StrCpy $TomcatShortcutAllUsers "0" StrCpy $TomcatServiceDefaultName "MyCompanyNameFederation" StrCpy $TomcatServiceName $TomcatServiceDefaultName StrCpy $TomcatServiceFileName "MyCompanyNameFederation.exe" ; StrCpy $TomcatServiceManagerFileName "MyCompanyNameFederationw.exe" StrCpy $TomcatServiceManagerFileName "MyCompanyNameFederation.exe" StrCpy $TomcatAdminEnable "0" StrCpy $TomcatAdminUsername "" StrCpy $TomcatAdminPassword "" StrCpy $TomcatAdminRoles "" Call checkIfInstalled FunctionEnd Function checkIfInstalled ; Check to see if already installed /* SetRegView 64 ;MessageBox MB_OK "user accout type $TomcatServiceName" ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat 7.0 Tomcat7" "UninstallString" StrCmp $R0 "" noTomcat ReadRegStr $INSTDIR HKLM "SOFTWARE\Apache Software Foundation\Tomcat\7.0\$TomcatServiceName" "InstallPath" MessageBox MB_YESNO "${AppName} is already installed. Uninstall the existing version? $INSTDIR" IDYES Uninstall IDNO Quit Uninstall: Exec $INSTDIR\Uninstall.exe Quit: Quit*/ SetRegView 32 ;MessageBox MB_OK "user accout type $TomcatServiceName" ReadRegStr $R0 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat 7.0 MyCompanyNameFederation" "UninstallString" StrCmp $R0 "" noTomcat ReadRegStr $INSTDIR HKLM "SOFTWARE\Apache Software Foundation\Tomcat\7.0\$TomcatServiceName" "InstallPath" MessageBox MB_YESNO "${AppName} is already installed. Uninstall the existing version? $INSTDIR" IDYES Uninstall32 IDNO Quit32 Uninstall32: Exec $INSTDIR\Uninstall.exe Quit32: Quit noTomcat: FunctionEnd ; onLeave function for the COMPONENTS page ; It updates options based on what components were selected. ; Function pageComponentsLeave StrCpy $TomcatAdminEnable "0" StrCpy $TomcatAdminRoles "" StrCpy $TomcatMenuEntriesEnable "0" SectionGetFlags ${SecManager} $0 IntOp $0 $0 & ${SF_SELECTED} ${If} $0 <> 0 StrCpy $TomcatAdminEnable "1" StrCpy $TomcatAdminRoles "manager-gui" ${EndIf} SectionGetFlags ${SecHostManager} $0 IntOp $0 $0 & ${SF_SELECTED} ${If} $0 <> 0 StrCpy $TomcatAdminEnable "1" ${If} $TomcatAdminRoles != "" StrCpy $TomcatAdminRoles "admin-gui,$TomcatAdminRoles" ${Else} StrCpy $TomcatAdminRoles "admin-gui" ${EndIf} ${EndIf} SectionGetFlags ${SecMenu} $0 IntOp $0 $0 & ${SF_SELECTED} ${If} $0 <> 0 StrCpy $TomcatMenuEntriesEnable "1" ${EndIf} FunctionEnd Function pageDirectoryLeave ${DirState} "$INSTDIR" $0 ${If} $0 == 1 ;folder is full. (other values: 0: empty, -1: not found) ;query selection MessageBox MB_OKCANCEL|MB_ICONQUESTION "$(TEXT_INSTDIR_NOT_EMPTY)" /SD IDOK IDCANCEL notok Goto ok notok: Abort ok: ${EndIf} FunctionEnd Function pageConfiguration !insertmacro MUI_HEADER_TEXT "$(TEXT_CONF_TITLE)" "$(TEXT_CONF_SUBTITLE)" nsDialogs::Create 1018 Pop $R0 ${NSD_CreateLabel} 0 2u 100u 14u "$(TEXT_CONF_LABEL_PORT_SHUTDOWN)" Pop $R0 ${NSD_CreateText} 150u 0 50u 12u "$TomcatPortShutdown" Pop $CtlTomcatPortShutdown ${NSD_SetTextLimit} $CtlTomcatPortShutdown 5 ${NSD_CreateLabel} 0 19u 100u 14u "$(TEXT_CONF_LABEL_PORT_HTTP)" Pop $R0 ${NSD_CreateText} 150u 17u 50u 12u "$TomcatPortHttp" Pop $CtlTomcatPortHttp ${NSD_SetTextLimit} $CtlTomcatPortHttp 5 ${NSD_CreateLabel} 0 36u 100u 14u "$(TEXT_CONF_LABEL_PORT_AJP)" Pop $R0 ${NSD_CreateText} 150u 34u 50u 12u "$TomcatPortAjp" Pop $CtlTomcatPortAjp ${NSD_SetTextLimit} $CtlTomcatPortAjp 5 ${NSD_CreateCheckBox} 0 150u 100% 14u "Update Property Files" pop $1 ${IfThen} $InstallType == DEMO ${|} ${NSD_Check} $1 ${|} nsDialogs::Show ${If} $TomcatMenuEntriesEnable == "1" ${NSD_CreateLabel} 0 75u 100u 14u "$(TEXT_CONF_LABEL_SHORTCUT_ALL_USERS)" Pop $R0 ${NSD_CreateCheckBox} 150u 74u 10u 10u "$TomcatShortcutAllUsers" Pop $CtlTomcatShortcutAllUsers ${EndIf} ${If} $TomcatAdminEnable == "1" ${NSD_CreateLabel} 0 93u 90u 28u "$(TEXT_CONF_LABEL_ADMIN)" Pop $R0 ${NSD_CreateLabel} 100u 93u 40u 14u "$(TEXT_CONF_LABEL_ADMINUSERNAME)" Pop $R0 ${NSD_CreateText} 150u 91u 110u 12u "$TomcatAdminUsername" Pop $CtlTomcatAdminUsername ${NSD_CreateLabel} 100u 110u 40u 12u "$(TEXT_CONF_LABEL_ADMINPASSWORD)" Pop $R0 ${NSD_CreatePassword} 150u 108u 110u 12u "$TomcatAdminPassword" Pop $CtlTomcatAdminPassword ${NSD_CreateLabel} 100u 127u 40u 14u "$(TEXT_CONF_LABEL_ADMINROLES)" Pop $R0 ${NSD_CreateText} 150u 125u 110u 12u "$TomcatAdminRoles" Pop $CtlTomcatAdminRoles ${EndIf} ${NSD_SetFocus} $CtlTomcatPortShutdown nsDialogs::Show FunctionEnd Function pageConfigurationLeave ${NSD_GetText} $CtlTomcatPortShutdown $TomcatPortShutdown ${NSD_GetText} $CtlTomcatPortHttp $TomcatPortHttp ${NSD_GetText} $CtlTomcatPortAjp $TomcatPortAjp ${If} $TomcatMenuEntriesEnable == "1" ${NSD_GetState} $CtlTomcatShortcutAllUsers $TomcatShortcutAllUsers ${EndIf} ${If} $TomcatAdminEnable == "1" ${NSD_GetText} $CtlTomcatAdminUsername $TomcatAdminUsername ${NSD_GetText} $CtlTomcatAdminPassword $TomcatAdminPassword ${NSD_GetText} $CtlTomcatAdminRoles $TomcatAdminRoles ${EndIf} ${If} $TomcatPortShutdown == "" MessageBox MB_ICONEXCLAMATION|MB_OK 'The shutdown port may not be empty' Abort "Config not right" Goto exit ${EndIf} ${If} $TomcatPortHttp == "" MessageBox MB_ICONEXCLAMATION|MB_OK 'The HTTP port may not be empty' Abort "Config not right" Goto exit ${EndIf} ${If} $TomcatPortAjp == "" MessageBox MB_ICONEXCLAMATION|MB_OK 'The AJP port may not be empty' Abort "Config not right" Goto exit ${EndIf} ${If} $TomcatServiceName == "" MessageBox MB_ICONEXCLAMATION|MB_OK 'The Service Name may not be empty' Abort "Config not right" Goto exit ${EndIf} Push $TomcatServiceName Call validateServiceName Pop $0 IntCmp $0 1 exit MessageBox MB_ICONEXCLAMATION|MB_OK 'The Service Name may not contain a space or any of the following characters: <>:"/\:|?*' Abort "Config not right" exit: FunctionEnd ; Validates that a service name does not use any of the invalid ; characters: <>:"/\:|?* ; Note that space is also not permitted although it will be once ; Tomcat is using Daemon 1.0.6 or later ; ; Put the proposed service name on the stack ; If the name is valid, a 1 will be left on the stack ; If the name is invalid, a 0 will be left on the stack Function validateServiceName Pop $0 StrLen $1 $0 StrCpy $3 '<>:"/\:|?* ' StrLen $4 $3 loopInput: IntOp $1 $1 - 1 IntCmp $1 -1 valid loopTestChars: IntOp $4 $4 - 1 IntCmp $4 -1 loopTestCharsDone StrCpy $2 $0 1 $1 StrCpy $5 $3 1 $4 StrCmp $2 $5 invalid loopTestChars loopTestCharsDone: StrLen $4 $3 Goto loopInput invalid: Push 0 Goto exit valid: Push 1 exit: FunctionEnd ;-------------------------------- ;Descriptions !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SecTomcat} $(DESC_SecTomcat) !insertmacro MUI_DESCRIPTION_TEXT ${SecTomcatCore} $(DESC_SecTomcatCore) !insertmacro MUI_DESCRIPTION_TEXT ${SecTomcatService} $(DESC_SecTomcatService) !insertmacro MUI_DESCRIPTION_TEXT ${SecTomcatNative} $(DESC_SecTomcatNative) !insertmacro MUI_DESCRIPTION_TEXT ${SecMenu} $(DESC_SecMenu) !insertmacro MUI_DESCRIPTION_TEXT ${SecDocs} $(DESC_SecDocs) !insertmacro MUI_DESCRIPTION_TEXT ${SecManager} $(DESC_SecManager) !insertmacro MUI_DESCRIPTION_TEXT ${SecHostManager} $(DESC_SecHostManager) !insertmacro MUI_DESCRIPTION_TEXT ${SecExamples} $(DESC_SecExamples) !insertmacro MUI_FUNCTION_DESCRIPTION_END ; ===================== ; CheckUserType Function ; ===================== ; ; Check the user type, and warn if it's not an administrator. ; Taken from Examples/UserInfo that ships with NSIS. Function CheckUserType UserInfo::GetAccountType Pop $0 ${If} $0 != "admin" ;Require admin rights on NT4+ MessageBox mb_iconstop "The Logged In User Is Not Administrator!" SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED Quit ${EndIf} ;MessageBox MB_OK "user accout type $0" FunctionEnd ; DetectJRE ; Inputs: Minimum JRE version requested on stack (this value will be overwritten) ; Outputs: Returns two values on the stack: ; First value (rv0): 0 - JRE not found. -1 - JRE found but too old. OK - JRE found and meets version criteria ; Second value (rv1): Problem description. Otherwise - Path to the java runtime (javaw.exe will be at .\bin\java.exe relative to this path) Function DetectJRE ; MessageBox MB_OK "Detecting 64 bit JRE..." Exch $0 ; Get version requested ; Now the previous value of $0 is on the stack, and the asked for version of JDK is in $0 Push $1 ; $1 = Java version string (ie 1.5.0) Push $2 ; $2 = Javahome Push $3 ; $3 = holds the version comparison result ; stack is now: r3, r2, r1, r0 ; first, check for an installed JRE SetRegView 32 ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" StrCmp $1 "" DetectTry2 ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$1" "JavaHome" StrCmp $2 "" DetectTry2 Goto GetJRE DetectTry2: ; next, check for an installed JDK SetRegView 32 ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion" StrCmp $1 "" NoFound ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$1" "JavaHome" StrCmp $2 "" NoFound GetJRE: ; ok, we found a JRE, let's compare it's version and make sure it is new enough ; $0 = version requested. $1 = version found. $2 = javaHome IfFileExists "$2\bin\java.exe" 0 NoFound ${VersionCompare} ${JRE_VERSION_7} $1 $3 ; $3 now contains the result of the comparison DetailPrint "Comparing version $0 to $1 results in $3" IntCmp $3 1 FoundOld IntCmp $3 2 FoundNew IntCmp $3 0 FoundNew NoFound: DetailPrint "No JRE found" strcpy $0 "0" strcpy $1 "No JRE Found" Goto DetectJREEnd FoundOld: DetailPrint "An old JRE was found" strcpy $0 "-1" strcpy $1 "Old JRE found" Goto DetectJREEnd FoundNew: DetailPrint "A suitable JRE was found" strcpy $0 "OK" strcpy $1 $2 Goto DetectJREEnd DetectJREEnd: ; at this stage, $0 contains rv0, $1 contains rv1 ; now, straighten the stack out and recover original values for r0, r1, r2 and r3 ; there are two return values: rv0 = -1, 0, OK and rv1 = JRE path or problem description ; stack looks like this: ; r3,r2,r1,r0 Pop $3 ; => r2,r1,r0 Pop $2 ; => r1,r0 Push $0 ; => rv0, r1, r0 Exch 2 ; => r0, r1, rv0 Push $1 ; => rv1, r0, r1, rv0 Exch 2 ; => r1, r0, rv1, rv0 Pop $1 ; => r0, rv1, rv0 Pop $0 ; => rv1, rv0 Exch ; => rv0, rv1 FunctionEnd Function GetJRE DetailPrint "Detecting JRE Version" Push "${JRE_VERSION_7}" Call DetectJRE Pop $0 ; Get return value from stack Pop $1 ; get JRE path (or error message) MessageBox MB_OK "JRE Version detection complete - $1" strcmp $0 "OK" End downloadJRE downloadJRE: MessageBox MB_OK "${AppName} uses Java ${JRE_VERSION_7} or higher, which cannot be found in the current machine, it will now be downloaded and installed" DetailPrint "About to download JRE from ${JRE_URL}" Inetc::get "${JRE_URL}" "$TEMP\jre_Setup.exe" /END Pop $0 # return value = exit code, "OK" if OK DetailPrint "Download result = $0" strcmp $0 "OK" downloadsuccessful MessageBox MB_OK "There was a problem downloading required component - Error: $0" abort downloadsuccessful: DetailPrint "Launching JRE setup" IfSilent doSilent ExecWait '"$TEMP\jre_setup.exe" /passive REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0 /L \"$TEMP\jre_setup.log\"' $0 goto jreSetupfinished doSilent: ExecWait '"$TEMP\jre_setup.exe" /S REBOOT=Suppress JAVAUPDATE=0 WEBSTARTICON=0 /L \"$TEMP\jre_setup.log\"' $0 jreSetupFinished: DetailPrint "JRE Setup finished" Delete "$TEMP\jre_setup.exe" StrCmp $0 "0" InstallVerif 0 Push "The JRE setup has been abnormally interrupted - return code $0" MessageBox MB_OK "There was a problem In Installing -----------> - Error: $0" Goto ExitInstallJRE InstallVerif: DetailPrint "Checking the JRE Setup's outcome" Push "${JRE_VERSION_7}" Call DetectJRE Pop $0 ; DetectJRE's return value Pop $1 ; JRE home (or error message if compatible JRE could not be found) DetailPrint "A suitable JRE was returned $0 $1" StrCmp $0 "OK" 0 JavaVerStillWrong Goto JREPathStorage JavaVerStillWrong: Push "Unable to find JRE with version above ${JRE_VERSION_7}, even though the JRE setup was successful$\n$\n$1" Goto ExitInstallJRE JREPathStorage: DetailPrint "JRE PATH Storage block" /* Push $0 ; => rv, r1, r0 Exch 2 ; => r0, r1, rv Exch ; => r1, r0, rv */ DetailPrint "JRE PATH Storage endofblock" Goto End ExitInstallJRE: Pop $1 MessageBox MB_OK "Unable to install Java - Setup will be aborted$\n$\n$1" Pop $1 ; Restore $1 Pop $0 ; Restore $0 Abort End: DetailPrint "END" Pop $1 ; Restore $1 Pop $0 ; Restore $0 DetailPrint "END end" FunctionEnd ; ================== ; checkJava Function ; ================== ; ; Checks that a valid JVM has been specified or a suitable default is available ; Sets $JavaHome, $JavaExe and $JvmDll accordingly ; Determines if the JVM is 32-bit or 64-bit and sets $Arch accordingly. For ; 64-bit JVMs, also determines if it is x64 or ia64 Function checkJava ;MessageBox MB_OK "Check Java Home... $JavaHome" ${If} $JavaHome == "" ; E.g. if a silent install Call findJavaHome Pop $JavaHome ${EndIf} ${If} $JavaHome == "" ${OrIfNot} ${FileExists} "$JavaHome\bin\java.exe" IfSilent +2 MessageBox MB_OK|MB_ICONSTOP "No Java Virtual Machine found in folder:$\r$\n$JavaHome" DetailPrint "No Java Virtual Machine found in folder:$\r$\n$JavaHome" Quit ${EndIf} StrCpy "$JavaExe" "$JavaHome\bin\java.exe" ; Need path to jvm.dll to configure the service - uses $JavaHome Call findJVMPath Pop $5 ${If} $5 == "" IfSilent +2 MessageBox MB_OK|MB_ICONSTOP "No Java Virtual Machine found in folder:$\r$\n$5" DetailPrint "No Java Virtual Machine found in folder:$\r$\n$5" Quit ${EndIf} StrCpy "$JvmDll" $5 ; Read PE header of JvmDll to check for architecture ; 1. Jump to 0x3c and read offset of PE header ; 2. Jump to offset. Read PE header signature. It must be 'PE'\0\0 (50 45 00 00). ; 3. The next word gives the machine type. ; 0x014c: x86 ; 0x8664: x64 ; 0x0200: i64 ClearErrors FileOpen $R1 "$JvmDll" r IfErrors WrongPEHeader FileSeek $R1 0x3c SET FileReadByte $R1 $R2 FileReadByte $R1 $R3 IntOp $R3 $R3 << 8 IntOp $R2 $R2 + $R3 FileSeek $R1 $R2 SET FileReadByte $R1 $R2 IntCmp $R2 0x50 +1 WrongPEHeader WrongPEHeader FileReadByte $R1 $R2 IntCmp $R2 0x45 +1 WrongPEHeader WrongPEHeader FileReadByte $R1 $R2 IntCmp $R2 0 +1 WrongPEHeader WrongPEHeader FileReadByte $R1 $R2 IntCmp $R2 0 +1 WrongPEHeader WrongPEHeader FileReadByte $R1 $R2 FileReadByte $R1 $R3 IntOp $R3 $R3 << 8 IntOp $R2 $R2 + $R3 IntCmp $R2 0x014c +1 +3 +3 StrCpy "$Arch" "x86" Goto DonePEHeader IntCmp $R2 0x8664 +1 +3 +3 StrCpy "$Arch" "x64" Goto DonePEHeader IntCmp $R2 0x0200 +1 +3 +3 StrCpy "$Arch" "i64" Goto DonePEHeader WrongPEHeader: IfSilent +2 MessageBox MB_OK|MB_ICONEXCLAMATION 'Cannot read PE header from "$JvmDll"$\r$\nWill assume that the architecture is x86.' DetailPrint 'Cannot read PE header from "$JvmDll". Assuming the architecture is x86.' StrCpy "$Arch" "x86" DonePEHeader: FileClose $R1 DetailPrint 'Architecture: "$Arch"' ; StrCpy $INSTDIR "$ResetInstDir" ; The default varies depending on 32-bit or 64-bit ${If} "$INSTDIR" == "" ${If} $Arch == "x86" ${If} $TomcatServiceName == $TomcatServiceDefaultName StrCpy $INSTDIR "$PROGRAMFILES\Apache Software Foundation\Tomcat 7.0" ${Else} StrCpy $INSTDIR "$PROGRAMFILES\Apache Software Foundation\Tomcat 7.0_$TomcatServiceName" ${EndIf} ${EndIf} ${If} $Arch == "x64" ${If} $TomcatServiceName == $TomcatServiceDefaultName StrCpy $INSTDIR "$PROGRAMFILES64\Apache Software Foundation\Tomcat 7.0" ${Else} StrCpy $INSTDIR "$PROGRAMFILES64\Apache Software Foundation\Tomcat 7.0_$TomcatServiceName" ${EndIf} ${EndIf} ${EndIf} FunctionEnd ; ===================== ; findJavaHome Function ; ===================== ; ; Find the JAVA_HOME used on the system, and put the result on the top of the ; stack ; Will return an empty string if the path cannot be determined ; Function findJavaHome ClearErrors StrCpy $1 "" ; Use the 64-bit registry first on 64-bit machines ExpandEnvStrings $0 "%PROGRAMW6432%" /* ${If} $0 != "%PROGRAMW6432%" SetRegView 64 ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "JavaHome" ReadRegStr $3 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "RuntimeLib" IfErrors 0 +2 StrCpy $1 "" ClearErrors ${EndIf}*/ ; If no 64-bit Java was found, look for 32-bit Java ${If} $1 == "" SetRegView 32 ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "JavaHome" ReadRegStr $3 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$2" "RuntimeLib" IfErrors 0 +2 StrCpy $1 "" ClearErrors ; If using 64-bit, go back to using 64-bit registry /* ${If} $0 != "%PROGRAMW6432%" SetRegView 64 ${EndIf}*/ ${EndIf} ; Put the result in the stack Push $1 FunctionEnd ; ==================== ; FindJVMPath Function ; ==================== ; ; Find the full JVM path, and put the result on top of the stack ; Implicit argument: $JavaHome ; Will return an empty string if the path cannot be determined ; Function findJVMPath ClearErrors ;Step one: Is this a JRE path (Program Files\Java\XXX) StrCpy $1 "$JavaHome" StrCpy $2 "$1\bin\hotspot\jvm.dll" IfFileExists "$2" FoundJvmDll StrCpy $2 "$1\bin\server\jvm.dll" IfFileExists "$2" FoundJvmDll StrCpy $2 "$1\bin\client\jvm.dll" IfFileExists "$2" FoundJvmDll StrCpy $2 "$1\bin\classic\jvm.dll" IfFileExists "$2" FoundJvmDll ;Step two: Is this a JDK path (Program Files\XXX\jre) StrCpy $1 "$JavaHome\jre" StrCpy $2 "$1\bin\hotspot\jvm.dll" IfFileExists "$2" FoundJvmDll StrCpy $2 "$1\bin\server\jvm.dll" IfFileExists "$2" FoundJvmDll StrCpy $2 "$1\bin\client\jvm.dll" IfFileExists "$2" FoundJvmDll StrCpy $2 "$1\bin\classic\jvm.dll" IfFileExists "$2" FoundJvmDll ClearErrors ;Step tree: Read defaults from registry ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$1" "RuntimeLib" IfErrors 0 FoundJvmDll StrCpy $2 "" FoundJvmDll: ClearErrors ; Put the result in the stack Push $2 FunctionEnd ; ================== ; Configure Function ; ================== ; ; Display the configuration dialog boxes, read the values entered by the user, ; and build the configuration files ; Function configure ; Build final server.xml DetailPrint "Creating server.xml.new" FileOpen $R1 "$INSTDIR\conf\server.xml" r FileOpen $R2 "$INSTDIR\conf\server.xml.new" w SERVER_XML_LOOP: FileRead $R1 $R3 IfErrors SERVER_XML_LEAVELOOP ${StrRep} $R4 $R3 "8005" "$TomcatPortShutdown" ${StrRep} $R3 $R4 "8080" "$TomcatPortHttp" ${StrRep} $R4 $R3 "8009" "$TomcatPortAjp" FileWrite $R2 $R4 Goto SERVER_XML_LOOP SERVER_XML_LEAVELOOP: FileClose $R1 FileClose $R2 ; Replace server.xml with server.xml.new Delete "$INSTDIR\conf\server.xml" FileOpen $R9 "$INSTDIR\conf\server.xml" w Push "$INSTDIR\conf\server.xml.new" Call copyFile FileClose $R9 Delete "$INSTDIR\conf\server.xml.new" DetailPrint 'Server shutdown listener configured on port "$TomcatPortShutdown"' DetailPrint 'HTTP/1.1 Connector configured on port "$TomcatPortHttp"' DetailPrint 'AJP/1.3 Connector configured on port "$TomcatPortAjp"' DetailPrint "server.xml written" FunctionEnd Function xmlEscape Pop $0 ${StrRep} $0 $0 "&" "&" ${StrRep} $0 $0 "$\"" """ ${StrRep} $0 $0 "<" "<" ${StrRep} $0 $0 ">" ">" Push $0 FunctionEnd ; ================= ; CopyFile Function ; ================= ; ; Copy specified file contents to $R9 ; Function copyFile ClearErrors Pop $0 FileOpen $1 $0 r NoError: FileRead $1 $2 IfErrors EOF 0 FileWrite $R9 $2 IfErrors 0 NoError EOF: FileClose $1 ClearErrors FunctionEnd !Macro "CreateURL" "URLFile" "URLSite" "URLDesc" WriteINIStr "$INSTDIR\${URLFile}.URL" "InternetShortcut" "URL" "${URLSite}" SetShellVarContext "all" CreateShortCut "$DESKTOP\${URLFile}.lnk" "$INSTDIR\${URLFile}.URL" \ "$INSTDIR\makeURL.exe" "$INSTDIR\tomcat.ico" 0 "SW_SHOWNORMAL" "" "${URLDesc}" !macroend ; ================= ; createShortcuts Function ; ================= Function createShortcuts DetailPrint "Creating Desktop Shortcut Link" ;!insertmacro "CreateURL" "MyCompanyNameFedGateway" "http://localhost:$TomcatPortHttp/Federation" "" FunctionEnd ; ================= ; startService Function ; ; Using a function allows the service name to be varied ; ================= Function startService ExpandEnvStrings $0 %COMSPEC% nsExec::ExecToStack '"$INSTDIR\bin\tomcat7.exe"' ; nsExec::Exec "" /C "$INSTDIR\bin\startup.bat" "//MR//$TomcatServiceName" FunctionEnd ;-------------------------------- ;Uninstaller Section Section Uninstall StrCpy $TomcatServiceName "MyCompanyNameFederation" StrCpy $TomcatServiceFileName "MyCompanyNameFederation.exe" StrCpy $TomcatServiceManagerFileName "MyCompanyNameFederationw.exe" ${If} $TomcatServiceName == "" MessageBox MB_ICONSTOP|MB_OK \ "No service name specified to uninstall. This will be provided automatically if you uninstall via \ Add/Remove Programs or the shortcut on the Start menu. Alternatively, call the installer from \ the command line with -ServiceName=$\"$\"." Quit ${EndIf} Delete "$INSTDIR\Uninstall.exe" ; Stop Tomcat service monitor if running DetailPrint "Stopping $TomcatServiceName service monitor" nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceManagerFileName" //MQ//$TomcatServiceName' ; Delete Tomcat service DetailPrint "Uninstalling $TomcatServiceName service" nsExec::ExecToLog '"$INSTDIR\bin\$TomcatServiceFileName" //DS//$TomcatServiceName' ClearErrors ; Don't know if 32-bit or 64-bit registry was used so, for now, remove both SetRegView 32 DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Apache Tomcat 7.0 $TomcatServiceName" DeleteRegKey HKLM "SOFTWARE\Apache Software Foundation\Tomcat\7.0\$TomcatServiceName" DeleteRegValue HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor7.0_$TomcatServiceName" DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "ApacheTomcatMonitor7.0_$TomcatServiceName" ; Don't know if short-cuts were created for all users, one user or not at all so, for now, remove both SetShellVarContext all RMDir /r "$SMPROGRAMS\Apache Tomcat 7.0 $TomcatServiceName" SetShellVarContext current RMDir /r "$SMPROGRAMS\Apache Tomcat 7.0 $TomcatServiceName" Delete "$INSTDIR\tomcat.ico" Delete "$INSTDIR\LICENSE" Delete "$INSTDIR\NOTICE" RMDir /r "$INSTDIR\bin" RMDir /r "$INSTDIR\lib" Delete "$INSTDIR\conf\*.dtd" RMDir "$INSTDIR\logs" RMDir /r "$INSTDIR\webapps\docs" RMDir /r "$INSTDIR\webapps\examples" RMDir /r "$INSTDIR\work" RMDir /r "$INSTDIR\temp" RMDir "$INSTDIR" Delete "$DESKTOP\MyCompanyNameFedGateway.lnk" IfSilent Removed 0 ; if $INSTDIR was removed, skip these next ones IfFileExists "$INSTDIR" 0 Removed MessageBox MB_YESNO|MB_ICONQUESTION \ "Remove all files in your Apache Tomcat 7.0 $TomcatServiceName directory? (If you have anything \ you created that you want to keep, click No)" IDNO Removed ; these would be skipped if the user hits no RMDir /r "$INSTDIR\webapps" RMDir /r "$INSTDIR\logs" RMDir /r "$INSTDIR\conf" Delete "$INSTDIR\*.*" RMDir /r "$INSTDIR" Sleep 500 IfFileExists "$INSTDIR" 0 Removed MessageBox MB_OK|MB_ICONEXCLAMATION \ "Note: $INSTDIR could not be removed." Removed: SectionEnd ; ================= ; uninstall init function ; ; Read the command line paramater and set up the service name variables so the ; uninstaller knows which service it is working with ; ================= Function un.onInit ${GetParameters} $R0 ${GetOptions} $R0 "-ServiceName=" $R1 StrCpy $TomcatServiceName "MyCompanyNameFederation" StrCpy $TomcatServiceFileName $R1.exe StrCpy $TomcatServiceManagerFileName $R1w.exe FunctionEnd ;eof