forked from vencik/psmouse-dkms-alpsv7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·80 lines (65 loc) · 2.01 KB
/
install.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
#!/bin/bash
source ./dkms.conf
MDIR="/lib/modules/$(uname -r)"
NEWMDIR="$MDIR/${DEST_MODULE_LOCATION[0]}"
MFILE="$MDIR/kernel/drivers/input/mouse/${BUILT_MODULE_NAME[0]}.ko"
NEWMFILE="$NEWMDIR/${BUILT_MODULE_NAME[0]}.ko"
M=psmouse-dkms-alpsv7
V=1.1
#Print error message and exit
abort()
{
echo "▶▶▶▶ Error: $1"
exit 2
}
#Make sure script is ran from base directory
if ! grep -q psmouse-dkms-alpsv7 dkms.conf; then
echo "Please run this script from the source directory for '$M'".
exit 1
fi
#Build module
echo "────── Building with dkms ───────"
echo
dkms add .
dkms build -m "$M" -v "$V" || abort "Build failed"
#Backup old module
if [ -f "$MFILE" ]; then
mv "$MFILE" "$MFILE.orig" || abort "Unable to backup old module. Aborting."
echo " ** Old module backed up as:"
echo " '$MFILE.orig'"
elif [ -f "$MFILE.gz" ]; then
mv "$MFILE.gz" "$MFILE.gz.orig" || abort "Unable to backup old module. Aborting."
echo " ** Old module backed up as:"
echo " '$MFILE.gz.orig'"
GZIP=.gz
fi
#Install module and gzip it if old module was gzipped
echo
echo
echo "────── Installing with dkms ───────"
echo
dkms install -m "$M" -v "$V" || abort "Install failed"
if [ -f "$NEWMFILE" ]; then
cp "$NEWMFILE" "$MFILE"
echo "Install succeded:"
echo " '$NEWMFILE' found and copied to:"
echo " '$MFILE'"
if [ "x$GZIP" = "x.gz" ]; then
echo "Original module was gzipped, gzipping new one."
gzip -9 "$MFILE" || echo "Unable to gzip new module. Continuing."
fi
else
abort "dkms install failed:\n '$NEWMFILE' not found."
fi
#Remove old module and modprobe new one
echo "──→ rmmod psmouse"
rmmod psmouse 2>&1 > /dev/null
echo "──→ modprobe psmouse"
if ! modprobe psmouse; then
#Restore backup if modprobe failed
echo "modprobe psmouse failed, restoring old module."
mv "$MFILE$GZIP.orig" "$MFILE$GZIP"
rmmod psmouse
modprobe psmouse || abort "Unable to modprobe old module! Sorry!"
fi
echo "ok."