2 ; smartmontools drive database update NSIS script
4 ; Home page of code is: http://www.smartmontools.org
6 ; Copyright (C) 2011-13 Christian Franke
8 ; SPDX-License-Identifier: GPL-2.0-or-later
10 ; $Id: update-smart-drivedb.nsi 4760 2018-08-19 18:45:53Z chrfranke $
14 ;--------------------------------------------------------------------
15 ; Command line arguments:
16 ; makensis -DBRANCH=<svn-branch-name> update-smart-drivedb.nsi
18 !include "FileFunc.nsh"
20 Name "update-smart-drivedb"
21 Caption "Update smartmontools drivedb.h"
22 OutFile "update-smart-drivedb.exe"
24 SetCompressor /solid lzma
27 InstallColors /windows
36 StrCpy $0 "branches/${BRANCH}"
46 MessageBox MB_OK "Download failed" /SD IDOK
47 Abort "Download failed"
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"
60 ; Keep old file if identical
61 Delete "drivedb.h.lastcheck"
62 IfFileExists "drivedb.h" 0 endcomp
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
73 Delete "drivedb.h.old"
74 Rename "drivedb.h" "drivedb.h.old"
77 Rename "drivedb.h.new" "drivedb.h"
78 MessageBox MB_OK "$INSTDIR\drivedb.h updated from $0" /SD IDOK
83 ; Install in same directory
84 ${GetExePath} $INSTDIR
87 ; Download from branch or trunk on stack, SetErrors on error
90 DetailPrint "Download from $R0"
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"
98 NSISdl::download $R1 "drivedb.h.new"
100 DetailPrint "Download: $R0"
102 StrCmp $R0 "success" 0 err
104 ; File must start with comment
105 FileOpen $R0 "drivedb.h.new" r
111 DetailPrint "drivedb.h.new: syntax error ($R1)"
114 Delete "drivedb.h.new"
118 ; Compare drivedb.h drivedb.h.new, SetErrors if different
119 ; TODO: ignore differences in Id string
122 FileOpen $R0 "drivedb.h" r
123 FileOpen $R1 "drivedb.h.new" r