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