]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - update-smart-drivedb.in
3 # smartmontools drive database update script
5 # Copyright (C) 2010-11 Christian Franke <smartmontools-support@lists.sourceforge.net>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # You should have received a copy of the GNU General Public License
13 # (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
15 # $Id: update-smart-drivedb.in 3294 2011-03-16 21:36:58Z chrfranke $
20 # Set by config.status
24 exec_prefix
="@exec_prefix@"
26 datarootdir
="@datarootdir@"
28 drivedbdir
="@drivedbdir@"
31 os_dltools
="@os_dltools@"
33 # drivedb.h update branch
34 BRANCH
="@DRIVEDB_BRANCH@"
36 # Default drivedb location
37 DEST
="$drivedbdir/drivedb.h"
39 # Smartctl used for syntax check
40 SMARTCTL
="$sbindir/smartctl"
42 # Trac repository browser (does not return HTTP 404 errors)
43 #SRCEXPR='http://sourceforge.net/apps/trac/smartmontools/export/HEAD/$location/smartmontools/drivedb.h'
45 # ViewVC repository browser
46 SRCEXPR
='http://smartmontools.svn.sourceforge.net/viewvc/smartmontools/$location/smartmontools/drivedb.h?revision=HEAD'
58 smartmontools $VERSION drive database update script
60 Usage: $0 [-v] [DESTFILE]
65 or DESTFILE from smartmontools SVN repository.
66 Tries to download first from branch $BRANCH
76 # Abort if 'which' is not available
77 which which >/dev
/null ||
exit 1
81 for t
in $os_dltools; do
82 if which $t >/dev
/null
2>/dev
/null
; then
84 curl
) DOWNLOAD
="curl ${q:+-s }"'-f -o "$DEST.new" "$SRC"' ;;
85 lynx
) DOWNLOAD
='lynx -source "$SRC" >"$DEST.new"' ;;
86 wget
) DOWNLOAD
="wget $q"'-O "$DEST.new" "$SRC"' ;;
87 fetch
) DOWNLOAD
='fetch -o "$DEST.new" "$SRC"' ;; # FreeBSD
88 ftp) DOWNLOAD
='ftp -o "$DEST.new" "$SRC"' ;; # OpenBSD
93 if [ -z "$DOWNLOAD" ]; then
94 echo "$0: found none of: $os_dltools" >&2; exit 1
97 # Try possible branch first, then trunk
98 for location
in "branches/$BRANCH" "trunk"; do
99 test -n "$q" ||
echo "Download from $location"
103 SRC
="`eval echo "$SRCEXPR"`"
105 if (eval $DOWNLOAD); then :; else
106 errmsg
="download from $location failed (HTTP error)"
109 if grep -i 'ViewVC Exception' "$DEST.new" >/dev
/null
; then
110 errmsg
="download from $location failed (ViewVC error)"
117 if [ -n "$errmsg" ]; then
119 echo "$0: $errmsg" >&2
123 # Adjust timestamp and permissions
125 chmod 0644 "$DEST.new"
129 if $SMARTCTL -B "$DEST.new" -P showall
>/dev
/null
; then :; else
130 mv "$DEST.new" "$DEST.error"
131 echo "$DEST.error: rejected by $SMARTCTL, probably no longer compatible" >&2
135 # Keep old file if identical, ignore differences in Id string
136 rm -f "$DEST.lastcheck"
137 if [ -f "$DEST" ]; then
138 if cat "$DEST" |
sed 's|\$''Id''[^$]*\$|$''Id''$|' |
cmp - "$DEST.new" >/dev
/null
; then
140 touch "$DEST.lastcheck"
141 echo "$DEST is already up to date"
144 mv "$DEST" "$DEST.old"
147 mv "$DEST.new" "$DEST"
149 echo "$DEST updated from $location"