]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - update-smart-drivedb.in
3 # smartmontools drive database update script
5 # Copyright (C) 2010 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 3072 2010-03-04 21:56:41Z chrfranke $
20 # Set by config.status
24 exec_prefix
="@exec_prefix@"
26 datarootdir
="@datarootdir@"
28 drivedbdir
="@drivedbdir@"
30 # Default drivedb location
31 DEST
="$drivedbdir/drivedb.h"
33 # Smartctl used for syntax check
34 SMARTCTL
="$sbindir/smartctl"
36 # Trac repository browser (does not return HTTP 404 errors)
37 #SRCEXPR='http://sourceforge.net/apps/trac/smartmontools/export/HEAD/$location/smartmontools/drivedb.h'
39 # ViewVC repository browser
40 SRCEXPR
='http://smartmontools.svn.sourceforge.net/viewvc/smartmontools/$location/smartmontools/drivedb.h?revision=HEAD'
42 # Convert version into branch name: 5.41[.X] -> "RELEASE_5_41_DRIVEDB"
43 BRANCH
="`echo $VERSION | sed -n 's|^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\([^0-9].*\)\?$|RELEASE_\1_\2_DRIVEDB|p'`"
45 if [ -z "$BRANCH" ]; then
46 echo "$0: syntax error in version number: $VERSION" >&2; exit 1
59 smartmontools $VERSION drive database update script
61 Usage: $0 [-v] [DESTFILE]
66 or DESTFILE from smartmontools SVN repository.
67 Tries to download first from branch $BRANCH
77 # Abort if 'which' is not available
78 which which >/dev
/null ||
exit 1
81 if which curl
>/dev
/null
2>/dev
/null
; then
82 DOWNLOAD
="curl ${q:+-s }"'-f -o "$DEST.new" "$SRC"'
83 elif which wget
>/dev
/null
2>/dev
/null
; then
84 DOWNLOAD
="wget $q"'-O "$DEST.new" "$SRC"'
85 elif which lynx
>/dev
/null
2>/dev
/null
; then
86 DOWNLOAD
='lynx -source "$SRC" >"$DEST.new"'
88 echo "$0: curl, wget or lynx not available" >&2; exit 1
91 # Try possible branch first, then trunk
92 for location
in "branches/$BRANCH" "trunk"; do
93 test -n "$q" ||
echo "Download from $location"
97 SRC
="`eval echo "$SRCEXPR"`"
99 if eval $DOWNLOAD; then :; else
100 errmsg
="download from $location failed (HTTP error)"
103 if grep -i 'ViewVC Exception' "$DEST.new" >/dev
/null
; then
104 errmsg
="download from $location failed (ViewVC error)"
111 if [ -n "$errmsg" ]; then
113 echo "$0: $errmsg" >&2
117 # Adjust timestamp and permissions
119 chmod 0644 "$DEST.new"
123 if $SMARTCTL -B "$DEST.new" -P showall
>/dev
/null
; then :; else
124 mv "$DEST.new" "$DEST.error"
125 echo "$DEST.error: rejected by $SMARTCTL, probably no longer compatible" >&2
129 # Keep old file if identical, ignore differences in Id string
130 rm -f "$DEST.lastcheck"
131 if [ -f "$DEST" ]; then
132 if cat "$DEST" |
sed 's|\$''Id''[^$]*\$|$''Id''$|' |
cmp - "$DEST.new" >/dev
/null
; then
134 touch "$DEST.lastcheck"
135 echo "$DEST is already up to date"
138 mv "$DEST" "$DEST.old"
141 mv "$DEST.new" "$DEST"
143 echo "$DEST updated from $location"