]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - update-smart-drivedb.in
3 # smartmontools drive database update script
5 # Copyright (C) 2010-16 Christian Franke
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)
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/>.
15 # $Id: update-smart-drivedb.in 4224 2016-02-26 20:29:24Z chrfranke $
20 # Set by config.status
24 exec_prefix
="@exec_prefix@"
26 datarootdir
="@datarootdir@"
28 drivedbdir
="@drivedbdir@"
31 os_dltools
="@os_dltools@"
33 # drivedb.h update branch
34 BRANCH
="@DRIVEDB_BRANCH@"
36 # Default drivedb location
37 DRIVEDB
="$drivedbdir/drivedb.h"
39 # Smartctl used for syntax check
40 SMARTCTL
="$sbindir/smartctl"
47 smartmontools $VERSION drive database update script
49 Usage: $myname [OPTIONS] [DESTFILE]
51 -s SMARTCTL Use SMARTCTL for syntax check ('-s -' to disable)
53 -t TOOL Use TOOL for download: $os_dltools
54 [default: first one found in PATH]
55 -u LOCATION Use URL of LOCATION for download:
56 sf (Sourceforge code browser via HTTPS)
57 svn (SVN repository via HTTPS) [default]
58 svni (SVN repository via HTTP)
59 trac (Trac code browser via HTTPS)
60 --cacert FILE Use CA certificates from FILE to verify the peer
61 --capath DIR Use CA certificate files from DIR to verify the peer
62 --insecure Don't abort download if certificate verification fails
63 --dryrun Print download commands only
67 or DESTFILE from smartmontools SVN repository.
68 Tries to download first from branch $BRANCH
76 echo "$myname: $*" >&2
82 echo "$myname: (Warning) $*" >&2
88 sf
) url
='https://sourceforge.net/p/smartmontools/code/HEAD/tree/trunk/smartmontools/drivedb.h?format=raw' ;;
89 svn
) url
='https://svn.code.sf.net/p/smartmontools/code/trunk/smartmontools/drivedb.h' ;;
90 svni
) url
='http://svn.code.sf.net/p/smartmontools/code/trunk/smartmontools/drivedb.h' ;;
91 trac
) url
='https://www.smartmontools.org/export/HEAD/trunk/smartmontools/drivedb.h' ;;
103 test -f "$d/$1" ||
continue
104 test -x "$d/$1" ||
continue
114 test -n "$q" ||
echo "$*"
117 # vrun COMMAND ARGS...
120 if [ -n "$dryrun" ]; then
122 elif [ -n "$q" ]; then
130 # vrun2 OUTFILE COMMAND ARGS...
136 if [ -n "$dryrun" ]; then
140 err
=`"$@" 2>&1 > $f` || rc
=$?
141 if [ -n "$err" ]; then
143 test $rc != 0 || rc
=42
158 vrun curl
${q:+-s} -f --max-redirs 0 \
159 ${cacert:+--cacert "$cacert"} \
160 ${capath:+--capath "$capath"} \
161 ${insecure:+--insecure} \
162 -o "$f" "$u" || rc
=$?
166 vrun wget
$q --max-redirect=0 \
167 ${cacert:+--ca-certificate="$cacert"} \
168 ${capath:+--ca-directory="$capath"} \
169 ${insecure:+--no-check-certificate} \
170 -O "$f" "$u" || rc
=$?
174 test -z "$cacert" || vrun
export SSL_CERT_FILE
="$cacert"
175 test -z "$capath" || vrun
export SSL_CERT_DIR
="$capath"
176 # Check also stderr as lynx does not return != 0 on HTTP error
177 vrun2
"$f" lynx
-stderr -noredir -source "$u" || rc
=$?
182 --non-interactive --no-auth-cache \
183 ${cacert:+--config-option "servers:global:ssl-trust-default-ca=no"} \
184 ${cacert:+--config-option "servers:global:ssl-authority-files=$cacert"} \
185 ${insecure:+--trust-server-cert} \
190 vrun fetch
$q --no-redirect \
191 ${cacert:+--ca-cert "$cacert"} \
192 ${capath:+--ca-path "$capath"} \
193 ${insecure:+--no-verify-hostname} \
194 -o "$f" "$u" || rc
=$?
199 ${cacert:+-S cafile="$cacert"} \
200 ${capath:+-S capath="$capath"} \
201 ${insecure:+-S dont} \
202 -o "$f" "$u" || rc
=$?
205 *) error
"$tool: unknown (internal error)" ;;
220 while true
; do case $1 in
222 shift; test -n "$1" || usage
227 case $1 in *\
*) usage
;; esac
228 case " $os_dltools " in *\
$1\
*) ;; *) usage
;; esac
232 shift; selecturl
"$1" ;;
241 shift; test -n "$1" || usage
245 shift; test -n "$1" || usage
264 if [ -z "$tool" ]; then
265 # Find download tool in PATH
266 for t
in $os_dltools; do
272 test -n "$tool" || error
"found none of: $os_dltools"
275 test -n "$url" || selecturl
"svn"
277 # Check option compatibility
279 svn
:http
*://svn.code.sf.net
*) ;;
280 svn
:*) error
"'-t svn' requires '-u svn' or '-u svni'" ;;
282 case "$tool:${capath:+set}" in
283 svn
:set) warning
"'--capath' is ignored if '-t svn' is used" ;;
285 case "${insecure:-f}:$url" in
286 t
:http
:*) insecure
= ;;
288 *) error
"'-u svni' requires '--insecure'" ;;
290 case "$tool:$insecure" in
291 lynx
:t
) warning
"'--insecure' is ignored if '-t lynx' is used" ;;
294 # Try possible branch first, then trunk
297 for location
in "branches/$BRANCH" "trunk"; do
298 test -z "$errmsg" || errmsg2
=$errmsg
299 vecho
"Download from $location with $tool"
304 *) src
=`echo "$url" | sed "s,/trunk/,/$location/,"` ;;
308 test -n "$dryrun" ||
rm -f "$DEST.new" ||
exit 1
310 download
"$src" "$DEST.new" || rc
=$?
311 test -z "$dryrun" ||
continue
314 if [ $rc != 0 ]; then
315 errmsg
="download from $location failed ($tool: exit $rc)"
319 # Check file contents
320 case `sed 1q "$DEST.new"` in
323 errmsg
="download from $location failed (HTML error message)"
326 errmsg
="download from $location failed (Unknown file contents)"
331 size
=`wc -c < "$DEST.new"`
332 if [ "$size" -lt 10000 ]; then
333 errmsg
="download from $location failed (too small file size $size bytes)"
336 if [ "$size" -gt 1000000 ]; then
337 errmsg
="download from $location failed (too large file size $size bytes)"
344 test -z "$dryrun" ||
exit 0
346 if [ -n "$errmsg" ]; then
348 test -z "$errmsg2" ||
echo "$myname: $errmsg2" >&2
352 # Adjust timestamp and permissions
354 chmod 0644 "$DEST.new"
356 if [ "$smtctl" != "-" ]; then
359 if "$smtctl" -B "$DEST.new" -P showall
>/dev
/null
; then
360 test -n "$q" ||
echo "$smtctl: syntax OK"
362 mv "$DEST.new" "$DEST.error"
363 echo "$DEST.error: rejected by $smtctl, probably no longer compatible" >&2
368 # Keep old file if identical, ignore missing Id keyword expansion in new file
369 rm -f "$DEST.lastcheck"
370 if [ -f "$DEST" ]; then
371 if cmp "$DEST" "$DEST.new" >/dev
/null
2>/dev
/null \
372 ||
cat "$DEST" |
sed 's|\$''Id''[^$]*\$|$''Id''$|' \
373 |
cmp - "$DEST.new" >/dev
/null
2>/dev
/null
; then
375 touch "$DEST.lastcheck"
376 echo "$DEST is already up to date"
379 mv "$DEST" "$DEST.old"
382 mv "$DEST.new" "$DEST"
384 echo "$DEST updated from $location"