]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - os_win32/update-smart-drivedb.nsi
import smartmontools 7.0
[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 ; SPDX-License-Identifier: GPL-2.0-or-later
9 ;
10 ; $Id: update-smart-drivedb.nsi 4760 2018-08-19 18:45:53Z chrfranke $
11 ;
12
13
14 ;--------------------------------------------------------------------
15 ; Command line arguments:
16 ; makensis -DBRANCH=<svn-branch-name> update-smart-drivedb.nsi
17
18 !include "FileFunc.nsh"
19
20 Name "update-smart-drivedb"
21 Caption "Update smartmontools drivedb.h"
22 OutFile "update-smart-drivedb.exe"
23
24 SetCompressor /solid lzma
25
26 XPStyle on
27 InstallColors /windows
28
29 Page instfiles
30
31 Section ""
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
46 MessageBox MB_OK "Download failed" /SD IDOK
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"
56 MessageBox MB_OK "drivedb.h.error: rejected by smartctl, probably no longer compatible" /SD IDOK
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"
66 MessageBox MB_OK "$INSTDIR\drivedb.h is already up to date" /SD IDOK
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"
78 MessageBox MB_OK "$INSTDIR\drivedb.h updated from $0" /SD IDOK
79
80 SectionEnd
81
82 Function .onInit
83 ; Install in same directory
84 ${GetExePath} $INSTDIR
85 FunctionEnd
86
87 ; Download from branch or trunk on stack, SetErrors on error
88 Function Download
89 Pop $R0
90 DetailPrint "Download from $R0"
91
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
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
113 err:
114 Delete "drivedb.h.new"
115 SetErrors
116 FunctionEnd
117
118 ; Compare drivedb.h drivedb.h.new, SetErrors if different
119 ; TODO: ignore differences in Id string
120 Function Cmp
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
127 StrCmp $R2 $R3 0 +2
128 IfErrors 0 readloop
129 FileClose $R0
130 FileClose $R1
131 ClearErrors
132 StrCmp $R2 $R3 0 +2
133 Return
134 SetErrors
135 FunctionEnd