diff --git a/.gitignore b/.gitignore index 91960d3..e214bc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ packages LinuxSDK +LatestLinuxSDK +VERSION tmp *.deb *.rpm diff --git a/build-dektec-dkms b/build-dektec-dkms index 148abaf..29efc7b 100755 --- a/build-dektec-dkms +++ b/build-dektec-dkms @@ -40,7 +40,7 @@ INSTALL=false export KEEP=false PREPARE_ONLY=false UNINSTALL=false -URL="http://www.dektec.com/products/SDK/DTAPI/Downloads/LinuxSDK.tar.gz" +URL="http://www.dektec.com/products/SDK/DTAPI/Downloads/LatestLinuxSDK" VERBOSE=false PATCH_OPTION="--silent" @@ -167,19 +167,25 @@ while [[ $# -gt 0 ]]; do done CONFDIR="$SCRIPTDIR/config" -TARBALL="$SCRIPTDIR/"$(basename "$URL") SDKDIR="$SCRIPTDIR/LinuxSDK" DTAPI_H="$SDKDIR/DTAPI/Include/DTAPI.h" PKGDIR="$SCRIPTDIR/packages" export TMPDIR="$SCRIPTDIR/tmp" +# The download URL is a generic one ending in ../LatestLinuxSDK. +# The actual file is redirected as ../LinuxSDK_v5.06.2017.0.tar.gz for instance. +# The file VERSION is created to contain the actual file name. + +TARBASE="$SCRIPTDIR/LinuxSDK" +VERSFILE="$SCRIPTDIR/VERSION" + #----------------------------------------------------------------------------- # Special cleanup operation. #----------------------------------------------------------------------------- if $CLEAN; then verbose "cleaning up non-original files" - rm -rf "$TARBALL" "$SDKDIR" "$TMPDIR" + rm -rf "${TARBASE}*" "$SDKDIR" "$TMPDIR" "$VERSFILE" cleanexit 0 fi @@ -189,11 +195,25 @@ fi # Download the LinuxSDK if not present. [[ -n "$URL" ]] || error "empty URL specified" -if $FORCE || [[ ! -e "$TARBALL" ]]; then +TARNAME=$(cat "$VERSFILE" 2>/dev/null) +TARBALL="$SCRIPTDIR/$TARNAME" +if $FORCE || [[ -z "$TARNAME" ]] || [[ ! -e "$TARBALL" ]]; then verbose "downloading $URL" - wget "$URL" -O "$TARBALL" || cleanexit 1 + mkdir -p "$TMPDIR" + # Do not download/redirect, just get the HTTP headers + curl -D "$TMPDIR/HEADERS" "$URL" || cleanexit 1 + TARNAME=$(grep -i Location: "$TMPDIR/HEADERS" | sed -e 's/.*: *//' -e 's/.*\///' -e 's/\r//g') + TARBALL="$SCRIPTDIR/$TARNAME" + [[ -n "$TARNAME" ]] || error "relocation header not found" + verbose "actual file name: $TARNAME" + echo "$TARNAME" >"$VERSFILE" + curl -L "$URL" -o "$TARBALL" || cleanexit 1 fi +# Get the Linux SDL version from the file name. +VERSION=$(sed <<<$TARNAME -e 's/LinuxSDK_v//' -e 's/\.tar\.gz//g' -e 's/\.tgz//g') +verbose "package version is $VERSION" + # Expand the LinuxSDK if newer than the expanded files. if $FORCE || [[ ! -e "$DTAPI_H" || "$TARBALL" -nt "$DTAPI_H" ]]; then verbose "expanding $TARBALL" @@ -203,19 +223,6 @@ if $FORCE || [[ ! -e "$DTAPI_H" || "$TARBALL" -nt "$DTAPI_H" ]]; then find "$SDKDIR" -print0 | xargs -0 touch fi -# The identification of the version of LinuxSDK is problematic. There is no -# unique version number. A LinuxSDK is informally identified by a date such -# as "Feb 2017" for instance. But this identification is not present inside -# the distribution. Otherwise, there are distinct version numbers for DTAPI -# and each driver: Dta, Dtu and DtaNw. As a compromise, we use the DTAPI -# version number for the complete LinuxSDK distribution. -VERSION_MAJOR=$(grep '\#define *DTAPI_VERSION_MAJOR ' "$DTAPI_H" | sed -e 's/ *$//' -e 's/.* //') -VERSION_MINOR=$(grep '\#define *DTAPI_VERSION_MINOR ' "$DTAPI_H" | sed -e 's/ *$//' -e 's/.* //') -VERSION_BUGFIX=$(grep '\#define *DTAPI_VERSION_BUGFIX ' "$DTAPI_H" | sed -e 's/ *$//' -e 's/.* //') -VERSION_BUILD=$(grep '\#define *DTAPI_VERSION_BUILD ' "$DTAPI_H" | sed -e 's/ *$//' -e 's/.* //') -VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_BUGFIX.$VERSION_BUILD" -verbose "package version is $VERSION" - SRCDIR="$TMPDIR/dektec-dkms-$VERSION" DKMS_DIR="$SRCDIR/dektec-$VERSION" DKMS_INSTALL="/usr/src/dektec-$VERSION" diff --git a/config/dektec-dkms.spec b/config/dektec-dkms.spec index ecb04ba..c69f441 100644 --- a/config/dektec-dkms.spec +++ b/config/dektec-dkms.spec @@ -10,6 +10,7 @@ Source0: dektec-dkms-%{version}.tgz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch Requires: dkms +Requires: elfutils-libelf-devel %description Provide the source code and DKMS setup for the kernel modules of the Dektec