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