Skip to content
Snippets Groups Projects
Commit a27d8701 authored by chrfranke's avatar chrfranke
Browse files

Add 'update-smart-drivedb' script (ticket #59).

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@3072 4ea69e1a-61f1-4043-bf83-b5c94c648137
parent 22bcb1d3
No related branches found
No related tags found
No related merge requests found
......@@ -43,6 +43,10 @@ NOTES FOR FUTURE RELEASES: see TODO file.
<DEVELOPERS: ADDITIONS TO THE CHANGE LOG GO JUST BELOW HERE, PLEASE>
[CF] Add 'update-smart-drivedb' script (ticket #59).
The script updates the drive database from SVN.
It is installed if '--enable-drivedb' is configured.
[MS] drivedb.h updates:
- Seagate Medalist 1720
- SuperTalent UltraDrive GX SSD
......
......@@ -25,6 +25,11 @@ endif
sbin_PROGRAMS = smartd \
smartctl
if ENABLE_DRIVEDB
sbin_SCRIPTS = update-smart-drivedb
endif
smartd_SOURCES = smartd.cpp \
atacmdnames.cpp \
atacmdnames.h \
......@@ -327,6 +332,10 @@ smartd.conf.5.in: smartd.8.in
cat $(top_builddir)/tmp.tail >> $(srcdir)/smartd.conf.5.in
rm -f $(top_builddir)/tmp.head $(top_builddir)/tmp.tail $(top_builddir)/tmp.directives
update-smart-drivedb: update-smart-drivedb.in config.status
$(SHELL) ./config.status --file=$@
if INSTALL_INITSCRIPT
if OS_DARWIN
initd_DATA = SMART \
......
......@@ -12,6 +12,7 @@ Summary: smartmontools release 5.40
- configure: New default value for '--with-docdir'.
- Drive database is in a separate source file 'drivedb.h'
which can be downloaded from SVN.
- New script 'update-smart-drivedb'.
- smartd libcap-ng support, option '-C, --capabilities'.
- smartctl option '-l scterc[,...]' to get/set the
SCT Error Recovery Control time limit.
......
......@@ -1037,6 +1037,10 @@
RelativePath="..\TODO"
>
</File>
<File
RelativePath="..\update-smart-drivedb.in"
>
</File>
<File
RelativePath="..\utility.cpp"
>
......
......@@ -989,6 +989,10 @@
RelativePath="..\TODO"
>
</File>
<File
RelativePath="..\update-smart-drivedb.in"
>
</File>
<File
RelativePath="..\utility.cpp"
>
......
......@@ -1313,6 +1313,9 @@ If this option is not specified, optional entries are read from the file
.\" BEGIN ENABLE_DRIVEDB
If \fB/usr/local/share/smartmontools/drivedb.h\fP is present, the
contents of this file is used instead of the built in table.
Run the script \fB/usr/local/sbin/update-smart-drivedb\fP to update this
file from the smartmontools SVN repository.
.\" END ENABLE_DRIVEDB
The database files use the same C/C++ syntax that is used to initialize
......
#! /bin/sh
#
# smartmontools drive database update script
#
# Copyright (C) 2010 Christian Franke <smartmontools-support@lists.sourceforge.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# You should have received a copy of the GNU General Public License
# (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
#
# $Id$
#
set -e
# Set by config.status
PACKAGE="@PACKAGE@"
VERSION="@VERSION@"
prefix="@prefix@"
exec_prefix="@exec_prefix@"
sbindir="@sbindir@"
datarootdir="@datarootdir@"
datadir="@datadir@"
drivedbdir="@drivedbdir@"
# Default drivedb location
DEST="$drivedbdir/drivedb.h"
# Smartctl used for syntax check
SMARTCTL="$sbindir/smartctl"
# Trac repository browser (does not return HTTP 404 errors)
#SRCEXPR='http://sourceforge.net/apps/trac/smartmontools/export/HEAD/$location/smartmontools/drivedb.h'
# ViewVC repository browser
SRCEXPR='http://smartmontools.svn.sourceforge.net/viewvc/smartmontools/$location/smartmontools/drivedb.h?revision=HEAD'
# Convert version into branch name: 5.41[.X] -> "RELEASE_5_41_DRIVEDB"
BRANCH="`echo $VERSION | sed -n 's|^\([0-9][0-9]*\)\.\([0-9][0-9]*\)\([^0-9].*\)\?$|RELEASE_\1_\2_DRIVEDB|p'`"
if [ -z "$BRANCH" ]; then
echo "$0: syntax error in version number: $VERSION" >&2; exit 1
fi
# Parse options
q="-q "
case "$1" in
-v) q=; shift ;;
esac
case "$*" in
-*|*\ *)
cat <<EOF
smartmontools $VERSION drive database update script
Usage: $0 [-v] [DESTFILE]
-v verbose output
Updates $DEST
or DESTFILE from smartmontools SVN repository.
Tries to download first from branch $BRANCH
and then from trunk.
EOF
exit 1
;;
"") ;;
*) DEST="$1" ;;
esac
# Abort if 'which' is not available
which which >/dev/null || exit 1
# Find download tool
if which curl >/dev/null 2>/dev/null; then
DOWNLOAD="curl ${q:+-s }"'-f -o "$DEST.new" "$SRC"'
elif which wget >/dev/null 2>/dev/null; then
DOWNLOAD="wget $q"'-O "$DEST.new" "$SRC"'
elif which lynx >/dev/null 2>/dev/null; then
DOWNLOAD='lynx -source "$SRC" >"$DEST.new"'
else
echo "$0: curl, wget or lynx not available" >&2; exit 1
fi
# Try possible branch first, then trunk
for location in "branches/$BRANCH" "trunk"; do
test -n "$q" || echo "Download from $location"
errmsg=
rm -f "$DEST.new"
SRC="`eval echo "$SRCEXPR"`"
if eval $DOWNLOAD; then :; else
errmsg="download from $location failed (HTTP error)"
continue
fi
if grep -i 'ViewVC Exception' "$DEST.new" >/dev/null; then
errmsg="download from $location failed (ViewVC error)"
continue
fi
break
done
if [ -n "$errmsg" ]; then
rm -f "$DEST.new"
echo "$0: $errmsg" >&2
exit 1
fi
# Adjust timestamp and permissions
touch "$DEST.new"
chmod 0644 "$DEST.new"
# Check syntax
rm -f "$DEST.error"
if $SMARTCTL -B "$DEST.new" -P showall >/dev/null; then :; else
mv "$DEST.new" "$DEST.error"
echo "$DEST.error: rejected by $SMARTCTL, probably no longer compatible" >&2
exit 1
fi
# Keep old file if identical, ignore differences in Id string
rm -f "$DEST.lastcheck"
if [ -f "$DEST" ]; then
if cat "$DEST" | sed 's|\$''Id''[^$]*\$|$''Id''$|' | cmp - "$DEST.new" >/dev/null; then
rm -f "$DEST.new"
touch "$DEST.lastcheck"
echo "$DEST is already up to date"
exit 0
fi
mv "$DEST" "$DEST.old"
fi
mv "$DEST.new" "$DEST"
echo "$DEST updated from $location"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment