diff --git a/smartmontools/CHANGELOG b/smartmontools/CHANGELOG index f3d47a35da179509bd5dd71fa15c490ebf5690f0..c650002d924c113e26e4d6dbe29e84543254f2ac 100644 --- a/smartmontools/CHANGELOG +++ b/smartmontools/CHANGELOG @@ -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 diff --git a/smartmontools/Makefile.am b/smartmontools/Makefile.am index bf6ecc277601942400ae4358fc3439f71ea3443a..2304291e490277813b7ae4790b594bb82ffe1bca 100644 --- a/smartmontools/Makefile.am +++ b/smartmontools/Makefile.am @@ -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 \ diff --git a/smartmontools/NEWS b/smartmontools/NEWS index 12e37973c498f8c4436c1f3bdc4613f5ac55328b..a1b9fcae7c405d200043197a16aa09211a0bbfaf 100644 --- a/smartmontools/NEWS +++ b/smartmontools/NEWS @@ -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. diff --git a/smartmontools/os_win32/smartctl_vc8.vcproj b/smartmontools/os_win32/smartctl_vc8.vcproj index d53105252e1bd1d7bd15c7bc091d555ff38546aa..980ff787f23c3d09029980d1f68f3577b9be3c26 100644 --- a/smartmontools/os_win32/smartctl_vc8.vcproj +++ b/smartmontools/os_win32/smartctl_vc8.vcproj @@ -1037,6 +1037,10 @@ RelativePath="..\TODO" > </File> + <File + RelativePath="..\update-smart-drivedb.in" + > + </File> <File RelativePath="..\utility.cpp" > diff --git a/smartmontools/os_win32/smartd_vc8.vcproj b/smartmontools/os_win32/smartd_vc8.vcproj index 2f7b69b9060ef7b86640a1d70ceab3227019bc58..807d4a2f0f5678355a1d2510a75a9571b69e6204 100644 --- a/smartmontools/os_win32/smartd_vc8.vcproj +++ b/smartmontools/os_win32/smartd_vc8.vcproj @@ -989,6 +989,10 @@ RelativePath="..\TODO" > </File> + <File + RelativePath="..\update-smart-drivedb.in" + > + </File> <File RelativePath="..\utility.cpp" > diff --git a/smartmontools/smartctl.8.in b/smartmontools/smartctl.8.in index a855c1cbb7278c9fec0647e66d87a0f56ec753bc..a2245cc828f46370573472986a0927ef48c1a9a6 100644 --- a/smartmontools/smartctl.8.in +++ b/smartmontools/smartctl.8.in @@ -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 diff --git a/smartmontools/update-smart-drivedb.in b/smartmontools/update-smart-drivedb.in new file mode 100644 index 0000000000000000000000000000000000000000..0f4ac7e1912dc1939f1e7481ae9d7764dbcb9a04 --- /dev/null +++ b/smartmontools/update-smart-drivedb.in @@ -0,0 +1,144 @@ +#! /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" +