]> Dogcows Code - chaz/yoink/blob - make-win32-installer.sh.in
minor build system changes
[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 OUT_FILE=${1:-yoinksetup-@VERSION@.exe}
21
22 # DLL dependencies
23 DLLS="SDL SDL_image zlib1 libpng12-0 OpenAL32 libalut-0 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"
269 ; uninstall
270 WriteUninstaller "uninstall.exe"
271 EOF
272
273
274 #
275 # Add DLL's to installer
276 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
277
278 for dll in $DLLS
279 do
280 cat >> "$SCRIPT" <<EOF
281 File "@prefix@/bin/$dll.dll"
282 EOF
283 done
284
285
286 #
287 # Continue writing the installer
288 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
289
290 cat >> "$SCRIPT" <<EOF
291 Call CheckUserInstallRights
292 Pop \$R0
293 ; "NONE" case already handled at start
294 StrCmp \$R0 "HKCU" _hkcu
295 WriteRegStr HKLM "$APP_PATHS_KEY" "" "\$INSTDIR\\yoink.exe"
296 WriteRegStr HKLM "$HKLM_PATH" "" "\$INSTDIR"
297 WriteRegStr HKLM "$HKLM_PATH" "Version" "@VERSION@"
298 WriteRegStr HKLM "$UNINSTALL_KEY" "DisplayName" "Yoink"
299 WriteRegStr HKLM "$UNINSTALL_KEY" "DisplayVersion" "@VERSION@"
300 WriteRegStr HKLM "$UNINSTALL_KEY" "UninstallString" "\$INSTDIR\\uninstall.exe"
301 ;Write language to the registry (for the uninstaller)
302 WriteRegStr HKLM "$HKLM_PATH" "Installer Language" \$LANGUAGE
303 ; Sets scope of the desktop and Start Menu entries for all users.
304 SetShellVarContext "all"
305 Goto _next
306
307 _hkcu:
308 WriteRegStr HKCU "$HKLM_PATH" "" "\$INSTDIR"
309 WriteRegStr HKCU "$HKLM_PATH" "Version" "@VERSION@"
310 WriteRegStr HKCU "$UNINSTALL_KEY" "DisplayName" "Yoink"
311 WriteRegStr HKCU "$UNINSTALL_KEY" "DisplayVersion" "@VERSION@"
312 WriteRegStr HKCU "$UNINSTALL_KEY" "UninstallString" "\$INSTDIR\\uninstall.exe"
313 ;Write language to the registry (for the uninstaller)
314 WriteRegStr HKCU "$HKLM_PATH" "Installer Language" \$LANGUAGE
315 ;SetShellVarContext "current"
316
317 _next:
318 SectionEnd ; Installer section
319
320 ;--------------------------------
321 ;Shortcuts
322 SectionGroup /e "$SEC_SHORTCUTS" SecShortcuts
323
324 ; Desktop shortcut
325 Section /o "$SEC_SHORTCUT1" SecDesktopShortcut
326 SetOverwrite on
327 CreateShortCut "\$DESKTOP\\Yoink.lnk" "\$INSTDIR\\yoink.exe" \
328 "" "\$INSTDIR\\yoink.exe" 0
329 SetOverwrite off
330 SectionEnd
331
332 ; Yoink uninstall shortcut in start menu
333 ; Might be forced if user has no install rights,
334 ; because it would be complex otherwise:
335 ; - No uninstall available in Windows "Program uninstall"
336 ; - Folder lost in APPDATA, which can be hidden, etc
337 Section "$SEC_SHORTCUT3" SecUninstallShortcut
338 SetOverwrite on
339 !insertmacro CreateDirectoryOnce "\$SMPROGRAMS\\Yoink"
340 CreateShortCut "\$SMPROGRAMS\\Yoink\\Uninstall.lnk" \
341 "\$INSTDIR\\uninstall.exe" "" "\$INSTDIR\\uninstall.exe" 0
342 SetOverwrite off
343 SectionEnd
344
345 ; Yoink shortcut in start menu
346 Section "$SEC_SHORTCUT2" SecStartMenuShortcut
347 SetOverwrite on
348 !insertmacro CreateDirectoryOnce "\$SMPROGRAMS\\Yoink"
349 CreateShortCut "\$SMPROGRAMS\\Yoink\\Play Yoink!.lnk" \
350 "\$INSTDIR\\yoink.exe" "" "\$INSTDIR\\yoink.exe" 0
351 SetOverwrite off
352 SectionEnd
353
354 SectionGroupEnd
355
356
357 ;--------------------------------
358 ;Descriptions
359
360 !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
361 !insertmacro MUI_DESCRIPTION_TEXT \${SecInstallYoink} "$SEC_INSTALL_DESC"
362 !insertmacro MUI_DESCRIPTION_TEXT \${SecShortcuts} "$SEC_SHORTCUTS_DESC"
363 !insertmacro MUI_DESCRIPTION_TEXT \${SecDesktopShortcut} "$SEC_SHORTCUT1"
364 !insertmacro MUI_DESCRIPTION_TEXT \${SecStartMenuShortcut} "$SEC_SHORTCUT2"
365 !insertmacro MUI_DESCRIPTION_TEXT \${SecUninstallShortcut} "$SEC_SHORTCUT3"
366 !insertmacro MUI_FUNCTION_DESCRIPTION_END
367
368
369 ;--------------------------------
370 ;Uninstaller Section
371
372 Section "Uninstall"
373 ; Set install path according to user rights
374 Call un.CheckUserInstallRights
375 Pop \$R0
376 StrCmp \$R0 "HKLM" _hklm
377
378 ; Also used as fallback by HKLM case
379 _hkcu:
380 ReadRegStr \$R0 HKCU "$HKLM_PATH" ""
381 StrCmp \$R0 "\$INSTDIR" 0 _next
382 ; HKCU install path matches our INSTDIR so uninstall
383 DeleteRegKey HKCU "$HKLM_PATH"
384 DeleteRegKey HKCU "$UNINSTALL_KEY"
385 Goto _next
386
387 _hklm:
388 ReadRegStr \$R0 HKLM "$HKLM_PATH" ""
389 StrCmp \$R0 \$INSTDIR 0 _hkcu
390 ; HKLM install path matches our INSTDIR so uninstall
391 DeleteRegKey HKLM "$APP_PATHS_KEY"
392 DeleteRegKey HKLM "$HKLM_PATH"
393 DeleteRegKey HKLM "$UNINSTALL_KEY"
394 SetShellVarContext all
395
396 _next:
397 ; Remove Language preference info
398 DeleteRegValue HKCU "$HKLM_PATH" "Installer Language"
399 ; remove shortcuts, if any.
400 Delete "\$SMPROGRAMS\\Yoink\\*.*"
401 RMDir "\$SMPROGRAMS\\Yoink"
402 Delete "\$SMPROGRAMS\\Yoink.lnk"
403 Delete "\$DESKTOP\\Yoink.lnk"
404 ; remove files
405 RMDir /r "\$INSTDIR"
406 SectionEnd
407
408 Function .onInit
409 ;Language selection
410 !insertmacro MUI_LANGDLL_DISPLAY
411
412 IntOp \$R0 \${SF_RO} | \${SF_SELECTED}
413 SectionSetFlags \${SecInstallYoink} \$R0
414 SectionSetFlags \${SecUninstallOldYoink} \$R0
415
416 ; Set install path according to user rights
417 Call CheckUserInstallRights
418 Pop \$R0
419 StrCmp \$R0 "NONE" _none
420 StrCmp \$R0 "HKLM" 0 _hkcu
421 StrCpy \$INSTDIR "\$PROGRAMFILES\\Yoink"
422 Goto _done
423
424 _hkcu:
425 Push \$SMPROGRAMS
426 \${GetParent} \$SMPROGRAMS \$R2
427 \${GetParent} \$R2 \$R2
428 StrCpy \$INSTDIR "\$R2\\Yoink"
429 ; In this case uninstall shortcut *must* be available because
430 ; the alternative are complex for the user
431 IntOp \$R0 \${SF_RO} | \${SF_SELECTED}
432 SectionSetFlags \${SecUninstallShortcut} \$R0
433 Goto _done
434
435 _none:
436 ; Not going to bother
437 MessageBox MB_OK "$PROMPT1" /SD IDOK
438 Quit
439
440 _done:
441 FunctionEnd
442
443 ; INSTDIR will be determined by reading a registry key
444 Function un.onInit
445 !insertmacro MUI_UNGETLANGUAGE
446 ; Set install path according to user rights
447 Call un.CheckUserInstallRights
448 Pop \$R0
449 StrCmp \$R0 "NONE" _none
450 Goto _end
451
452 _none:
453 ; Not going to bother
454 MessageBox MB_OK "$PROMPT1" /SD IDOK
455 Quit
456
457 _end:
458 FunctionEnd
459 EOF
460
461
462 #
463 # Compile the installer and cleanup.
464 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
465
466 if ! "${MAKENSIS:-makensis}" "$SCRIPT"
467 then
468 echo "makensis failed, aborting..."
469 exit 1
470 fi
471
472 rm -rf "$DEST"
473
This page took 0.052154 seconds and 4 git commands to generate.