From bbbaed0c0295b998ceeab9bb68aa136a6c1dcd26 Mon Sep 17 00:00:00 2001 From: BuongiornoTexas <48264358+BuongiornoTexas@users.noreply.github.com> Date: Mon, 4 Mar 2024 09:22:45 +1100 Subject: [PATCH 1/3] Improve grafana plugin updates, close #443 --- grafana.env.sample | 13 +++++++++- upgrade.sh | 61 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/grafana.env.sample b/grafana.env.sample index 65b3e9b8..7b7e8a33 100644 --- a/grafana.env.sample +++ b/grafana.env.sample @@ -1,6 +1,17 @@ GF_PATHS_PROVISIONING=/var/lib/grafana/provisions GF_SERVER_HTTP_PORT=9000 -GF_INSTALL_PLUGINS=grafana-piechart-panel, https://github.com/yesoreyeram/yesoreyeram-boomtable-panel/releases/download/v1.5.0-alpha.3/yesoreyeram-boomtable-panel-1.5.0-alpha.3.zip;yesoreyeram-boomtable-panel, grafana-influxdb-flux-datasource, fetzerch-sunandmoon-datasource, simpod-json-datasource + +# Core plugins required by Powerwall-Dashboard are managed in PWD_CORE_PLUGINS. +# WARNING: Please do not edit or redefine this variable later in this file. +# update.sh relies on only one appearance of this variable, and changes my break +# the update script. +# To add your own custom plugins, modify GF_INSTALL_PLUGINS. +PWD_CORE_PLUGINS=grafana-piechart-panel, https://github.com/yesoreyeram/yesoreyeram-boomtable-panel/releases/download/v1.5.0-alpha.3/yesoreyeram-boomtable-panel-1.5.0-alpha.3.zip;yesoreyeram-boomtable-panel, fetzerch-sunandmoon-datasource, simpod-json-datasource + +# Add your customs plugins to the end of GF_INSTALL_PLUGINS (comma-space separated!). +# Please do not remove ${PWD_CORE_PLUGINS}, as this will break the dashboard. +GF_INSTALL_PLUGINS=${PWD_CORE_PLUGINS} + GF_ANALYTICS_CHECK_FOR_UPDATES=false GF_ANALYTICS_REPORTING_ENABLED=false GF_PANELS_DISABLE_SANITIZE_HTML=true diff --git a/upgrade.sh b/upgrade.sh index a0252415..e65625d0 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -196,20 +196,63 @@ if [ ! -f ${GF_ENV_FILE} ]; then cp "${GF_ENV_FILE}.sample" "${GF_ENV_FILE}" fi -# Check for latest Grafana settings (required in 2.6.2) -if ! grep -q "yesoreyeram-boomtable-panel-1.5.0-alpha.3.zip" "${GF_ENV_FILE}"; then - echo "Your Grafana environmental settings are outdated." - read -r -p "Upgrade ${GF_ENV_FILE}? [y/N] " response +# Previously, this block checked for the existence of a marker plugin and overwrote +# grafana.env with a copy of grafana.env.sample. The new version updates plugins only +# and doesn't modify other parts of grafana.env. This may result in creeping differences +# in the sample and active env files. +# Create variables as script gets unwieldy otherwise. +core_env=PWD_CORE_PLUGINS +old_core=$(sed -n "s/^${core_env}=//p" ${GF_ENV_FILE}) +new_core=$(sed -n "s/^${core_env}=//p" ${GF_ENV_FILE}.sample) + +if [ "${old_core}" == "" ]; then + # This if block is a run once - could move to a separate tool, + # or just delete 6 or 12 months in the future (Aug '24 - Mar '25), as everyone + # will probably have been forced to update anyway by then due to + # Tesla firmware updates (on 23.44 as of this code). + + echo "Updating '${GF_ENV_FILE}' structure. '.old' backup file created." + + old_core=$(sed -n "s/^GF_INSTALL_PLUGINS=//p" ${GF_ENV_FILE}) + update_gf_file="# Plugins updated to use ${core_env}.\n# See '${GF_ENV_FILE}.sample' for details." + update_gf_file="${update_gf_file}\n${core_env}=${old_core}" + update_gf_file="${update_gf_file}\nGF_INSTALL_PLUGINS=\${${core_env}}" + + # Force update of grafana env file with new PWD_CORE_PLUGINS structure. + sed -i.old -e "s@^GF_INSTALL_PLUGINS=.*@${update_gf_file}@" $GF_ENV_FILE +fi + +if [ "${old_core}" == "${new_core}" ]; then + echo "Grafana plugin list is current. No action required." +else + echo + echo "Grafana plugin list has changed." + echo + echo "You appear to be running an older Grafana configuration with" + echo "plugins that are different to the current recommended list." + echo "This script can update your plugins to the current recommendations." + echo "If you have installed custom plugins or want to keep it as" + echo "it is, answer 'n' below and the script will provide instructions for" + echo "manual checks/updates." + echo + read -r -p "Do you want to update your Grafana plugin list? [y/N] " response if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]] then - cp "${GF_ENV_FILE}" "${GF_ENV_FILE}.bak" - cp "${GF_ENV_FILE}.sample" "${GF_ENV_FILE}" - echo "Updated" + sed -i.bak -e "s@^${core_env}=.*@${core_env}=${new_core}@" $GF_ENV_FILE docker stop grafana docker rm grafana + # Probably safe to delete all plugins as grafana downloads everything everytime anyway. + rm -fr ./grafana/plugins/* else - echo "No Change" - fi + echo + echo " Okay. Your grafana plugin list has not been updated." + echo + echo "However, this version of Powerwall-Dashboard may need new plugins" + echo "for the latest grafana dashboard. To address this, please" + echo "check the list of required plugins (listed in ${core_env} in" + echo "'${GF_ENV_FILE}.sample') and make sure all of these plugins are" + echo "added to ${core_env}' in '${GF_ENV_FILE}'." + fi fi # Silently create default docker compose env file if needed. From e62b704097595084e55f7bd9590a6b9950e0fc0b Mon Sep 17 00:00:00 2001 From: Jason Cox Date: Sun, 10 Mar 2024 08:16:49 -0700 Subject: [PATCH 2/3] v4.1.0 --- RELEASE.md | 4 ++++ VERSION | 2 +- upgrade.sh | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index d984758b..fe1c3a38 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,5 +1,9 @@ # RELEASE NOTES +## v4.1.0 - Grafana Plugin Updates + +* Update plugin list for Grafana, removing unneeded plugins (e.g. `flux datasource`) and adding logic to upgrade script to prune old `grafana.env` settings by @BuongiornoTexas in #442 #433 + ## v4.0.4 - Cloud Grid Status * Update to pyPowerwall v0.7.9 - Bug fix to render correct grid status for Solar-Only systems on `cloud mode` (see https://github.com/jasonacox/Powerwall-Dashboard/issues/437) diff --git a/VERSION b/VERSION index c5106e6d..ee74734a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.4 +4.1.0 diff --git a/upgrade.sh b/upgrade.sh index e65625d0..3b09686c 100755 --- a/upgrade.sh +++ b/upgrade.sh @@ -6,7 +6,7 @@ set -e # Set Globals -VERSION="4.0.4" +VERSION="4.1.0" CURRENT="Unknown" COMPOSE_ENV_FILE="compose.env" INFLUXDB_ENV_FILE="influxdb.env" From f6f708a9daefd03be68880b523a2f73eec79c0d9 Mon Sep 17 00:00:00 2001 From: Jason Cox Date: Sun, 10 Mar 2024 08:20:06 -0700 Subject: [PATCH 3/3] Version CR --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 99eba4de..ee74734a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.0 \ No newline at end of file +4.1.0