-
Notifications
You must be signed in to change notification settings - Fork 1
/
auto-disconnect-usb-device.sh
67 lines (45 loc) · 1.33 KB
/
auto-disconnect-usb-device.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
#!/bin/bash
DEVICE_PORT=$1
EXAMPLE="Example:\n\tauto-disconnect-device.sh [Port]"
if [ ! $DEVICE_PORT ]; then
echo "Please provide a port as an argument."
echo $EXAMPLE
exit 1
fi
echo "Automatically disconnecting device..."
echo "Device port: $DEVICE_PORT"
#sh update.sh
echo "Looking for device:"
DEVICES_DIR="devices"
DEVICE_NAME=""
if [ -d $DEVICES_DIR ]; then
for d in $DEVICES_DIR/*
do
echo "Device info dir: $d"
PORT=$(cat "$d/port.txt")
echo "Port: $PORT"
if [ "$PORT" = "$DEVICE_PORT" ]; then
DEVICE_NAME=$(cat "$d/name.txt")
fi
done
fi
# Disabled because it's causing problems with tests
#notify-send "Removing $DEVICE_NAME device"
if [ $DEVICE_NAME ]; then
sh mqtt-publish-device.sh "$DEVICE_NAME" "StatusMessage" "Disconnecting"
echo "Device name: $DEVICE_NAME"
echo "Stopping device services..."
sh stop-garden-device.sh $DEVICE_NAME
SCRIPT_NAME="disconnect-garden-device.sh"
echo ""
echo "Remove device script:"
echo $SCRIPT_NAME "$DEVICE_NAME"
echo ""
sh $SCRIPT_NAME "$DEVICE_NAME" || exit 1
sh mqtt-publish-device.sh "$DEVICE_NAME" "StatusMessage" "Disconnected"
echo "Finished auto disconnecting device."
else
echo "Device not found."
fi
# Disabled because it's causing problems with tests
#notify-send "Finished removing $DEVICE_NAME device"