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