]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - update-smart-drivedb.in
Correct maintscript syntax
[mirror_smartmontools-debian.git] / update-smart-drivedb.in
CommitLineData
7f0798ef
GI
1#! /bin/sh
2#
3# smartmontools drive database update script
4#
3d17a85c 5# Copyright (C) 2010-13 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#
3d17a85c 15# $Id: update-smart-drivedb.in 3814 2013-06-04 19:38:25Z 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
3d17a85c
GI
42# Download URL for sourceforge code browser
43SRCEXPR='http://sourceforge.net/p/smartmontools/code/HEAD/tree/$location/smartmontools/drivedb.h?format=raw'
7f0798ef
GI
44
45# Parse options
46q="-q "
47case "$1" in
48 -v) q=; shift ;;
49esac
50
51case "$*" in
52 -*|*\ *)
53 cat <<EOF
54smartmontools $VERSION drive database update script
55
56Usage: $0 [-v] [DESTFILE]
57
58 -v verbose output
59
60Updates $DEST
61or DESTFILE from smartmontools SVN repository.
62Tries to download first from branch $BRANCH
63and then from trunk.
64EOF
65 exit 1
66 ;;
67
68 "") ;;
69 *) DEST="$1" ;;
70esac
71
72# Abort if 'which' is not available
73which which >/dev/null || exit 1
74
75# Find download tool
cfbba5b9
GI
76DOWNLOAD=
77for t in $os_dltools; do
78 if which $t >/dev/null 2>/dev/null; then
79 case $t in
80 curl) DOWNLOAD="curl ${q:+-s }"'-f -o "$DEST.new" "$SRC"' ;;
81 lynx) DOWNLOAD='lynx -source "$SRC" >"$DEST.new"' ;;
82 wget) DOWNLOAD="wget $q"'-O "$DEST.new" "$SRC"' ;;
83 fetch) DOWNLOAD='fetch -o "$DEST.new" "$SRC"' ;; # FreeBSD
84 ftp) DOWNLOAD='ftp -o "$DEST.new" "$SRC"' ;; # OpenBSD
85 esac
86 break
87 fi
88done
89if [ -z "$DOWNLOAD" ]; then
90 echo "$0: found none of: $os_dltools" >&2; exit 1
7f0798ef
GI
91fi
92
93# Try possible branch first, then trunk
94for location in "branches/$BRANCH" "trunk"; do
95 test -n "$q" || echo "Download from $location"
96
97 errmsg=
98 rm -f "$DEST.new"
99 SRC="`eval echo "$SRCEXPR"`"
100
cfbba5b9 101 if (eval $DOWNLOAD); then :; else
7f0798ef
GI
102 errmsg="download from $location failed (HTTP error)"
103 continue
104 fi
3d17a85c
GI
105 if grep -i '<title>.*Error has Occurred' "$DEST.new" >/dev/null; then
106 errmsg="download from $location failed (SF code browser error)"
7f0798ef
GI
107 continue
108 fi
109
110 break
111done
112
113if [ -n "$errmsg" ]; then
114 rm -f "$DEST.new"
115 echo "$0: $errmsg" >&2
116 exit 1
117fi
118
119# Adjust timestamp and permissions
120touch "$DEST.new"
121chmod 0644 "$DEST.new"
122
123# Check syntax
124rm -f "$DEST.error"
125if $SMARTCTL -B "$DEST.new" -P showall >/dev/null; then :; else
126 mv "$DEST.new" "$DEST.error"
127 echo "$DEST.error: rejected by $SMARTCTL, probably no longer compatible" >&2
128 exit 1
129fi
130
3d17a85c 131# Keep old file if identical
7f0798ef
GI
132rm -f "$DEST.lastcheck"
133if [ -f "$DEST" ]; then
3d17a85c 134 if cmp "$DEST" "$DEST.new" >/dev/null 2>/dev/null; then
7f0798ef
GI
135 rm -f "$DEST.new"
136 touch "$DEST.lastcheck"
137 echo "$DEST is already up to date"
138 exit 0
139 fi
140 mv "$DEST" "$DEST.old"
141fi
142
143mv "$DEST.new" "$DEST"
144
145echo "$DEST updated from $location"
146