This repository has been archived by the owner on Aug 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
common.sh
86 lines (78 loc) · 2.16 KB
/
common.sh
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
# default options
SYSCONFDIR=/etc
INCLUDEDIR=/usr/include
ARCH=k1om
INSTALL_CONFIG=1
INSTALL_HEADER=1
# parse some extra arguments
while [ $# -gt 0 ]; do
case "$1" in
--no-config )
INSTALL_CONFIG=0
shift ;;
--no-header )
INSTALL_HEADER=0
shift ;;
--sysconfdir )
[ $# -ge 2 ] || { echo "error: '$1' requires parameter" &1>2; exit 1; }
SYSCONFDIR="$2"
shift 2 ;;
--includedir )
[ $# -ge 2 ] || { echo "error: '$1' requires parameter" &1>2; exit 1; }
INCLUDEDIR="$2"
shift 2 ;;
-a | --arch )
[ $# -ge 2 ] || { echo "error: '$1' requires parameter" &1>2; exit 1; }
ARCH="$2"
shift 2 ;;
-\? | --help )
cat <<-END
$0 [options]
flags:
--no-config do not install config files into $SYSCONFDIR
--no-header do not install header files into $INCLUDEDIR
options:
--sysconfdir DIR common directory for system configuration files (default: $SYSCONFDIR)
--includedir DIR common directory for developer header files (default: $INCLUDEDIR)
-k, --kernel VERSION kernel version [manual install] (auto-detected)
-a, --arch ARCH driver architecture (default: $ARCH)
END
exit 0 ;;
* ) echo "error: unknown option '$1'" &1>2; exit 1 ;;
esac
done
# check if DKMS is present, otherwise show some instructions
if [ -z "$(which dkms 2>/dev/null)" ]; then
echo -n "$0 expects DKMS to be installed." 1>&2
if [ -n "$(which apt-get 2>/dev/null)" ]; then
echo " Try: 'sudo apt-get install dkms'"
elif [ -n "$(which yum 2>/dev/null)" ]; then
echo " Try: 'sudo yum install dkms'"
else
echo
echo "Install without DKMS using: 'make && sudo make install'"
fi
exit 1
fi
# require root
if [ $EUID -ne 0 ]; then
echo "$0 must be run as root. Try: 'sudo $0'" 1>&2
exit 1
fi
# get version information from Git tag
if [ -n "$(which git 2>/dev/null)" ]; then
TAG=$(git describe)
TAG=${TAG%-g*} # strip Git version if any
VERSION=${TAG#*-}
NAME=${TAG%%-*}
else # fallback to .mpss-metadata if Git is not present
read VERSION < .mpss-metadata
NAME=mpss
TAG=$NAME-$VERSION
fi
# make sure VERSION and NAME are set
if [ -z "$VERSION" ] || [ -z "$NAME" ]; then
echo "Cannot find module version. Aborting." 1>&2
exit 1
fi
SRC="/usr/src/$TAG"