-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-px4-drv
executable file
·208 lines (179 loc) · 3.96 KB
/
install-px4-drv
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/bin/sh
set -eu
PROGNAME=$(basename $0)
BASEDIR=$(cd $(dirname $0); pwd)
# Original: https://github.com/nns779/px4_drv
GITHUB_URL=https://github.com/tsukumijima/px4_drv
DKMS=no
VERSION=0.4.4
LINUX_HEADERS=
ACTION=
DEPS="ca-certificates curl gcc make unzip"
help() {
cat <<EOF >&2
Install/Uninstall px4_drv
Usage:
$PROGNAME -h | --help
$PROGNAME [--dkms] [--tag <version>] install
$PROGNAME [--dkms] uninstall
$PROGNAME [--dkms] [--tag <version>] update
Options:
-h, --help
Show help.
--dkms
Use DKMS.
--tag <version> [default: $VERSION]
Version to install.
Actions:
install
Install the driver.
uninstall
Uninstall the driver.
update
Update the driver. Make sure the driver has already been installed before
updating.
EOF
exit 0
}
error() {
echo "$1" >&2
exit 1
}
distro() {
cat /etc/os-release | grep -E '^ID=' | cut -d '=' -f 2
}
install_firmware() {
echo "Installing firmware..."
(cd /tmp/px4_drv/fwtool \
&& make -j $(nproc) \
&& curl http://plex-net.co.jp/plex/pxw3u4/pxw3u4_BDA_ver1x64.zip -fSL >pxw3u4_BDA_ver1x64.zip \
&& unzip -oj pxw3u4_BDA_ver1x64.zip pxw3u4_BDA_ver1x64/PXW3U4.sys \
&& ./fwtool PXW3U4.sys it930x-firmware.bin \
&& sudo mkdir -p /lib/firmware \
&& sudo cp it930x-firmware.bin /lib/firmware/)
}
uninstall_firmware() {
echo "Removing firmware..."
sudo rm -f /lib/firmware/it930x-firmware.bin
}
install_dkms_driver() {
echo "Installing px4_drv/$VERSION using dkms..."
(cd /tmp/px4_drv \
&& sudo cp -a ./ /usr/src/px4_drv-$VERSION \
&& sudo dkms add -m px4_drv -v $VERSION \
&& sudo dkms install -m px4_drv -v $VERSION)
}
uninstall_dkms_driver() {
# Uninstall only the first px4_drv.
# Run multiple times if you install multiple versions of px4_drv.
V=$(sudo dkms status | grep px4_drv | head -1 | cut -d ',' -f 1 | cut -d '/' -f 2)
if [ -n $V ]
then
echo "Removing px4_drv/$V installed using dkms..."
sudo dkms remove -m px4_drv -v $V --all
sudo rm -rf /usr/src/px4_drv-$V
else
echo "No px4_drv installed"
fi
}
install_driver() {
echo "Installing px4_drv/$VERSION..."
(cd /tmp/px4_drv/driver && make && sudo make install)
}
uninstall_driver() {
V=$(sudo modinfo px4_drv | grep -E '^version' | cut -d ':' -f 2 | tr -d ' ')
if [ -n $V ]
then
echo "Removing px4_drv/$V..."
(cd /tmp/px4_drv/driver && sudo make uninstall)
else
echo "No px4_drv installed"
fi
}
while [ $# -gt 0 ]
do
case "$1" in
'-h' | '--help')
help
;;
'--dkms')
DKMS=yes
shift
;;
'--tag')
VERSION="$2"
shift 2
;;
'install')
ACTION=install
break
;;
'uninstall')
ACTION=uninstall
break
;;
'update')
ACTION=update
break
;;
esac
done
if [ -z "$ACTION" ]
then
error "Specify action (install|uninstall|update)"
fi
if [ "$DKMS" = yes ]
then
DEPS="$DEPS dkms"
fi
echo "Installing deps..."
case "$(distro)" in
arch)
sudo pacman -S --noconfirm $DEPS
;;
debian)
sudo apt-get update -qq
sudo apt-get install -y -qq --no-install-recommends $DEPS
;;
esac
mkdir /tmp/px4_drv
trap "rm -rf /tmp/px4_drv" EXIT
echo "Downloading $VERSION..."
curl $GITHUB_URL/tarball/v$VERSION -fSL | tar -zx -C /tmp/px4_drv --strip-components=1
echo "Enable workqueue"
sed -i 's/make KVER=${kernelver} /make KVER=${kernelver} ITEDTV_BUS_USE_WORKQUEUE=1 /' /tmp/px4_drv/dkms.conf
case "$ACTION" in
'install')
install_firmware
if [ "$DKMS" = yes ]
then
install_dkms_driver
else
install_driver
fi
;;
'uninstall')
if [ "$DKMS" = yes ]
then
uninstall_dkms_driver
else
uninstall_driver
fi
uninstall_firmware
;;
'update')
if [ "$DKMS" = yes ]
then
uninstall_dkms_driver
uninstall_firmware
install_firmware
install_dkms_driver
else
uninstall_driver
uninstall_firmware
install_firmware
install_driver
fi
;;
esac
echo "Done"