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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# Maintainer: Chris Severance aur.severach aATt spamgourmet dott com
_opt_DKMS=1 # This can be toggled between installs
_opt_defaultmode='660' # default: 620
# Todo: Test secure mode
# Todo: python tools should be updated to python3
# Todo: nslinktool Config Driver needs an up down button to reorder entries
# Todo: TUI firmware updater.
# Todo: Comtrol icons for nslinktool and the firmware updater
# Todo: nslinktool set the mouse pointer to a spinning circle far too long after startup
# Todo: rm /dev/ttySI* on rmmod nslink
# Todo: nslinktool, HUB IP Admin, [Get] with SocketServer, error getting IP info, did not get ip6info reply
# Uninstall cleanup: sudo rm -f /etc/nslink.conf*
# Configure with the NS-Link Manager GUI, Config Driver
# Ports are /dev/ttySI0 through /dev/ttySI31
set -u
pkgname='nslink'
pkgver='7.28'
pkgrel='4'
pkgdesc='tty driver and firmware update for Comtrol DeviceMaster, RTS, LT, PRO, 500, UP, RPSH-SI, RPSH, and Serial port Hub console terminal device server'
# UP is not explicitly supported by NS-Link, only by the firmware updater.
_pkgdescshort="Comtrol DeviceMaster ${pkgname} TTY driver"
arch=('i686' 'x86_64')
url='http://www.comtrol.com/'
license=('GPL')
depends=('glibc' 'openssl' 'python2' 'sed' 'groff' 'tcl' 'tk' 'util-linux') # python is also needed for the firmware updater
optdepends=(
'gksu: NS-Link Manager GUI'
)
backup=('etc/nslink.conf')
options=('!zipman')
install="${pkgname}-install.sh"
_verwatch=('http://downloads.comtrol.com/html/DM_PRO_RTS_SERIALHUB_drivers.htm' '.*/devicemaster-linux-\([0-9\.]\+\)\.tar\.gz' 'l')
_srcdir="devicemaster-linux-${pkgver}"
_srcdir2='DM-Firmware-Updater-1.06' # http://downloads.comtrol.com/html/DM_PRO_RTS_SERIALHUB_pvdx2.htm
#source=("ftp://ftp.comtrol.com/dev_mstr/rts/drivers/linux/devicemaster-linux-${pkgver}.tar.gz")
source=("http://downloads.comtrol.com/dev_mstr/rts/drivers/linux/devicemaster-linux-${pkgver}.tar.gz")
#source+=('ftp://ftp.comtrol.com/dev_mstr/rts/utility/linux_firmware_uploader/DM-Firmware-Updater-1.06.tar.gz')
source+=('http://downloads.comtrol.com/dev_mstr/rts/utility/linux_firmware_uploader/DM-Firmware-Updater-1.06.tar.gz')
source+=('dmupdate.py.usage.patch')
source+=('0000-Invalid-MKDEV-macro.patch')
sha256sums=('900d0681a86d0732cf3e71e56a013456d5a77a68f7faa2afb955e275f73353fb'
'd21c5eeefdbf08a202a230454f0bf702221686ba3e663eb41852719bb20b75fb'
'5a4e2713a8d1fe0eebd94fc843839ce5daa647f9fa7d88f62507e660ae111073'
'6968b10cd66d783f86f587a03584e78af4a2766d223b8d5c24c3ea4fe79f7230'
'5c00939eb945c98336211cd61408b5a8623b01a7059356e663ccc638b0d159fb')
if [ "${_opt_DKMS}" -ne 0 ]; then
depends+=('linux' 'dkms' 'linux-headers')
else
makedepends+=('linux-headers')
fi
_opt_LEGACY_VER=''
# Install both versions so dkms gets the right version for each kernel
if [ "${_opt_DKMS}" -ne 0 ]; then
# 7.26 supports Kernels 2.6.33 through 4.14.x
# 7.28 supports Kernels 4.15 through 4.17.x.
_opt_LEGACY_VER='7.26'
if [ "$(vercmp "${pkgver}" "${_opt_LEGACY_VER}")" -gt 0 ]; then
_srcalt="${_srcdir//${pkgver}/${_opt_LEGACY_VER}}"
source+=("http://downloads.comtrol.com/legacy/dev_mstr/rts/drivers/linux/${_opt_LEGACY_VER}/${_srcalt}.tar.gz")
else
_opt_LEGACY_VER=''
fi
fi
_fn_patch_km() {
set +u; msg2 "patch_km $1"; set -u
# Fix permissions
find -type 'f' -perm '/111' -exec chmod 644 '{}' '+'
chmod 755 *.sh *.py 'nslinktool'
#diff -pNau5 nslinkd.c{.orig,} > '0000-Invalid-MKDEV-macro.patch'
patch -Nbup0 -i "${srcdir}/0000-Invalid-MKDEV-macro.patch"
# Version check
local _ver
_ver="$(sed -n -e 's:^#define\sSI_VERSION\s"\([^"]\+\).*$:\1:p' 'version.h')"
if [ "$1" != "${_ver}" ]; then
echo "Version mismatch $1 != ${_ver}"
set +u
false
fi
unset _ver
# Make package compatible
#cp -p 'install.sh' 'install.sh.Arch' # testmode for diff comparison
sed -e '# Fix some paths' \
-e 's: /lib/: /usr/lib/:g' \
-e 's: /sbin: /usr/bin:g' \
-e 's:"/sbin:"/usr/bin:g' \
-e 's:/usr/sbin:/usr/bin:g' \
-e 's:/usr/local/man:/usr/share/man:g' \
-e '# I suspect this folder for systemd is wrong even on RedHat' \
-e 's:/etc/systemd/system:/usr/lib/systemd/system:g' \
-e '# make package compatible' \
-e 's:"/etc/:"${DESTDIR}/etc/:g' \
-e 's: /etc/: "${DESTDIR}"/etc/:g' \
-e 's:"/usr/:"${DESTDIR}/usr/:g' \
-e 's: /usr/: "${DESTDIR}"/usr/:g' \
-e '# Disable module management and message' \
-e 's:^\s\+echo\s-n\s"Rebuilding:# &:g' \
-e 's:^.*depmod -a:# &:g' \
-e '# Disable systemd management' \
-e 's:^\s\+systemctl:# &:g' \
-e '# Get rid of the start messages lest someone believes them' \
-e 's:^\s\+if\s\[\s"$WillStart"\s=\syes\s\]:return\n&:g' \
-i 'install.sh'
test ! -s 'install.sh.Arch' || echo "${}"
# Switch to python2
sed -e '# Why using local on just this one?' \
-e 's:/usr/local/bin/python:/usr/bin/python:g' \
-e 's:/usr/bin/python:&2:g' \
-i *.py 'nslinktool'
# Branding in dmesg
sed -e '/^int nrp_init(/,/^}/ s:version %s %s:& Arch Linux:g' -i 'nslink.c'
grep -qFe 'Arch Linux' 'nslink.c' || echo "${}"
# Fix nslinktool. We'll get rid of the tabs while we're here.
expand -i 'nslinktool' | sed -e 's:\s\+$::g' > 'nslinktool.orig'
sed -e 's:/usr/local/man:/usr/share/man:g' 'nslinktool.orig' > 'nslinktool'
rm 'nslinktool.orig'
# Convert the live config entries to samples. This eliminates
# special handling for detecting a blank configuration.
sed -e 's:^[^#]:#&:g' -i 'nslink.conf'
# Fix makefile
sed -e 's:=/lib/modules:=/usr/lib/modules:g' -i 'Makefile'
# Correct group and chmod for serial
sed -e '/getgrnam/ s:"tty":"uucp":g' \
-e '# This method results in 666' \
-e '#s:\(mode_t mode\) = [0-9]\+\(.*;\)'":\1 = ${_opt_defaultmode}\2:g" \
-e "/mknod/ s:mode:0${_opt_defaultmode}:g" \
-i 'nslinkd.c'
}
prepare() {
set -u
cd "${_srcdir}"
_fn_patch_km "${pkgver}"
if [ ! -z "${_opt_LEGACY_VER}" ]; then
pushd "${srcdir}/${_srcalt}" > /dev/null
_fn_patch_km "${_opt_LEGACY_VER}"
popd > /dev/null
fi
# Fix up the firmware downloaders
cd "${srcdir}/${_srcdir2}"
# Fix permissions
find -type 'f' -perm '/111' -exec chmod 644 '{}' '+'
chmod 755 *.py
sed -e '# Cosmetic cleanup for simpler patch editing, trim space at eol' \
-e 's:\s\+$::g' \
-e '# Switch to python2' \
-e 's:/usr/bin/python:&2:g' \
-i *.py
# Patch usage and help into command line tool
#diff -pNau5 dmupdate.py{.orig,} > '../dmupdate.py.usage.patch'
patch -Nbup0 -i "${srcdir}/dmupdate.py.usage.patch"
set +u
}
build() {
set -u
cd "${_srcdir}"
set +u
if ! make -s -j1 QUIET=0; then
warning 'a no such file or directory error means you need to reboot to load the updated kernel'
false
fi
}
package() {
set -u
cd "${_srcdir}"
if [ "${_opt_DKMS}" -eq 0 ]; then
# I don't want Linux version info showing on AUR web. After a few months 'linux<0.0.0' makes it look like an out of date package.
local _kernelversionsmall="$(uname -r)"
_kernelversionsmall="${_kernelversionsmall%%-*}"
_kernelversionsmall="${_kernelversionsmall%\.0}" # trim 4.0.0 -> 4.0, 4.1.0 -> 4.1
# prevent the mksrcinfo bash emulator from getting these vars!
#eval 'conf''licts=("linux>${_kernelversionsmall}" "linux<${_kernelversionsmall}")'
eval 'dep''ends+=("linux=${_kernelversionsmall}")'
fi
# This installer expects the system folders to already exist
install -dm755 "${pkgdir}"{'/usr/bin','/etc',"/usr/lib/modules/$(uname -r)/misc",'/usr/lib/systemd/system'}
DESTDIR="${pkgdir}" \
INIT='systemd' \
sh -e -u 'install.sh' "$(uname -r)" install | \
sed -e "s:${pkgdir}::g" # cleaner display
# Fix paths in the service file
sed -e 's:/sbin/:/usr/bin/:g' -i "${pkgdir}/usr/lib/systemd/system/nslink.service"
# Root only permissions on executables. Easier than hacking UID 0 into them.
find "${pkgdir}/usr/bin/" -type 'f' -perm /111 -exec chmod 744 '{}' '+'
# Preserve an original copy of the config file
install -Dpm644 "${pkgdir}/etc/nslink.conf" "${pkgdir}/usr/share/nslink/nslink.conf.orig"
# Desktop file for NS-Link
install -Dm644 <(cat << EOF
[Desktop Entry]
Name=Comtrol NS-Link Administration
GenericName=Device Server Manager
Comment=DeviceMaster NS-Link for Comtrol Device Servers
Exec=gksudo -k -u root nslinktool
Terminal=false
Type=Application
#Icon=
Categories=Application;Utilities;
MimeType=application/x-executable
EOF
) "${pkgdir}/usr/share/applications/nslinktool.desktop"
# DKMS
if [ "${_opt_DKMS}" -ne 0 ]; then
rm -r "${pkgdir}/usr/lib/modules/"
local _dkms="${pkgdir}/usr/src/${pkgname}-${pkgver}"
#install -d "${_dkms}"
install -Dm644 <(cat << EOF
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/
PACKAGE_NAME="${pkgname}"
PACKAGE_VERSION="${pkgver}"
AUTOINSTALL="yes"
BUILT_MODULE_NAME[0]="nslink"
BUILT_MODULE_LOCATION[0]=""
# Using all processors doesn't compile this tiny module any faster.
MAKE[0]="make -j1 all QUIET=1"
CLEAN[0]="make -j1 clean"
# Placing the DKMS generated module in a different location than the standard install prevents conflicts when PKGBUILD _opt_DKMS is toggled
DEST_MODULE_LOCATION[0]="/kernel/drivers/misc"
EOF
) "${_dkms}/dkms.conf"
_fn_dkmsinst() {
install -Dpm644 'nslink.h' 'nslink_int.h' 'version.h' 'nslink.c' 'Makefile' -t "$1"
#make -C "$1" clean
sed -e '# No DKMS instructions say to do this but it works and keeps the MAKE line real simple' \
-e 's:$(shell uname -r):$(KERNELRELEASE):g' \
-e 's:`uname -r`:$(KERNELRELEASE):g' \
-e 's:$(KVER):$(KERNELRELEASE):g' \
-e '# Get rid of make lines so make all makes the module' \
-e 's:^\s\+make\s:#&:g' \
-i "$1/Makefile"
}
if [ -z "${_opt_LEGACY_VER}" ]; then
_fn_dkmsinst "${_dkms}"
else
# It is not necessary to install files to ${_dkms} for pacman -Qo
# The cp does not happen in /usr/src but in /var/lib/dkms where dkms cleans everything up
_fn_dkmsinst "${_dkms}/${pkgver}"
# Install a custom make helper that selects source based on kernel version
sed -e "/^MAKE/ s:make :${_dkms#${pkgdir}}/makedkms.sh"' KERNELRELEASE=$kernelver :g' -i "${_dkms}/dkms.conf"
install -Dm744 <(cat << EOF
#!/usr/bin/bash
# Automatically generated by ${pkgname}-${pkgver} PKGBUILD from Arch Linux AUR
# https://aur.archlinux.org/
set -e
set -u
kv="\$*" # \$@ is not what we want here.
kv="\${kv##*KERNELRELEASE=}"
kv="\${kv%% *}"
if [ "\$(vercmp "\${kv}" '4.15')" -lt 0 ]; then
cp -p '${_opt_LEGACY_VER}'/* .
else
cp -p '${pkgver}'/* .
fi
make "\$@"
EOF
) "${_dkms}/makedkms.sh"
# Install legacy code
pushd "${srcdir}/${_srcdir//${pkgver}/${_opt_LEGACY_VER}}" > /dev/null
_fn_dkmsinst "${_dkms}/${_opt_LEGACY_VER}"
popd > /dev/null
fi
fi
# Install firmware updaters
cd "${srcdir}/${_srcdir2}"
install -Dpm755 *.py -t "${pkgdir}/usr/bin/"
install -Dpm644 'README.txt' -t "${pkgdir}/usr/share/nslink/"
# Desktop file for GUI firmware updater
install -Dm644 <(cat << EOF
[Desktop Entry]
Name=Comtrol Update Firmware
GenericName=Device Server Manager
Comment=Manage Firmware on Comtrol Device Servers
Exec=DM-Firmware-Updater.py
Terminal=false
Type=Application
#Icon=
Categories=Application;Utilities;
MimeType=application/x-executable
EOF
) "${pkgdir}/usr/share/applications/DM-Firmware-Updater.py.desktop"
set +u
}
set +u
|