-
Notifications
You must be signed in to change notification settings - Fork 1
/
disconnect-garden-device.sh
44 lines (33 loc) · 1.19 KB
/
disconnect-garden-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
echo ""
echo "Disconnecting garden device..."
echo ""
DEVICE_NAME=$1
BOARD_TYPE=$(cat "devices/$DEVICE_NAME/board.txt")
if [ ! $DEVICE_NAME ]; then
echo "Error: Specify a device name as an argument."
exit 1
else
echo " Device name: $DEVICE_NAME"
echo " Board type: $BOARD_TYPE"
sh remove-device-services.sh $DEVICE_NAME || exit 1
DEVICE_INFO_DIR="devices/$DEVICE_NAME"
# Check whether it's a WiFi device
[ "$BOARD_TYPE" = "esp" ] \
&& IS_WIFI=1 \
|| IS_WIFI=0
# Only remove it from the system completely if it's NOT an ESP/WiFi board. They can keep running without a USB connection.
if [ $IS_WIFI = 1 ]; then
echo " WiFi based device. Device will remain registered but marked as disconnected."
echo "0" > "$DEVICE_INFO_DIR/is-usb-connected.txt"
else
echo " USB based device. It is being removed from the system completely."
echo " Removing device info.."
if [ -d $DEVICE_INFO_DIR ]; then
rm $DEVICE_INFO_DIR -R
fi
# Recreating garden UI
# TODO: Instead of regenerating the entire UI, figure out how to remove a single item from the UI
sh recreate-garden-ui.sh || exit 1
fi
echo "Garden device removed: $DEVICE_NAME"
fi