; ; $Id$ ; ; (c)2015-2016 The clazzes.org project. ; ; NSIS Installation Script for the osgi-runner service. ; ; Author: Wolfgang Glas ; ; HM NIS Edit Wizard helper defines !define PRODUCT_NAME "@PROJECT_NAME@" !define PRODUCT_VERSION "@PROJECT_VERSION@" !define PRODUCT_PUBLISHER "The Clazzes.org Project" !define PRODUCT_WEB_SITE "http://www.clazzes.org" !define PRODUCT_PATH_REGKEY "Software\osgi-runner" !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\osgi-runner.exe" !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" !define PRODUCT_UNINST_ROOT_KEY "HKLM" !define ARCHITECTURE "@ARCHITECTURE@" !define BINDIR "/usr/@ARCHTRIPLET@/bin" Unicode true ; Use LZMA compression, because nsis-2.46-1 as of ubuntu lucid fails to compress ; osgi-3.5.1.v20090827.jar, see https://bugs.launchpad.net/bugs/585442 SetCompressor LZMA SetCompressorDictSize 32 SetCompress Auto SetDatablockOptimize On ; MUI 1.67 compatible ------ !include "MUI.nsh" !include "TextFunc.nsh" !include "WordFunc.nsh" !include "Sections.nsh" !insertmacro LineFind !insertmacro WordReplace ; MUI Settings !define MUI_ABORTWARNING !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico" !define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" ; Language Selection Dialog Settings !define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}" !define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}" !define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language" ; Welcome page !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_COMPONENTS !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH ; Uninstaller pages !insertmacro MUI_UNPAGE_INSTFILES ; Language files !insertmacro MUI_LANGUAGE "English" ; MUI end ------ Name "${PRODUCT_NAME} ${PRODUCT_VERSION}" OutFile "${PRODUCT_NAME}-${PRODUCT_VERSION}-setup-${ARCHITECTURE}.exe" InstallDir "$@PROGRAMFILES@\osgi-runner" ShowInstDetails show ShowUnInstDetails show var INSTMODE var LOGGING var JAVA_HOME var JAVA_VERSION Section "-OSGi Runner" SEC00 SetOutPath "$INSTDIR" File /oname=osgi-runner.exe "@ARCH_DIST_SUBDIR@prunsrv.exe" File /oname=osgi-runnerw.exe "prunmgr.exe" File "../InstallOsgiService.bat" File "../UninstallOsgiService.bat" File "../MigrateKeysProperties.bat" CreateShortCut "$INSTDIR\tail-osgi-log.lnk" powershell.exe `-command "& '.\ps1\tail-osgi-log.ps1'"` CreateShortCut "$INSTDIR\osgi-shell.lnk" powershell.exe `-command "& '.\ps1\osgi-shell.ps1'"` SetOutPath "$INSTDIR\ps1" File /r "@DIST_DIR@/win32/ps1/*.ps1" SetOutPath "$INSTDIR\lib" File /r "@DIST_DIR@/downloads/lib/*" SetOutPath "$INSTDIR\bundle1" File /r "@DIST_DIR@/downloads/bundle1/*" SetOutPath "$INSTDIR\bundle2" File /r "@DIST_DIR@/downloads/bundle2/pax-logging-api-*.jar" SetOutPath "$INSTDIR\bundle3" File /r "@DIST_DIR@/downloads/bundle3/*" SetOutPath "$INSTDIR\bundle4" File /r "@DIST_DIR@/downloads/bundle4/*" SetOutPath "$INSTDIR\bundle5" File /r "@DIST_DIR@/downloads/bundle5/*" ; ; Do not overwrite configuration files, which have not been deleted. ; Install changed config files as *.new and print a remark. ; SetOutPath "$INSTDIR\etc" !include "./install-config.nsi" SetOutPath "$INSTDIR\log" File "../README" SetOutPath "$INSTDIR\cache" File "../README" SetOutPath "$INSTDIR\var" File "../README" SetOutPath "$INSTDIR\deploy" File "../README" SetOutPath "$INSTDIR\drivers" File "../README-DRIVERS" SetOutPath "$INSTDIR\java" File "./Aes256Test.class" SetOutPath "$INSTDIR\java\java8" File "@DIST_DIR@/java/java8/local_policy.jar" SetOutPath "$INSTDIR\etc\sshd.d" File "../README-SSHD" WriteRegStr HKLM "${PRODUCT_PATH_REGKEY}" "instdir" "$INSTDIR" WriteRegStr HKLM "${PRODUCT_PATH_REGKEY}" "logging" "$LOGGING" IfFileExists "$INSTDIR\etc\karaf.d" 0 install_service IfFileExists "$INSTDIR\etc\karaf.d\host.key" 0 +2 Rename "$INSTDIR\etc\karaf.d\host.key" "$INSTDIR\etc\sshd.d\host.key" IfFileExists "$INSTDIR\etc\karaf.d\keys.properties" 0 +2 ExecWait '"$INSTDIR\MigrateKeysProperties.bat" "$JAVA_HOME"' Rename "$INSTDIR\etc\karaf.d" "$INSTDIR\etc\karaf.d.save" install_service: ExecWait '"$INSTDIR\InstallOsgiService.bat" auto' SectionEnd Section "log4j logging (traditional)" SEC01 SetOutPath "$INSTDIR\bundle2" File /r "@DIST_DIR@/downloads/bundle2-log4j/pax-logging-log4j1-*.jar" ; ; Do not overwrite configuration files, which have not been deleted. ; Install changed config files as *.new and print a remark. ; SetOutPath "$INSTDIR\etc" !include "./install-config-log4j.nsi" SectionEnd Section "log4j2 logging (new generation)" SEC02 SetOutPath "$INSTDIR\bundle2" File /r "@DIST_DIR@/downloads/bundle2-log4j2/pax-logging-log4j2-*.jar" File /r "@DIST_DIR@/downloads/bundle2-logstash/pax-logstash-plugin-*.jar" ; ; Do not overwrite configuration files, which have not been deleted. ; Install changed config files as *.new and print a remark. ; SetOutPath "$INSTDIR\etc" !include "./install-config-log4j2.nsi" SectionEnd Function .onInit SetRegView @REGVIEW@ !insertmacro MUI_LANGDLL_DISPLAY StrCpy $JAVA_VERSION "8" ReadRegStr $JAVA_HOME HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\1.8" "JavaHome" IfErrors 0 JRE17Found StrCpy $JAVA_VERSION "11" ReadRegStr $JAVA_HOME HKLM "SOFTWARE\JavaSoft\JRE\11" "JavaHome" IfErrors 0 JRE17Found StrCpy $JAVA_VERSION "8" ReadRegStr $JAVA_HOME HKLM "SOFTWARE\JavaSoft\Java Development Kit\1.8" "JavaHome" IfErrors 0 JRE17Found StrCpy $JAVA_VERSION "11" ReadRegStr $JAVA_HOME HKLM "SOFTWARE\JavaSoft\JDK\11" "JavaHome" IfErrors 0 JRE17Found MessageBox MB_OK "Couldn't find a Java Runtime 11 or 1.8 installed. Setup will exit now." Quit JRE17Found: ReadRegStr $LOGGING HKLM "${PRODUCT_PATH_REGKEY}" "logging" IfErrors log4jlogging StrCmp $LOGGING "log4j2" log4j2logging log4jlogging: StrCpy $LOGGING "log4j" SectionGetFlags ${SEC01} $0 IntOp $0 $0 | ${SF_SELECTED} SectionSetFlags ${SEC01} $0 SectionGetFlags ${SEC02} $0 IntOp $0 $0 & ${SECTION_OFF} SectionSetFlags ${SEC02} $0 goto goon log4j2logging: SectionGetFlags ${SEC01} $0 IntOp $0 $0 & ${SECTION_OFF} SectionSetFlags ${SEC01} $0 SectionGetFlags ${SEC02} $0 IntOp $0 $0 | ${SF_SELECTED} SectionSetFlags ${SEC02} $0 goon: ; osgi-runner already installed ? ReadRegStr $0 ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" IfErrors fromscratch 0 MessageBox MB_OKCANCEL "There is another version of osgi-runner currently installed. Run Uninstaller $0 now?" IDOK +2 IDCANCEL +1 Abort "Installation aborted by the user." ReadRegStr $INSTDIR HKLM "${PRODUCT_PATH_REGKEY}" "instdir" ExecWait '$0 _?=$INSTDIR' StrCpy $INSTMODE "update" goto goon2 fromscratch: StrCpy $INSTMODE "install" goon2: ; remove some registry keys which interfere badly, when osgi-runner and/or the JRE is updated. ; We do this here after running the uninstaller, so we even erase the regkeys when ; older installers were installed before SetRegView 32 DeleteRegValue HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Java" "Jvm" DeleteRegValue HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Java" "Classpath" DeleteRegValue HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Java" "Options" DeleteRegKey HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Log" DeleteRegKey HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Start" DeleteRegKey HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Stop" SetRegView @REGVIEW@ FunctionEnd Function .onSelChange Push $0 StrCmp $LOGGING "log4j2" check_log4j2_on ;check_log4j_on: SectionGetFlags ${SEC02} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 check_log4j_off check_log4j_off SectionGetFlags ${SEC01} $0 IntOp $0 $0 & ${SECTION_OFF} SectionSetFlags ${SEC01} $0 StrCpy $LOGGING "log4j2" goto check_done check_log4j_off: SectionGetFlags ${SEC01} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} check_done 0 check_done SectionGetFlags ${SEC02} $0 IntOp $0 $0 | ${SF_SELECTED} SectionSetFlags ${SEC02} $0 StrCpy $LOGGING "log4j2" goto check_done check_log4j2_on: SectionGetFlags ${SEC01} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} 0 check_log4j2_off check_log4j2_off SectionGetFlags ${SEC02} $0 IntOp $0 $0 & ${SECTION_OFF} SectionSetFlags ${SEC02} $0 StrCpy $LOGGING "log4j" goto check_done check_log4j2_off: SectionGetFlags ${SEC02} $0 IntOp $0 $0 & ${SF_SELECTED} IntCmp $0 ${SF_SELECTED} check_done 0 check_done SectionGetFlags ${SEC01} $0 IntOp $0 $0 | ${SF_SELECTED} SectionSetFlags ${SEC01} $0 StrCpy $LOGGING "log4j" goto check_done ; former wish: ; instead switching log4j2 off should also switch logstash off ; switching logstash on should also switch log4j2 on, log4j off ; ; decision: ; tie logstash directly with log4j2, if not used it's ; only a view clazzes sleeping in one classloader check_done: Pop $0 FunctionEnd Section -AdditionalIcons SetOutPath $INSTDIR WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}" SectionEnd Section -Post StrCmp $JAVA_VERSION "8" java8_jce jce_ok java8_jce: ExecWait '"$JAVA_HOME\bin\javaw.exe" -cp "$INSTDIR\java" Aes256Test' $0 StrCmp $0 "0" jce_ok MessageBox MB_ICONQUESTION|MB_YESNO "Java in $JAVA_HOME is not enabled for AES-256, install unlimited JCE policy now?" IDNO jce_ok CopyFiles "$INSTDIR\java\java8\local_policy.jar" "$JAVA_HOME\lib\security" jce_ok: WriteUninstaller "$INSTDIR\uninst.exe" WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\bin\osgi-runner.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\bin\osgi-runner.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}" SetAutoClose false SectionEnd Function un.onUninstSuccess ; HideWindow MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) was successfully removed from your computer." FunctionEnd Function un.onInit SetRegView @REGVIEW@ !insertmacro MUI_UNGETLANGUAGE MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES +2 Abort FunctionEnd Section Uninstall ExecWait '"$INSTDIR\UninstallOsgiService.bat"' Delete "$INSTDIR\${PRODUCT_NAME}.url" Delete "$INSTDIR\uninst.exe" Delete "$INSTDIR\osgi-runner.exe" Delete "$INSTDIR\osgi-runnerw.exe" Delete "$INSTDIR\InstallOsgiService.bat" Delete "$INSTDIR\UninstallOsgiService.bat" Delete "$INSTDIR\MigrateKeysProperties.bat" Delete "$INSTDIR\tail-osgi-log.lnk" Delete "$INSTDIR\osgi-shell.lnk" Delete "$INSTDIR\ps1\tail-osgi-log.ps1" Delete "$INSTDIR\ps1\osgi-shell.ps1" RMDir "$INSTDIR\ps1" RMDir /r "$INSTDIR\lib" RMDir /r "$INSTDIR\bundle1" RMDir /r "$INSTDIR\bundle2" RMDir /r "$INSTDIR\bundle3" RMDir /r "$INSTDIR\bundle4" RMDir /r "$INSTDIR\bundle5" Delete "$INSTDIR\deploy\README" RMDir "$INSTDIR\deploy" Delete "$INSTDIR\drivers\README-DRIVERS" RMDir "$INSTDIR\drivers" ; This will mot likely fail, if host.key and/or authorized_keys is present in sshd.d Delete "$INSTDIR\etc\sshd.d\README-SSHD" RMDir "$INSTDIR\etc\sshd.d" RMDir /r "$INSTDIR\cache" RMDir /r "$INSTDIR\java" Delete "$INSTDIR\var\README" RMDir "$INSTDIR\var" Delete "$INSTDIR\log\README" Delete "$INSTDIR\log\osgi-runner.*.log" Delete "$INSTDIR\log\stdout.log" Delete "$INSTDIR\log\stderr.log" RMDir "$INSTDIR\log" Delete "$INSTDIR\etc\adm.d\*.new" Delete "$INSTDIR\etc\conf.d\*.new" ; ; Only delete files, which have not been changed as per MD5 checksum. ; !include "./remove-config.nsi" RMDir "$INSTDIR\etc\conf.d" RMDir "$INSTDIR\etc\adm.d" RMDir "$INSTDIR\etc\htpasswd.d" RMDir "$INSTDIR\etc" RMDir "$INSTDIR" DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}" DeleteRegKey HKLM "${PRODUCT_PATH_REGKEY}" SetRegView 32 DeleteRegValue HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Java" "Jvm" DeleteRegValue HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Java" "Classpath" DeleteRegValue HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Java" "Options" DeleteRegKey HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Log" DeleteRegKey HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Start" DeleteRegKey HKLM "Software\Apache Software Foundation\Procrun 2.0\osgi-runner\Parameters\Stop" SetRegView @REGVIEW@ SetAutoClose true SectionEnd