File: driver-version.sh

package info (click to toggle)
intel-compute-runtime 25.27.34303.9-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 76,556 kB
  • sloc: cpp: 886,192; lisp: 3,433; sh: 715; makefile: 159; python: 21
file content (90 lines) | stat: -rwxr-xr-x 1,991 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash

#
# Copyright (C) 2019-2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
#

check_deb() {
    DriverVer=$(dpkg -l 'intel-opencl' | awk '/ii  intel-opencl / { print $3 }')
    if [ -z $DriverVer ]
    then
        DriverVer=$(dpkg -l 'intel-opencl-icd' | awk '/ii  intel-opencl-icd / { print $3 }')
    fi
}

check_rpm() {
    DriverVer=$(rpm -q --queryformat '%{VERSION}' intel-opencl)
    if [ $? != 0 ]
    then
        DriverVer=""
    fi
}

check_pacman() {
    DriverVer=$(pacman -Q intel-compute-runtime | awk '{print $2}' | sed "s/-.*$//")
}

if [ -f /etc/os-release ]
then
    source /etc/os-release
    if [ -z "${ID}" ]
    then
        echo "Unknown OS"
        exit 1
    fi
fi

case "${ID}" in
    debian | ubuntu ) check_deb
        ;;
    fedora | centos | rhel) check_rpm
        ;;
    arch ) check_pacman
        ;;
    * ) echo "Unsupported OS: ${ID}"
        exit 1
        ;;
esac

if [ -z $DriverVer ]
then
    echo No driver detected in the system
    exit 1
fi

if [ $# -eq 0 ]
then
    echo $DriverVer
    exit 1
fi


if [ $# -ne 1 ] || [ $1 == "-h" ] || [ $1 == "--help" ]
then
    echo $0 called with no parameters, prints the version of the installed OpenCL driver
    echo $0 called with a single parameter containing expected version number,
    echo returns success \(0\) if installed the specified driver version or newer
    echo returns failure \(1\) if no driver or older than specified
    exit 1
fi

if ! [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+.* ]]; then
    echo Invalid version format
    exit 1
fi

TestedString=$(echo "$1" | awk -F. '{ printf("%d.%02d.%d\n", $1,$2,$3); }';)

DriverStatus=$( echo -e "${DriverVer}\n${TestedString}"  | sort -V -C -r ; echo $? )

if [ $DriverStatus -eq 1 ]
then
    echo Driver $DriverVer is older than referenced version passed from command line ${TestedString}
else
    echo Driver $DriverVer is newer than or equal to referenced version passed from command line ${TestedString}
fi

exit $DriverStatus