]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - os_win32/update-smart-drivedb.nsi
Imported Upstream version 6.4+svn4214
[mirror_smartmontools-debian.git] / os_win32 / update-smart-drivedb.nsi
CommitLineData
cfbba5b9
GI
1;
2; smartmontools drive database update NSIS script
3;
6b80b4d2 4; Home page of code is: http://www.smartmontools.org
cfbba5b9 5;
3d17a85c 6; Copyright (C) 2011-13 Christian Franke <smartmontools-support@lists.sourceforge.net>
cfbba5b9
GI
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2, or (at your option)
11; any later version.
12;
13; You should have received a copy of the GNU General Public License
14; (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
15;
6b80b4d2 16; $Id: update-smart-drivedb.nsi 4120 2015-08-27 16:12:21Z samm2 $
cfbba5b9
GI
17;
18
19
20;--------------------------------------------------------------------
21; Command line arguments:
22; makensis -DBRANCH=<svn-branch-name> update-smart-drivedb.nsi
23
24!include "FileFunc.nsh"
25
26Name "update-smart-drivedb"
27Caption "Update smartmontools drivedb.h"
28OutFile "update-smart-drivedb.exe"
29
30SetCompressor /solid lzma
31
32XPStyle on
33InstallColors /windows
34
35Page instfiles
36
37Section ""
38
39 SetOutPath $INSTDIR
40
41!ifdef BRANCH
42 StrCpy $0 "branches/${BRANCH}"
43 Push $0
44 Call Download
45 IfErrors 0 endload
46!endif
47
48 StrCpy $0 "trunk"
49 Push $0
50 Call Download
51 IfErrors 0 endload
d008864d 52 MessageBox MB_OK "Download failed" /SD IDOK
cfbba5b9
GI
53 Abort "Download failed"
54 endload:
55
56 ; Check syntax
57 Delete "drivedb.h.error"
58 IfFileExists "smartctl-nc.exe" 0 endsyntax
59 ExecWait '.\smartctl-nc.exe -B drivedb.h.new -P showall' $1
60 StrCmp $1 "0" endsyntax
61 Rename "drivedb.h.new" "drivedb.h.error"
d008864d 62 MessageBox MB_OK "drivedb.h.error: rejected by smartctl, probably no longer compatible" /SD IDOK
cfbba5b9
GI
63 Abort "drivedb.h.error: rejected by smartctl, probably no longer compatible"
64 endsyntax:
65
66 ; Keep old file if identical
67 Delete "drivedb.h.lastcheck"
68 IfFileExists "drivedb.h" 0 endcomp
69 Call Cmp
70 IfErrors changed 0
71 DetailPrint "drivedb.h is already up to date"
d008864d 72 MessageBox MB_OK "$INSTDIR\drivedb.h is already up to date" /SD IDOK
cfbba5b9
GI
73 Delete "drivedb.h.new"
74 DetailPrint "Create file: drivedb.h.lastcheck"
75 FileOpen $1 "drivedb.h.lastcheck" w
76 FileClose $1
77 Return
78 changed:
79 Delete "drivedb.h.old"
80 Rename "drivedb.h" "drivedb.h.old"
81
82 endcomp:
83 Rename "drivedb.h.new" "drivedb.h"
d008864d 84 MessageBox MB_OK "$INSTDIR\drivedb.h updated from $0" /SD IDOK
cfbba5b9
GI
85
86SectionEnd
87
88Function .onInit
89 ; Install in same directory
90 ${GetExePath} $INSTDIR
91FunctionEnd
92
93; Download from branch or trunk on stack, SetErrors on error
94Function Download
95 Pop $R0
96 DetailPrint "Download from $R0"
97
3d17a85c
GI
98 ; SVN repository read-only URL
99 ; (SF code browser does not return ContentLength required for NSISdl::download)
100 StrCpy $R1 "http://svn.code.sf.net/p/smartmontools/code/$R0/smartmontools/drivedb.h"
101
cfbba5b9
GI
102 DetailPrint "($R1)"
103
104 NSISdl::download $R1 "drivedb.h.new"
105 Pop $R0
106 DetailPrint "Download: $R0"
107 ClearErrors
108 StrCmp $R0 "success" 0 err
109
110 ; File must start with comment
111 FileOpen $R0 "drivedb.h.new" r
112 FileReadByte $R0 $R1
113 FileClose $R0
114 ClearErrors
115 StrCmp $R1 "47" 0 +2
116 Return
117 DetailPrint "drivedb.h.new: syntax error ($R1)"
118
119err:
120 Delete "drivedb.h.new"
121 SetErrors
122FunctionEnd
123
124; Compare drivedb.h drivedb.h.new, SetErrors if different
125; TODO: ignore differences in Id string
126Function Cmp
d008864d
GI
127 ClearErrors
128 FileOpen $R0 "drivedb.h" r
129 FileOpen $R1 "drivedb.h.new" r
130 readloop:
131 FileRead $R0 $R2
132 FileRead $R1 $R3
cfbba5b9 133 StrCmp $R2 $R3 0 +2
d008864d
GI
134 IfErrors 0 readloop
135 FileClose $R0
136 FileClose $R1
137 ClearErrors
138 StrCmp $R2 $R3 0 +2
139 Return
140 SetErrors
cfbba5b9 141FunctionEnd