]> git.proxmox.com Git - mirror_smartmontools-debian.git/blobdiff - update-smart-drivedb.in
postrm: set -e
[mirror_smartmontools-debian.git] / update-smart-drivedb.in
index 467531abdce4137e9043ff193f7c2d402c22bec0..1b53a52c6521c99cff60cc6c0b73b4c0f5ff4c19 100644 (file)
@@ -2,7 +2,7 @@
 #
 # smartmontools drive database update script
 #
-# Copyright (C) 2010 Christian Franke <smartmontools-support@lists.sourceforge.net>
+# Copyright (C) 2010-14 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
@@ -12,7 +12,7 @@
 # You should have received a copy of the GNU General Public License
 # (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
 #
-# $Id: update-smart-drivedb.in 3072 2010-03-04 21:56:41Z chrfranke $
+# $Id: update-smart-drivedb.in 4019 2014-12-06 20:12:50Z chrfranke $
 #
 
 set -e
@@ -27,25 +27,20 @@ datarootdir="@datarootdir@"
 datadir="@datadir@"
 drivedbdir="@drivedbdir@"
 
+# Download tools
+os_dltools="@os_dltools@"
+
+# drivedb.h update branch
+BRANCH="@DRIVEDB_BRANCH@"
+
 # 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
-
+# 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 "
@@ -78,14 +73,21 @@ esac
 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
+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
@@ -96,12 +98,12 @@ for location in "branches/$BRANCH" "trunk"; do
   rm -f "$DEST.new"
   SRC="`eval echo "$SRCEXPR"`"
 
-  if eval $DOWNLOAD; then :; else
+  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)"
+  if grep -i '<title>.*Error has Occurred' "$DEST.new" >/dev/null; then
+    errmsg="download from $location failed (SF code browser error)"
     continue
   fi
 
@@ -120,16 +122,16 @@ chmod 0644 "$DEST.new"
 
 # Check syntax
 rm -f "$DEST.error"
-if $SMARTCTL -B "$DEST.new" -P showall >/dev/null; then :; else
+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
+# Keep old file if identical
 rm -f "$DEST.lastcheck"
 if [ -f "$DEST" ]; then
-  if cat "$DEST" | sed 's|\$''Id''[^$]*\$|$''Id''$|' | cmp - "$DEST.new" >/dev/null; 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"