]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - update-smart-drivedb.in
Refreshed patches and removed patches applied upstream
[mirror_smartmontools-debian.git] / update-smart-drivedb.in
CommitLineData
7f0798ef
GI
1#! /bin/sh
2#
3# smartmontools drive database update script
4#
cfbba5b9 5# Copyright (C) 2010-11 Christian Franke <smartmontools-support@lists.sourceforge.net>
7f0798ef
GI
6#
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)
10# any later version.
11#
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/>.
14#
cfbba5b9 15# $Id: update-smart-drivedb.in 3294 2011-03-16 21:36:58Z chrfranke $
7f0798ef
GI
16#
17
18set -e
19
20# Set by config.status
21PACKAGE="@PACKAGE@"
22VERSION="@VERSION@"
23prefix="@prefix@"
24exec_prefix="@exec_prefix@"
25sbindir="@sbindir@"
26datarootdir="@datarootdir@"
27datadir="@datadir@"
28drivedbdir="@drivedbdir@"
29
cfbba5b9
GI
30# Download tools
31os_dltools="@os_dltools@"
32
33# drivedb.h update branch
34BRANCH="@DRIVEDB_BRANCH@"
35
7f0798ef
GI
36# Default drivedb location
37DEST="$drivedbdir/drivedb.h"
38
39# Smartctl used for syntax check
40SMARTCTL="$sbindir/smartctl"
41
42# Trac repository browser (does not return HTTP 404 errors)
43#SRCEXPR='http://sourceforge.net/apps/trac/smartmontools/export/HEAD/$location/smartmontools/drivedb.h'
44
45# ViewVC repository browser
46SRCEXPR='http://smartmontools.svn.sourceforge.net/viewvc/smartmontools/$location/smartmontools/drivedb.h?revision=HEAD'
47
7f0798ef
GI
48
49# Parse options
50q="-q "
51case "$1" in
52 -v) q=; shift ;;
53esac
54
55case "$*" in
56 -*|*\ *)
57 cat <<EOF
58smartmontools $VERSION drive database update script
59
60Usage: $0 [-v] [DESTFILE]
61
62 -v verbose output
63
64Updates $DEST
65or DESTFILE from smartmontools SVN repository.
66Tries to download first from branch $BRANCH
67and then from trunk.
68EOF
69 exit 1
70 ;;
71
72 "") ;;
73 *) DEST="$1" ;;
74esac
75
76# Abort if 'which' is not available
77which which >/dev/null || exit 1
78
79# Find download tool
cfbba5b9
GI
80DOWNLOAD=
81for t in $os_dltools; do
82 if which $t >/dev/null 2>/dev/null; then
83 case $t in
84 curl) DOWNLOAD="curl ${q:+-s }"'-f -o "$DEST.new" "$SRC"' ;;
85 lynx) DOWNLOAD='lynx -source "$SRC" >"$DEST.new"' ;;
86 wget) DOWNLOAD="wget $q"'-O "$DEST.new" "$SRC"' ;;
87 fetch) DOWNLOAD='fetch -o "$DEST.new" "$SRC"' ;; # FreeBSD
88 ftp) DOWNLOAD='ftp -o "$DEST.new" "$SRC"' ;; # OpenBSD
89 esac
90 break
91 fi
92done
93if [ -z "$DOWNLOAD" ]; then
94 echo "$0: found none of: $os_dltools" >&2; exit 1
7f0798ef
GI
95fi
96
97# Try possible branch first, then trunk
98for location in "branches/$BRANCH" "trunk"; do
99 test -n "$q" || echo "Download from $location"
100
101 errmsg=
102 rm -f "$DEST.new"
103 SRC="`eval echo "$SRCEXPR"`"
104
cfbba5b9 105 if (eval $DOWNLOAD); then :; else
7f0798ef
GI
106 errmsg="download from $location failed (HTTP error)"
107 continue
108 fi
109 if grep -i 'ViewVC Exception' "$DEST.new" >/dev/null; then
110 errmsg="download from $location failed (ViewVC error)"
111 continue
112 fi
113
114 break
115done
116
117if [ -n "$errmsg" ]; then
118 rm -f "$DEST.new"
119 echo "$0: $errmsg" >&2
120 exit 1
121fi
122
123# Adjust timestamp and permissions
124touch "$DEST.new"
125chmod 0644 "$DEST.new"
126
127# Check syntax
128rm -f "$DEST.error"
129if $SMARTCTL -B "$DEST.new" -P showall >/dev/null; then :; else
130 mv "$DEST.new" "$DEST.error"
131 echo "$DEST.error: rejected by $SMARTCTL, probably no longer compatible" >&2
132 exit 1
133fi
134
135# Keep old file if identical, ignore differences in Id string
136rm -f "$DEST.lastcheck"
137if [ -f "$DEST" ]; then
138 if cat "$DEST" | sed 's|\$''Id''[^$]*\$|$''Id''$|' | cmp - "$DEST.new" >/dev/null; then
139 rm -f "$DEST.new"
140 touch "$DEST.lastcheck"
141 echo "$DEST is already up to date"
142 exit 0
143 fi
144 mv "$DEST" "$DEST.old"
145fi
146
147mv "$DEST.new" "$DEST"
148
149echo "$DEST updated from $location"
150