#! /bin/sh # # smartmontools drive database update script # # Copyright (C) 2010-13 Christian Franke # # 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 . # # $Id: update-smart-drivedb.in 3814 2013-06-04 19:38:25Z chrfranke $ # set -e # Set by config.status PACKAGE="smartmontools" VERSION="6.2" prefix="/usr" exec_prefix="/usr" sbindir="/usr/sbin" datarootdir="${prefix}/share" datadir="/usr/share" drivedbdir="${datadir}/${PACKAGE}" # Download tools os_dltools="curl wget lynx" # drivedb.h update branch BRANCH="RELEASE_6_2_DRIVEDB" # Default drivedb location DEST="$drivedbdir/drivedb.h" # Smartctl used for syntax check SMARTCTL="$sbindir/smartctl" # Download URL for sourceforge code browser SRCEXPR='http://sourceforge.net/p/smartmontools/code/HEAD/tree/$location/smartmontools/drivedb.h?format=raw' # Parse options q="-q " case "$1" in -v) q=; shift ;; esac case "$*" in -*|*\ *) cat </dev/null || exit 1 # Find download tool DOWNLOAD= for t in $os_dltools; do if which $t >/dev/null 2>/dev/null; then case $t in curl) DOWNLOAD="curl ${q:+-s }"'-f -o "$DEST.new" "$SRC"' ;; lynx) DOWNLOAD='lynx -source "$SRC" >"$DEST.new"' ;; wget) DOWNLOAD="wget $q"'-O "$DEST.new" "$SRC"' ;; fetch) DOWNLOAD='fetch -o "$DEST.new" "$SRC"' ;; # FreeBSD ftp) DOWNLOAD='ftp -o "$DEST.new" "$SRC"' ;; # OpenBSD esac break fi done if [ -z "$DOWNLOAD" ]; then echo "$0: found none of: $os_dltools" >&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 '.*Error has Occurred' "$DEST.new" >/dev/null; then errmsg="download from $location failed (SF code browser 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 rm -f "$DEST.lastcheck" if [ -f "$DEST" ]; then if cmp "$DEST" "$DEST.new" >/dev/null 2>/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"