CDM Server as win32 service - installer improvements
[cdm-server.git] / src / main / installer / win32 / setup.nsi
1 # Auto-generated by EclipseNSIS Script Wizard
2 # 28.10.2010 13:58:54
3
4 # TODO : preserve $INSTDIR/.cdmLibrary from being deleted if the user desides to keep it, or just warn the user.
5
6 Name "EDIT CDM-Server"
7
8 # General Symbol Definitions
9 !define REGKEY "SOFTWARE\$(^Name)"
10 !define VERSION 2.5
11 !define COMPANY "EDIT - European Distributed Institute of Taxonomy"
12 !define EDIT_PLATFORM "EDIT Platform for Cybertaxonomy"
13 !define URL http://wp5.e-taxonomy.eu/
14 !define URL-EDIT http://www.e-taxonomy.eu/
15
16 # Included files
17 !include Sections.nsh
18
19 # Files and Folders
20 !define OUT_FOLDER "..\..\..\..\dist"
21 !define JAR_FILE_NAME "cdm-server-${VERSION}.jar"
22 !define JAR_FILE "..\..\..\..\target\${JAR_FILE_NAME}"
23 !define CDMLIBRARY_TEMPLATE "..\templates\.cdmLibrary"
24
25 # Reserved Files
26 ReserveFile "${NSISDIR}\Plugins\StartMenu.dll"
27
28 # Variables
29 Var StartMenuGroup
30
31 # Installer pages
32 Page license
33 Page directory
34 Page custom StartMenuGroupSelect "" ": Start Menu Folder"
35 Page instfiles
36
37 # Installer attributes
38 OutFile "${OUT_FOLDER}\EDIT CDM-Server-${VERSION}.exe"
39 InstallDir "$PROGRAMFILES\EDIT CDM-Server"
40 CRCCheck on
41 XPStyle on
42 Icon "${NSISDIR}\Contrib\Graphics\Icons\classic-install.ico"
43 ShowInstDetails show
44 AutoCloseWindow false
45 LicenseData ..\..\..\..\LICENSE.TXT
46 VIProductVersion 2.5.0.0
47 VIAddVersionKey ProductName "$(^Name)"
48 VIAddVersionKey ProductVersion "${VERSION}"
49 VIAddVersionKey CompanyName "${COMPANY}"
50 VIAddVersionKey CompanyWebsite "${URL}"
51 VIAddVersionKey FileVersion "${VERSION}"
52 VIAddVersionKey FileDescription ""
53 VIAddVersionKey LegalCopyright ""
54 InstallDirRegKey HKLM "${REGKEY}" Path
55 UninstallIcon "${NSISDIR}\Contrib\Graphics\Icons\classic-uninstall.ico"
56 ShowUninstDetails show
57
58 # Installer sections
59 Section -Main SEC0000
60 SetOutPath $INSTDIR
61 SetOverwrite on
62 File /r /x .svn /x *.log /x *.jar program-folder\*
63 File /r /x .svn ${CDMLIBRARY_TEMPLATE}
64 File ${JAR_FILE}
65 SetOverwrite off
66 SetOutPath "$INSTDIR\lib"
67 WriteRegStr HKLM "${REGKEY}\Components" Main 1
68 SectionEnd
69
70 Section -post SEC0001
71 WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
72 WriteRegStr HKLM "${REGKEY}" StartMenuGroup $StartMenuGroup
73 SetOutPath $INSTDIR
74 WriteUninstaller $INSTDIR\uninstall.exe
75 SetOutPath $SMPROGRAMS\$StartMenuGroup
76 CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk" $INSTDIR\uninstall.exe
77 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
78 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayVersion "${VERSION}"
79 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" Publisher "${COMPANY}"
80 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" URLInfoAbout "${URL}"
81 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\uninstall.exe
82 WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\uninstall.exe
83 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
84 WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
85
86 ExecWait '"$INSTDIR\CDMServer.exe" --install "$INSTDIR\etc\CDMServer.conf$\"'
87 ExecWait '"$INSTDIR\CDMServer.exe" --start "$INSTDIR\etc\CDMServer.conf$\"'
88 SectionEnd
89
90 Section -AdditionalIcons SEC0003
91 SetOutPath $INSTDIR
92 WriteIniStr "$INSTDIR\${EDIT_PLATFORM}.url" "InternetShortcut" "URL" "${URL}"
93 WriteIniStr "$INSTDIR\${COMPANY}.url" "InternetShortcut" "URL" "${URL-EDIT}"
94 CreateDirectory "$SMPROGRAMS\$(^Name)"
95 CreateShortCut "$SMPROGRAMS\$(^Name)\${EDIT_PLATFORM}.lnk" "$INSTDIR\${EDIT_PLATFORM}.url"
96 CreateShortCut "$SMPROGRAMS\$(^Name)\${COMPANY}.lnk" "$INSTDIR\${COMPANY}.url"
97 CreateShortCut "$SMPROGRAMS\$(^Name)\Uninstall $(^Name).lnk" "$INSTDIR\uninstall.exe"
98 CreateShortCut "$SMPROGRAMS\$(^Name)\Start $(^Name).lnk" "$INSTDIR\start-service.bat"
99 CreateShortCut "$SMPROGRAMS\$(^Name)\Stop $(^Name).lnk" "$INSTDIR\stop-service.bat"
100 SectionEnd
101
102 # Macro for selecting uninstaller sections
103 !macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
104 Push $R0
105 ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}"
106 StrCmp $R0 1 0 next${UNSECTION_ID}
107 !insertmacro SelectSection "${UNSECTION_ID}"
108 GoTo done${UNSECTION_ID}
109 next${UNSECTION_ID}:
110 !insertmacro UnselectSection "${UNSECTION_ID}"
111 done${UNSECTION_ID}:
112 Pop $R0
113 !macroend
114
115 # Uninstaller sections
116 Section /o -un.Main UNSEC0000
117 ExecWait '"$INSTDIR\CDMServer.exe" --remove "$INSTDIR\etc\CDMServer.conf$\"'
118 RmDir /r /REBOOTOK $INSTDIR
119 DeleteRegValue HKLM "${REGKEY}\Components" Main
120 SectionEnd
121
122 Section -un.post UNSEC0001
123 DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
124 Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
125 Delete /REBOOTOK $INSTDIR\uninstall.exe
126 DeleteRegValue HKLM "${REGKEY}" StartMenuGroup
127 DeleteRegValue HKLM "${REGKEY}" Path
128 DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components"
129 DeleteRegKey /IfEmpty HKLM "${REGKEY}"
130 RmDir /REBOOTOK $SMPROGRAMS\$StartMenuGroup
131 RmDir /REBOOTOK $INSTDIR
132 SectionEnd
133
134 # Installer functions
135 Function StartMenuGroupSelect
136 Push $R1
137 StartMenu::Select /autoadd /text "Select the Start Menu folder in which to create the program's shortcuts:" /lastused $StartMenuGroup "$(^Name)"
138 Pop $R1
139 StrCmp $R1 success success
140 StrCmp $R1 cancel done
141 MessageBox MB_OK $R1
142 Goto done
143 success:
144 Pop $StartMenuGroup
145 done:
146 Pop $R1
147 FunctionEnd
148
149 Function .onInstSuccess
150
151 FunctionEnd
152
153 Function .onInit
154 InitPluginsDir
155 FunctionEnd
156
157 # Uninstaller functions
158 Function un.onInit
159 ReadRegStr $INSTDIR HKLM "${REGKEY}" Path
160 ReadRegStr $StartMenuGroup HKLM "${REGKEY}" StartMenuGroup
161 !insertmacro SELECT_UNSECTION Main ${UNSEC0000}
162 FunctionEnd
163