-
Notifications
You must be signed in to change notification settings - Fork 3
/
assignAPC
executable file
·66 lines (63 loc) · 2.21 KB
/
assignAPC
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
#!/bin/bash
#emacs: -*- mode: shell-script; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
#ex: set sts=4 ts=4 sw=4 noet:
#-------------------------- =+- Shell script -+= --------------------------
#
# @file assignAPC
# @date Fri Feb 20 11:16:31 2009
# @brief
#
#
# Yaroslav Halchenko CS@UNM, CS@NJIT
# web: http://www.onerussian.com & PSYCH@RUTGERS
# e-mail: [email protected] ICQ#: 60653192
#
# DESCRIPTION (NOTES):
#
# Helper script to create deterministic links to each APC unit's USB device
# It was coded long ago, so it is quite sloppy ;)
#
# COPYRIGHT: Yaroslav Halchenko 2007-2009
#
# LICENSE:
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
# On Debian system see /usr/share/common-licenses/GPL for the full license.
#
#-----------------\____________________________________/------------------
LDIR=/etc/apcupsd/links
APCDEVICES=( YS0320110332 YS0422220996 YS0422221259 )
mkdir -p $LDIR
for d in ${APCDEVICES[*]}
do
# echo $d
# First find out bus/dev for this device
usbparm=`grep -6 $d /proc/bus/usb/devices | grep 'Bus.*Dev' | head -1 | sed -e 's/.*Bus=0*\([1-90]*\) .*Dev#=[ 0]*\([0-9]*\) .*/\1 \2 0/g' 2>/dev/null`
found=0
# find out hiddev for it in a stupid way for now
for dhid in /dev/usb/hiddev*
do
hidparm=`/usr/local/sbin/usbinfo $dhid 2>/dev/null`
if [ "x${hidparm}x" == "x${usbparm}x" ]
then
found=1
ln -sf $dhid $LDIR/$d
break;
fi
done
[ $found == 1 ] || echo "Couldn't find corresponding device for UPS $d"
done