A script to install a Tomcat web application

From NSIS Wiki

Author: rkaltenbach (talk, contrib)


Description

I have developed a script to install a file into the 'webapps' directory of the Tomcat server. It installs and uninstalls cleanly. It is included here in case anyone else want to use it.

I know anyone running a Tomcat server should know how to install a web app, but...

The Script

; Sample_install_to_webapps.nsi   RBK 2003.03
;
; This script will install install_test.txt into a directory that the user
;   selects, with the default of webapps in Tomcat directory.
 
Name    "WebappInst"       ; The name of the installation
OutFile "WebappInst.exe"   ; The name of the unistaller file to write
 
; Set prompt text for select components window and select directory window
ComponentText "Select components of 'install_test.txt' to install."
DirText       "Choose the Tomcat web application directory (usually 'webapps')."
 
; Tomcat 4.1 registry key is checked for default install directory name
InstallDirRegKey HKLM "SOFTWARE\Apache Group\Tomcat\4.1" ""
 
; At initialization, ABORT if Tomcat has not already been installed
Function .onInit
  StrCmp $INSTDIR "" 0 Continue  ; IF installation directory string from reg key = null
    MessageBox MB_OK "Tomcat 4.1 is not installed on this system. Installation aborted."
    Abort
  Continue:
  StrCpy $INSTDIR "$INSTDIR\webapps" ; Point installation to the webapps subdirectory
FunctionEnd
 
; Define steps to install install_test.txt
Section "install_test.txt (required)"
 
  SetOutPath $INSTDIR      ; Set output path to the installation directory
  File "install_test.txt"  ; Put file there
 
  ; Write the installation path and uninstall keys into the registry
  WriteRegStr HKLM Software\WebappInst "Install_Dir" $INSTDIR
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WebappInst" \
			"DisplayName" "WebappInst (remove only)"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WebappInst" \
			"UninstallString" '"$INSTDIR\WebappInst_uninstall.exe"'
 
  WriteUninstaller "WebappInst_uninstall.exe"   ; build uninstall program
 
SectionEnd
 
; Define steps to install shortcuts (if selected during installation)
Section "Start Menu Shortcuts"
  CreateDirectory "$SMPROGRAMS\WebappInst"
  CreateShortCut "$SMPROGRAMS\WebappInst\install_test.lnk" "$INSTDIR\install_test.txt"
  CreateShortCut "$SMPROGRAMS\WebappInst\Uninstall.lnk" "$INSTDIR\WebappInst_uninstall.exe" \
			"" "$INSTDIR\WebappInst_uninstall.exe" 0
SectionEnd
 
; Set prompt text for uninstall window
UninstallText "This will uninstall WebappInst. Press 'Uninstall' to continue."
 
; Define steps to unistall everything installed.
Section "Uninstall"
  ; remove registry keys
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\WebappInst"
  DeleteRegKey HKLM SOFTWARE\WebappInst
 
  ; remove files and directories
  Delete $INSTDIR\install_test.txt
  Delete $INSTDIR\WebappInst_uninstall.exe  ; MUST REMOVE UNINSTALLER, too
  Delete "$SMPROGRAMS\WebappInst\*.*"       ; remove shortcuts, if any
  RMDir "$SMPROGRAMS\WebappInst"            ; remove shortcut directory
  RMDir /r "$INSTDIR\install_test"          ; remove webapp dir IF created by Tomcat
SectionEnd
 
; eof

Credits

Cheers,
Randy

Personal tools
donate