forked from WebThingsIO/gateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcandle_controller.sh
More file actions
executable file
·135 lines (104 loc) · 4.11 KB
/
candle_controller.sh
File metadata and controls
executable file
·135 lines (104 loc) · 4.11 KB
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
#!/bin/bash
#set -e -x
if [ -f /dev/kmsg ]; then
echo "in candle_controller.sh: starting gateway" | sudo tee -a /dev/kmsg
fi
echo "Preparing the Candle Controller for launch"
NVM_DIR="/home/pi/.nvm"
source $NVM_DIR/nvm.sh
#if [ ! -d /home/pi/.dbus/session-bus ]; then
# export $(dbus-launch)
#fi
#echo "BEFORE:"
#echo "XDG_RUNTIME_DIR: $XDG_RUNTIME_DIR"
#echo "DBUS_SESSION_BUS_ADDRESS: $DBUS_SESSION_BUS_ADDRESS"
#echo "--"
#printenv
#echo "--"
if [ -n "$XDG_RUNTIME_DIR" ] ; then
echo "XDG_RUNTIME_DIR was empty"
XDG_RUNTIME_DIR="/run/user/$(id -u)"
#DBUS_SESSION_BUS_ADDRESS="/run/user/$(id -u)/bus"
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
#export DBUS_SESSION_BUS_ADDRESS="/run/user/$(id -u)/bus"
fi
#if [ -n "$DBUS_SESSION_BUS_ADDRESS" ] ; then
#if [ -d /home/pi/.dbus/session-bus ] ; then
# SESSION_FILE=$(ls -tp /home/pi/.dbus/session-bus | grep -v /$ | head -1)
# if ps aux | grep -q '/dbus-daemon'; then
# if [ -n "$SESSION_FILE" ] && [ -f "/home/pi/.dbus/session-bus/$SESSION_FILE" ]; then
# echo "sourcing: /home/pi/.dbus/session-bus/$SESSION_FILE"
# source "/home/pi/.dbus/session-bus/$SESSION_FILE"
# fi
# fi
#else
# echo "calling dbus-launch"
# export $(dbus-launch)
#fi
#echo "DBUS_SESSION_BUS_ADDRESS was (still) empty, calling export dbus-launch"
#export $(dbus-launch)
#fi
#eval $(dbus-launch --sh-syntax)
if [ -n "$DISPLAY" ] ; then
export DISPLAY=:0
fi
#XDG_RUNTIME_DIR="/run/user/1000"
#export XDG_RUNTIME_DIR="/run/user/1000"
#DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
#export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"
#export DBUS_SESSION_BUS_ADDRESS="$XDG_RUNTIME_DIR/bus"
#echo "AFTER:"
echo "XDG_RUNTIME_DIR: $XDG_RUNTIME_DIR"
echo "DBUS_SESSION_BUS_ADDRESS: $DBUS_SESSION_BUS_ADDRESS"
#echo "--"
#printenv
#echo "--"
#systemctl --user restart pipewire pipewire-pulse
# Ensure that the Candle Store addon is enabled
if [ ! -f "/boot/firmware/candle_skip_store_check.txt" ]; then
if [ -f /home/pi/.webthings/config/db.sqlite3 ]; then
candleappstore_settings=$(sqlite3 /home/pi/.webthings/config/db.sqlite3 'SELECT value FROM settings WHERE key = "addons.candleappstore"')
if [[ "$candleappstore_settings" == *",\"enabled\":false,"* ]]; then
echo "Enabling candle store addon"
echo "----BEFORE----"
echo $candleappstore_settings
echo "----"
new_candleappstore_settings="${candleappstore_settings//,\"enabled\":false,/,\"enabled\":true,}"
#new_candleappstore_settings="${new_candleappstore_settings//\"/\\\"}"
echo "----AFTER----"
echo $new_candleappstore_settings
echo "----"
sqlite3 /home/pi/.webthings/config/db.sqlite3 "UPDATE settings SET value='$new_candleappstore_settings' WHERE key IS 'addons.candleappstore';"
else
echo "OK, Candle store is enabled"
fi
fi
if [ ! -d "/home/pi/.webthings/addons/candleappstore" ] && [ -d "/home/pi/.webthings/backups/addons/candleappstore" ]; then
cp -r /home/pi/.webthings/backups/addons/candleappstore /home/pi/.webthings/addons/candleappstore
chown -R pi:pi /home/pi/.webthings/addons/candleappstore
fi
fi
#CONTROLLER_NODE_VERSION_FILE_PATH="${WEBTHINGS_HOME}/.node_version"
use_node_version=$(node --version | egrep -o '[0-9]+' | head -n1)
echo "candle_controller.sh: use_node_version: $use_node_version"
#AVAILABLE_NODE_VERSIONS=$(nvm list | grep "lts/" | grep -v "N/A")
#echo
#echo "Installed node versions: "
#echo "${AVAILABLE_NODE_VERSIONS}"
#echo
# Optionally let the desired Node version be overridden with a file in /boot
if [ -f "/boot/firmware/candle_node_version.txt" ]; then
use_node_version=$(cat /boot/firmware/candle_node_version.txt)
echo "Candle node version file detected. overriding Node version to use to: ${use_node_version}"
fi
WEBTHINGS_HOME="${WEBTHINGS_HOME:=${HOME}/.webthings}"
mkdir -p "${WEBTHINGS_HOME}/log"
if [ -f "${WEBTHINGS_HOME}/log/run-app.log" ]; then
rm -f "${WEBTHINGS_HOME}/log/run-app.log"
fi
echo
echo "Starting Candle Controller!"
echo "Node version: $use_node_version"
echo
#nvm exec ${use_node_version} node build/app.js
exec dbus-launch node build/app.js