new windows installer script, clarified licenses
[chaz/yoink] / make-win32-installer.sh.in
1 #!/bin/bash
2
3 #
4 # Yoink
5 # Run this script to create a win32 installer.
6 # This was blatantly yoinked and adapted from the Wormux Project.
7 #
8
9 # Programs
10 MAKENSIS="@MAKENSIS@"
11 STRIP="@STRIP@"
12
13 # Anchor paths
14 ROOT_DIR="$PWD"
15
16 # Stuff
17 COMPRESSION="/solid lzma"
18 DEST="tmp-yoink-win32"
19 SCRIPT="$DEST/yoink.nsi"
20
21 # DLL dependencies
22 DLLS="SDL SDL_image zlib1 libpng12-0 OpenAL32 libalut-0 libvorbis-0 libogg-0"
23 DLLS="$DLLS libvorbisfile-3"
24
25 # Prepare
26 ${STRIP:-strip} "$ROOT_DIR/src/yoink.exe"
27 rm -rf "$DEST"
28 mkdir -p "$DEST"
29
30
31 #
32 # Set installer definitions and strings.
33 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34
35 HKLM_PATH='SOFTWARE\Games\Yoink'
36 UNINSTALL_KEY='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Yoink'
37 APP_PATHS_KEY='SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\yoink.exe'
38 START_RUN_KEY='SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
39
40
41 PROMPT1="Not enough rights to install, aborting. :-("
42 PROMPT2="Unable to uninstall the currently installed version of Yoink. The new version will be installed without removing the currently installed version."
43
44 SEC_INSTALL="Install Yoink!"
45 SEC_INSTALL_DESC="Installs Yoink to your computer."
46 SEC_UNINSTALL="Uninstall previous version."
47 SEC_SHORTCUTS="Install Shortcuts."
48 SEC_SHORTCUTS_DESC="Install shortcuts at various locations."
49 SEC_SHORTCUT1="Place a shortcut on the desktop."
50 SEC_SHORTCUT2="Place a shortcut in the start menu."
51 SEC_SHORTCUT3="Place an uninstall shortcut in the start menu."
52
53 WEBSITE_LINK="Visit the Yoink website"
54
55
56 #
57 # Begin output of installer script.
58 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59
60 cat > "$SCRIPT" <<EOF
61 ; based on MUI Welcome/Finish Page Example Script written by Joost Verburg
62 !include "MUI2.nsh"
63 !include "Sections.nsh"
64 !include "LogicLib.nsh"
65 !include "FileFunc.nsh"
66
67 !insertmacro GetParent
68
69 Name "Yoink"
70 VIProductVersion "@PVERSION@"
71 VIAddVersionKey "FileDescription" "Yoink Setup"
72 VIAddVersionKey "ProductName" "Yoink"
73 VIAddVersionKey "FileVersion" "@VERSION@"
74 VIAddVersionKey "ProductVersion" "@VERSION@"
75 VIAddVersionKey "LegalCopyright" "Copyright 2009 Charles McGarvey et al."
76
77 ;General
78 OutFile "$ROOT_DIR/yoinksetup-@VERSION@.exe"
79 SetCompressor $COMPRESSION
80 ShowInstDetails show
81 ShowUninstDetails show
82 SetDateSave on
83 RequestExecutionLevel highest
84
85
86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87 ;; Modern UI Configuration ;;
88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89
90 !define MUI_ICON "$ROOT_DIR/src/yoink.ico"
91 !define MUI_UNICON "$ROOT_DIR/src/yoink.ico"
92 ; Language
93 !define MUI_LANGDLL_ALWAYSSHOW
94 !define MUI_LANGDLL_REGISTRY_ROOT "HKCU"
95 !define MUI_LANGDLL_REGISTRY_KEY "$HKLM_PATH"
96 !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"
97 ; Misc stuff
98 !define MUI_COMPONENTSPAGE_SMALLDESC
99 !define MUI_ABORTWARNING
100 ; Do not close dialogs, allow to check installation result
101 !define MUI_FINISHPAGE_NOAUTOCLOSE
102 !define MUI_UNFINISHPAGE_NOAUTOCLOSE
103 ;Finish Page config
104 !define MUI_FINISHPAGE_RUN "\$INSTDIR\\yoink.exe"
105 !define MUI_FINISHPAGE_RUN_NOTCHECKED
106 !define MUI_FINISHPAGE_LINK "$WEBSITE_LINK"
107 !define MUI_FINISHPAGE_LINK_LOCATION "http://www.dogcows.com/"
108
109 ;--------------------------------
110 ;Pages
111 ; Install
112 !insertmacro MUI_PAGE_WELCOME
113 !insertmacro MUI_PAGE_COMPONENTS
114 !insertmacro MUI_PAGE_DIRECTORY
115 !insertmacro MUI_PAGE_INSTFILES
116 !insertmacro MUI_PAGE_FINISH
117 ; Uninstall
118 !insertmacro MUI_UNPAGE_WELCOME
119 !insertmacro MUI_UNPAGE_CONFIRM
120 !insertmacro MUI_UNPAGE_INSTFILES
121 !insertmacro MUI_UNPAGE_FINISH
122
123 ;--------------------------------
124 ;Languages
125 !insertmacro MUI_LANGUAGE "English"
126
127 ;--------------------------------
128 ;Reserve Files
129 ;If you are using solid compression, files that are required before
130 ;the actual installation should be stored first in the data block,
131 ;because this will make your installer start faster.
132
133 !insertmacro MUI_RESERVEFILE_LANGDLL
134
135 ;--------------------------------
136 ;Folder-selection page
137 InstallDir "\$PROGRAMFILES\\Yoink"
138 ; Registry key to check for directory (so if you install again, it will
139 ; overwrite the old one automatically)
140 InstallDirRegKey HKLM "$HKLM_PATH" "Path"
141 AutoCloseWindow false
142
143 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
144 ;; Start Install Sections ;;
145 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
146
147 ;-----------------------------------------
148 ;Create folder only if it doesnt exist yet
149 !macro CreateDirectoryOnce FOLDER
150 IfFileExists "\${FOLDER}\\*.*" +1
151 CreateDirectory "\${FOLDER}"
152 !macroend
153
154 ;--------------------------------
155 ;Check (un)install rights
156 !macro CheckUserInstallRightsMacro UN
157 Function \${UN}CheckUserInstallRights
158 Push \$0
159 Push \$1
160 ClearErrors
161 UserInfo::GetName
162 IfErrors Win9x
163 Pop \$0
164 UserInfo::GetAccountType
165 Pop \$1
166
167 StrCmp \$1 "Admin" 0 +3
168 StrCpy \$1 "HKLM"
169 Goto done
170 StrCmp \$1 "Power" 0 +3
171 StrCpy \$1 "HKLM"
172 Goto done
173 StrCmp \$1 "User" 0 +3
174 StrCpy \$1 "HKCU"
175 Goto done
176 StrCmp \$1 "Guest" 0 +3
177 StrCpy \$1 "NONE"
178 Goto done
179 ; Unknown error
180 StrCpy \$1 "NONE"
181 Goto done
182
183 Win9x:
184 StrCpy \$1 "HKLM"
185
186 done:
187 Exch \$1
188 Exch
189 Pop \$0
190 FunctionEnd
191 !macroend
192 !insertmacro CheckUserInstallRightsMacro ""
193 !insertmacro CheckUserInstallRightsMacro "un."
194
195 ;--------------------------------
196 ; Uninstall any old version of Yoink
197
198 ; Section hidden because automatically selected by the installer
199 Section "$SEC_UNINSTALL" SecUninstallOldYoink
200 ; Check install rights..
201 StrCpy \$R3 $HKLM_PATH
202 StrCpy \$R4 $UNINSTALL_KEY
203 StrCpy \$R5 "uninstall.exe"
204 Call CheckUserInstallRights
205 Pop \$R0
206 ; "NONE" case already handled at start
207 StrCmp \$R0 "HKCU" _hkcu
208 ReadRegStr \$R1 HKLM \$R3 ""
209 ReadRegStr \$R2 HKLM "\$R4" "UninstallString"
210 Goto try_uninstall
211
212 _hkcu:
213 ReadRegStr \$R1 HKCU \$R3 ""
214 ReadRegStr \$R2 HKCU "\$R4" "UninstallString"
215
216 ; If a previous version exists, remove it
217 try_uninstall:
218 ; If first string is unavailable, Yoink was probably not installed
219 StrCmp \$R1 "" done
220 ; Check if we have uninstall string..
221 IfFileExists \$R2 0 no_file
222 ; Have uninstall string, go ahead and uninstall.
223 SetOverwrite on
224 ; Need to copy uninstaller outside of the install dir
225 ClearErrors
226 CopyFiles /SILENT \$R2 "\$TEMP\\\$R5"
227 SetOverwrite off
228 IfErrors uninstall_problem
229 ; Ready to uninstall..
230 ClearErrors
231 ExecWait '"\$TEMP\\\$R5" /S _?=\$R1'
232 IfErrors exec_error
233 Delete "\$TEMP\\\$R5"
234 Goto done
235
236 exec_error:
237 Delete "\$TEMP\\\$R5"
238 Goto uninstall_problem
239
240 no_file:
241 MessageBox MB_OK "No uninstaller exe found" /SD IDOK IDOK done
242
243 uninstall_problem:
244 ; We cant uninstall. Either the user must manually uninstall or
245 ; we ignore and reinstall over it.
246 MessageBox MB_OKCANCEL "$PROMPT2" /SD IDOK IDCANCEL done
247 Quit
248
249 done:
250 SectionEnd
251
252 ;--------------------------------
253 ; Installer Sections
254
255 Section "$SEC_INSTALL" SecInstallYoink
256 ; Create install and config folders
257 CreateDirectory "\$INSTDIR"
258 ; Set output path to the installation directory.
259 SetOutPath "\$INSTDIR"
260 File "$ROOT_DIR/src/yoink.ico"
261 ; Executing in tmpdir, looking for file in folder below
262 File "$ROOT_DIR/src/yoink.exe"
263 ; data
264 File /r /x Makefile* /x *.desktop "$ROOT_DIR/data"
265 ; uninstall
266 WriteUninstaller "uninstall.exe"
267 EOF
268
269
270 #
271 # Add DLL's to installer
272 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273
274 for dll in $DLLS
275 do
276 cat >> "$SCRIPT" <<EOF
277 File "@prefix@/bin/$dll.dll"
278 EOF
279 done
280
281
282 #
283 # Continue writing the installer
284 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
285
286 cat >> "$SCRIPT" <<EOF
287 Call CheckUserInstallRights
288 Pop \$R0
289 ; "NONE" case already handled at start
290 StrCmp \$R0 "HKCU" _hkcu
291 WriteRegStr HKLM "$APP_PATHS_KEY" "" "\$INSTDIR\\yoink.exe"
292 WriteRegStr HKLM "$HKLM_PATH" "" "\$INSTDIR"
293 WriteRegStr HKLM "$HKLM_PATH" "Version" "@VERSION@"
294 WriteRegStr HKLM "$UNINSTALL_KEY" "DisplayName" "Yoink"
295 WriteRegStr HKLM "$UNINSTALL_KEY" "DisplayVersion" "@VERSION@"
296 WriteRegStr HKLM "$UNINSTALL_KEY" "UninstallString" "\$INSTDIR\\uninstall.exe"
297 ;Write language to the registry (for the uninstaller)
298 WriteRegStr HKLM "$HKLM_PATH" "Installer Language" \$LANGUAGE
299 ; Sets scope of the desktop and Start Menu entries for all users.
300 SetShellVarContext "all"
301 Goto _next
302
303 _hkcu:
304 WriteRegStr HKCU "$HKLM_PATH" "" "\$INSTDIR"
305 WriteRegStr HKCU "$HKLM_PATH" "Version" "@VERSION@"
306 WriteRegStr HKCU "$UNINSTALL_KEY" "DisplayName" "Yoink"
307 WriteRegStr HKCU "$UNINSTALL_KEY" "DisplayVersion" "@VERSION@"
308 WriteRegStr HKCU "$UNINSTALL_KEY" "UninstallString" "\$INSTDIR\\uninstall.exe"
309 ;Write language to the registry (for the uninstaller)
310 WriteRegStr HKCU "$HKLM_PATH" "Installer Language" \$LANGUAGE
311 ;SetShellVarContext "current"
312
313 _next:
314 SectionEnd ; Installer section
315
316 ;--------------------------------
317 ;Shortcuts
318 SectionGroup /e "$SEC_SHORTCUTS" SecShortcuts
319
320 ; Desktop shortcut
321 Section /o "$SEC_SHORTCUT1" SecDesktopShortcut
322 SetOverwrite on
323 CreateShortCut "\$DESKTOP\\Yoink.lnk" "\$INSTDIR\\yoink.exe" \
324 "" "\$INSTDIR\\yoink.exe" 0
325 SetOverwrite off
326 SectionEnd
327
328 ; Yoink shortcut in start menu
329 Section "$SEC_SHORTCUT2" SecStartMenuShortcut
330 SetOverwrite on
331 !insertmacro CreateDirectoryOnce "\$SMPROGRAMS\\Yoink"
332 CreateShortCut "\$SMPROGRAMS\\Yoink\\Play Yoink!.lnk" \
333 "\$INSTDIR\\yoink.exe" "" "\$INSTDIR\\yoink.exe" 0
334 SetOverwrite off
335 SectionEnd
336
337 ; Yoink uninstall shortcut in start menu
338 ; Might be forced if user has no install rights,
339 ; because it would be complex otherwise:
340 ; - No uninstall available in Windows "Program uninstall"
341 ; - Folder lost in APPDATA, which can be hidden, etc
342 Section "$SEC_SHORTCUT3" SecUninstallShortcut
343 SetOverwrite on
344 !insertmacro CreateDirectoryOnce "\$SMPROGRAMS\\Yoink"
345 CreateShortCut "\$SMPROGRAMS\\Yoink\\Uninstall.lnk" \
346 "\$INSTDIR\\uninstall.exe" "" "\$INSTDIR\\uninstall.exe" 0
347 SetOverwrite off
348 SectionEnd
349
350 SectionGroupEnd
351
352
353 ;--------------------------------
354 ;Descriptions
355
356 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
357 !insertmacro MUI_DESCRIPTION_TEXT \${SecInstallYoink} "$SEC_INSTALL_DESC"
358 !insertmacro MUI_DESCRIPTION_TEXT \${SecShortcuts} "$SEC_SHORTCUTS_DESC"
359 !insertmacro MUI_DESCRIPTION_TEXT \${SecDesktopShortcut} "$SEC_SHORTCUT1"
360 !insertmacro MUI_DESCRIPTION_TEXT \${SecStartMenuShortcut} "$SEC_SHORTCUT2"
361 !insertmacro MUI_DESCRIPTION_TEXT \${SecUninstallShortcut} "$SEC_SHORTCUT3"
362 !insertmacro MUI_FUNCTION_DESCRIPTION_END
363
364
365 ;--------------------------------
366 ;Uninstaller Section
367
368 Section "Uninstall"
369 ; Set install path according to user rights
370 Call un.CheckUserInstallRights
371 Pop \$R0
372 StrCmp \$R0 "HKLM" _hklm
373
374 ; Also used as fallback by HKLM case
375 _hkcu:
376 ReadRegStr \$R0 HKCU "$HKLM_PATH" ""
377 StrCmp \$R0 "\$INSTDIR" 0 _next
378 ; HKCU install path matches our INSTDIR so uninstall
379 DeleteRegKey HKCU "$HKLM_PATH"
380 DeleteRegKey HKCU "$UNINSTALL_KEY"
381 Goto _next
382
383 _hklm:
384 ReadRegStr \$R0 HKLM "$HKLM_PATH" ""
385 StrCmp \$R0 \$INSTDIR 0 _hkcu
386 ; HKLM install path matches our INSTDIR so uninstall
387 DeleteRegKey HKLM "$APP_PATHS_KEY"
388 DeleteRegKey HKLM "$HKLM_PATH"
389 DeleteRegKey HKLM "$UNINSTALL_KEY"
390 SetShellVarContext all
391
392 _next:
393 ; Remove Language preference info
394 DeleteRegValue HKCU "$HKLM_PATH" "Installer Language"
395 ; remove shortcuts, if any.
396 Delete "\$SMPROGRAMS\\Yoink\\*.*"
397 RMDir "\$SMPROGRAMS\\Yoink"
398 Delete "\$SMPROGRAMS\\Yoink.lnk"
399 Delete "\$DESKTOP\\Yoink.lnk"
400 ; remove files
401 RMDir /r "\$INSTDIR"
402 SectionEnd
403
404 Function .onInit
405 ;Language selection
406 !insertmacro MUI_LANGDLL_DISPLAY
407
408 IntOp \$R0 \${SF_RO} | \${SF_SELECTED}
409 SectionSetFlags \${SecInstallYoink} \$R0
410 SectionSetFlags \${SecUninstallOldYoink} \$R0
411
412 ; Set install path according to user rights
413 Call CheckUserInstallRights
414 Pop \$R0
415 StrCmp \$R0 "NONE" _none
416 StrCmp \$R0 "HKLM" 0 _hkcu
417 StrCpy \$INSTDIR "\$PROGRAMFILES\\Yoink"
418 Goto _done
419
420 _hkcu:
421 Push \$SMPROGRAMS
422 \${GetParent} \$SMPROGRAMS \$R2
423 \${GetParent} \$R2 \$R2
424 StrCpy \$INSTDIR "\$R2\\Yoink"
425 ; In this case uninstall shortcut *must* be available because
426 ; the alternative are complex for the user
427 IntOp \$R0 \${SF_RO} | \${SF_SELECTED}
428 SectionSetFlags \${SecUninstallShortcut} \$R0
429 Goto _done
430
431 _none:
432 ; Not going to bother
433 MessageBox MB_OK "$PROMPT1" /SD IDOK
434 Quit
435
436 _done:
437 FunctionEnd
438
439 ; INSTDIR will be determined by reading a registry key
440 Function un.onInit
441 !insertmacro MUI_UNGETLANGUAGE
442 ; Set install path according to user rights
443 Call un.CheckUserInstallRights
444 Pop \$R0
445 StrCmp \$R0 "NONE" _none
446 Goto _end
447
448 _none:
449 ; Not going to bother
450 MessageBox MB_OK "$PROMPT1" /SD IDOK
451 Quit
452
453 _end:
454 FunctionEnd
455 EOF
456
457
458 #
459 # Compile the installer and cleanup.
460 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
461
462 if ! "${MAKENSIS:-makensis}" "$SCRIPT"
463 then
464 echo "makensis failed, aborting..."
465 exit 1
466 fi
467
468 rm -rf "$DEST"
469
This page took 0.046461 seconds and 4 git commands to generate.