forked from jasonacox/Powerwall-Dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.sh
executable file
·215 lines (185 loc) · 5.65 KB
/
upgrade.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
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
#!/bin/bash
# Stop on Errors
set -e
# Set Globals
VERSION="2.9.11"
CURRENT="Unknown"
COMPOSE_ENV_FILE="compose.env"
TELEGRAF_LOCAL="telegraf.local"
if [ -f VERSION ]; then
CURRENT=`cat VERSION`
fi
# Verify not running as root
if [ "$EUID" -eq 0 ]; then
echo "ERROR: Running this as root will cause permission issues."
echo ""
echo "Please ensure your local user in in the docker group and run without sudo."
echo " sudo usermod -aG docker \$USER"
echo " $0"
echo ""
exit 1
fi
# Service Running Helper Function
running() {
local url=${1:-http://localhost:80}
local code=${2:-200}
local status=$(curl --head --location --connect-timeout 5 --write-out %{http_code} --silent --output /dev/null ${url})
[[ $status == ${code} ]]
}
# Because this file can be upgrade, don't use it to run the upgrade
if [ "$0" != "tmp.sh" ]; then
# Grab latest upgrade script from github and run it
curl -sL --output tmp.sh https://raw.githubusercontent.com/jasonacox/Powerwall-Dashboard/main/upgrade.sh
exec bash tmp.sh upgrade
fi
# Check to see if an upgrade is available
if [ "$VERSION" == "$CURRENT" ]; then
echo "WARNING: You already have the latest version (v${VERSION})."
echo ""
fi
echo "Upgrade Powerwall-Dashboard from ${CURRENT} to ${VERSION}"
echo "---------------------------------------------------------------------"
echo "This script will attempt to upgrade you to the latest version without"
echo "removing existing data. A backup is still recommended."
echo ""
# Stop upgrade if the installation is key files are missing
ENV_FILE="pypowerwall.env"
if [ ! -f ${ENV_FILE} ]; then
echo "ERROR: Missing ${ENV_FILE} - This means you have not run 'setup.sh' or"
echo " you have an older version that cannot be updated automatically."
echo " Run 'git pull' and resolve any conflicts then run the 'setup.sh'"
echo " script to re-enter your Powerwall credentials."
echo ""
echo "Exiting"
exit 1
fi
# Verify Upgrade
read -r -p "Upgrade - Proceed? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
echo ""
else
echo "Cancel"
exit
fi
# Remember Timezone and Reset to Default
echo "Resetting Timezone to Default..."
DEFAULT="America/Los_Angeles"
TZ=`cat tz`
if [ -z "${TZ}" ]; then
TZ="America/Los_Angeles"
fi
./tz.sh "${DEFAULT}"
# Pull from Github
echo ""
echo "Pull influxdb.sql, dashboard.json, telegraf.conf, and other changes..."
echo ""
git stash
git pull --rebase
echo ""
# Create Grafana Settings if missing (required in 2.4.0)
if [ ! -f grafana.env ]; then
cp "grafana.env.sample" "grafana.env"
fi
# Check for latest Grafana settings (required in 2.6.2)
if ! grep -q "yesoreyeram-boomtable-panel-1.5.0-alpha.3.zip" grafana.env; then
echo "Your Grafana environmental settings are outdated."
read -r -p "Upgrade grafana.env? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
cp "grafana.env" "grafana.env.bak"
cp "grafana.env.sample" "grafana.env"
echo "Updated"
docker stop grafana
docker rm grafana
else
echo "No Change"
fi
fi
# Silently create default docker compose env file if needed.
if [ ! -f ${COMPOSE_ENV_FILE} ]; then
cp "${COMPOSE_ENV_FILE}.sample" "${COMPOSE_ENV_FILE}"
fi
# Create default telegraf local file if needed.
if [ ! -f ${TELEGRAF_LOCAL} ]; then
cp "${TELEGRAF_LOCAL}.sample" "${TELEGRAF_LOCAL}"
fi
# Check to see if Weather Data is Available
if [ ! -f weather/weather411.conf ]; then
echo "This version (${VERSION}) allows you to add local weather data."
echo ""
# Optional - Setup Weather Data
if [ -f weather.sh ]; then
./weather.sh setup
else
echo "However, you are missing the weather.sh setup file. Skipping..."
echo ""
fi
fi
# Check to see that TZ is set in pypowerwall
if ! grep -q "TZ=" pypowerwall.env; then
echo "Your pypowerwall environmental settings are missing TZ."
echo "Adding..."
echo "TZ=America/Los_Angeles" >> pypowerwall.env
fi
# Make sure stack is running
echo ""
echo "Start Powerwall-Dashboard stack..."
./compose-dash.sh up -d
# Set Timezone
echo ""
echo "Setting Timezone back to ${TZ}..."
./tz.sh "${TZ}"
# Update Influxdb
echo ""
echo "Waiting for InfluxDB to start..."
until running http://localhost:8086/ping 204 2>/dev/null; do
printf '.'
sleep 5
done
echo " up!"
sleep 2
echo ""
echo "Add downsample continuous queries to InfluxDB..."
docker exec --tty influxdb sh -c "influx -import -path=/var/lib/influxdb/influxdb.sql"
cd influxdb
for f in run-once*.sql; do
if [ ! -f "${f}.done" ]; then
echo "Executing single run query $f file...";
docker exec --tty influxdb sh -c "influx -import -path=/var/lib/influxdb/${f}"
echo "OK" > "${f}.done"
fi
done
cd ..
# Delete pyPowerwall for Upgrade
echo ""
echo "Delete and Upgrade pyPowerwall to Latest"
docker stop pypowerwall
docker rm pypowerwall
# Delete telegraf for Upgrade
echo ""
echo "Delete and Upgrade telegraf to Latest"
docker stop telegraf
docker rm telegraf
# Delete weather411 for Upgrade
echo ""
echo "Delete and Upgrade weather411 to Latest"
docker stop weather411
docker rm weather411
# Restart Stack
echo ""
echo "Restarting Powerwall-Dashboard stack..."
./compose-dash.sh up -d
# Display Final Instructions
cat << EOF
---------------[ Update Dashboard ]---------------
Open Grafana at http://localhost:9000/
From 'Dashboard/Browse', select 'New/Import', and
upload 'dashboard.json' located in the folder
${PWD}/dashboards/
Please note, you may need to select data sources
for 'InfluxDB' and 'Sun and Moon' via the
dropdowns and use 'Import (Overwrite)' button.
EOF
# Clean up temporary upgrade script
rm -f tmp.sh