]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_win32/update-smart-drivedb.nsi
145b055f8d140357e42a765771f83305b3d10e14
[mirror_smartmontools-debian.git] / os_win32 / update-smart-drivedb.nsi
1 ;
2 ; smartmontools drive database update NSIS script
3 ;
4 ; Home page of code is: http://www.smartmontools.org
5 ;
6 ; Copyright (C) 2011-13 Christian Franke
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 ;
16 ; $Id: update-smart-drivedb.nsi 4431 2017-08-08 19:38:15Z chrfranke $
17 ;
18
19
20 ;--------------------------------------------------------------------
21 ; Command line arguments:
22 ; makensis -DBRANCH=<svn-branch-name> update-smart-drivedb.nsi
23
24 !include "FileFunc.nsh"
25
26 Name "update-smart-drivedb"
27 Caption "Update smartmontools drivedb.h"
28 OutFile "update-smart-drivedb.exe"
29
30 SetCompressor /solid lzma
31
32 XPStyle on
33 InstallColors /windows
34
35 Page instfiles
36
37 Section ""
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
52 MessageBox MB_OK "Download failed" /SD IDOK
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"
62 MessageBox MB_OK "drivedb.h.error: rejected by smartctl, probably no longer compatible" /SD IDOK
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"
72 MessageBox MB_OK "$INSTDIR\drivedb.h is already up to date" /SD IDOK
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"
84 MessageBox MB_OK "$INSTDIR\drivedb.h updated from $0" /SD IDOK
85
86 SectionEnd
87
88 Function .onInit
89 ; Install in same directory
90 ${GetExePath} $INSTDIR
91 FunctionEnd
92
93 ; Download from branch or trunk on stack, SetErrors on error
94 Function Download
95 Pop $R0
96 DetailPrint "Download from $R0"
97
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
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
119 err:
120 Delete "drivedb.h.new"
121 SetErrors
122 FunctionEnd
123
124 ; Compare drivedb.h drivedb.h.new, SetErrors if different
125 ; TODO: ignore differences in Id string
126 Function Cmp
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
133 StrCmp $R2 $R3 0 +2
134 IfErrors 0 readloop
135 FileClose $R0
136 FileClose $R1
137 ClearErrors
138 StrCmp $R2 $R3 0 +2
139 Return
140 SetErrors
141 FunctionEnd