Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#1426 closed enhancement (fixed)

update-smart-drivedb: Allow update from other URLs or local files

Reported by: Paul Wise Owned by: Christian Franke
Priority: minor Milestone: Release 7.3
Component: all Version:
Keywords: Cc: onlyjob

Description

I think it would be nice if the Debian package maintainer did not have to re-implement the checks implemented by update-smart-drivedb (including the ones suggested in #1424) in the Debian postinstall script, so I suggest that a --local-dir option for update-smart-drivedb could be used to make it look at a local directory for the drivedb.h copy installed by the Debian package, perform the necessary checks and then update the canonical drivedb.h in /var. Then the Debian postinstall script could just run update-smart-drivedb --local-dir, passing the directory in the package where the necessary files are installed.

I have CCed onlyjob, the Debian package maintainer.

Change History (14)

comment:1 by Christian Franke, 3 years ago

Component: drivedball
Milestone: Release 7.3

comment:2 by Christian Franke, 3 years ago

Adding this to update-smart-drivedb will take some time due to required refactorings.

For now, here is a standalone script:

#!/bin/sh
set -e

test $# = 2 || { echo "Usage: $0 SOURCE_DB DEST_DB"; exit 1; }
src=$1; dst=$2

get_db_version()
{
  local r v x
  x=$(sed -n '/^[ {]*"VERSION: *[^"]*"/{s,^[ {]*"VERSION: \([1-9][./0-9]* [^"]*\)".*$,\1,p;q}' "$1")
  v=${x%% *}
  test -n "$v" || return 0
  if [ "${v%/*}" = "$v" ]; then # trunk: get rev from expanded SVN-Id
    r=$(echo "$x" | sed -n 's,^[^$]*$Id: drivedb\.h \([1-9][0-9]*\) .*$,\1,p')
    test -n "$r" || return 0
    v="$v/$r"
  fi
  echo "$v"
}

a=$(get_db_version "$src")
test -n "$a" || { echo "$src: VERSION information not found"; exit 1; }
b=$(test ! -e "$dst" || get_db_version "$dst")
test -n "$b" || b="0/0"

upd=true
if [ "${a#*/}" -lt "${b#*/}" ]; then
  if [ "${a%%/*}" = "${b%%/*}" ]; then
    upd=false
  else
    echo "Warning: $dst: requires downgrade due to branch change, run update-smart-drivedb" >&2
  fi
fi

if $upd; then
  echo "$dst: $b replaced with $a"
  cp -f "$src" "$dst"
  rm -f "$dst.raw" "$dst.raw.asc"
else
  echo "$dst: $b not replaced with $a"
fi

comment:3 by Paul Wise, 3 years ago

I forgot to mention that enabling the --local-dir option should disable the signature checks because there are multiple types of use-cases for this:

The Debian package does not include the signatures for drivedb.h.

The Debian drivedb.h could be patched compared to upstream, say in a Debian stable release or similar.

The user could be trying to install their own custom drivedb.h.

comment:4 by Christian Franke, 3 years ago

--no-verify could already be used to disable signature checks. Proposed syntax:

update-smart-drivedb [--no-verify] --local /src/dir/drivedb.h [/dest/dir/drivedb.h]

If --no-verify is not specified, /src/dir/drivedb.h.raw.asc must exist. This enables another use case: Offline updates for machines without internet connection.

comment:5 by Paul Wise, 3 years ago

Sounds good to me.

comment:6 by Christian Franke, 2 years ago

Owner: set to Christian Franke
Status: newaccepted

comment:7 by Christian Franke, 2 years ago

Summary: drivedb.h: update-smart-drivedb --local-dir optionupdate-smart-drivedb: Allow update from other URLs or local files

Will be implemented by an enhancement to the -u option. It will accept other URLs or local path names. Changing summary accordingly.

comment:8 by Paul Wise, 2 years ago

TBH, I think it is better to not merge two different namespaces (URLs and local files) and two different features (downloading files and loading files from disk) into one option.

comment:9 by Christian Franke, 2 years ago

Hmm... agree, so there will be new options --url and --file.

comment:10 by Christian Franke, 2 years ago

Resolution: fixed
Status: acceptedclosed

comment:11 by Christian Franke, 2 years ago

If possible, please test whether this works for your use case:

update-smart-drivedb --no-verify --file /src/dir/drivedb.h [/dest/dir/drivedb.h]

comment:12 by Christian Franke, 2 years ago

A further enhancement added in r5318:

To distribute drivedb.h separately, use for example:

./configure ... \
  --with-drivedbinstdir=/usr/share/smartmontools \
  --with-drivedbdir=/var/lib/smartmontools

Then make install installs /usr/share/smartmontools/drivedb.h but smartctl and smartd still use /var/lib/smartmontools/drivedb.h.

Include this in the package postinstall script:

/usr/sbin/update-smart-drivedb [--quiet] --install

This copies /usr/share/smartmontools/drivedb.h to /var/lib/smartmontools/drivedb.h except if an already present version is newer and on the same branch.

comment:13 by Paul Wise, 2 years ago

That is a perfect outcome, thanks for your work on this.

I'll convey these changes to the Debian bug about this.

https://bugs.debian.org/976696

comment:14 by Paul Wise, 2 years ago

That bug was closed and archived so I have filed a new bug about using the approach from comment:12 above:

https://bugs.debian.org/1006019

Note: See TracTickets for help on using tickets.