-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use templates for files depending on TZ value
- Loading branch information
Showing
13 changed files
with
188 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
#!/bin/bash | ||
# Shell script to replace timezone values in powerwall.yml, telegraf.conf, influxdb.sql and dashboard.json | ||
if [ $# -eq 0 ] | ||
then | ||
# Shell script to create files depending on TZ value from templates | ||
|
||
# This is an hidden option to not print warning message | ||
# used by setup.sh script and by upgrade.sh script when | ||
# updating from version without templates | ||
if [ "$1" == "-y" ]; then | ||
PRINT_WARNING=false | ||
shift 1 | ||
fi | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "ERROR: No timezone supplied" | ||
echo | ||
echo "USAGE: ${0} {timezone}" | ||
exit | ||
fi | ||
|
||
# Current and New TZ values | ||
DEFAULT="America/Los_Angeles" | ||
CURRENT=`cat tz` | ||
NEW=$1 | ||
export TZ=$1 | ||
|
||
TEMPLATES=( | ||
$(echo dashboards/*.json.template) | ||
influxdb/influxdb.sql.template | ||
telegraf.conf.template | ||
) | ||
|
||
# Replace TZ Function | ||
updatetz() { | ||
local from=${1} | ||
local to=${2} | ||
sed -i.bak "s@${from}@${to}@g" powerwall.yml | ||
sed -i.bak "s@${from}@${to}@g" telegraf.conf | ||
sed -i.bak "s@${from}@${to}@g" influxdb/influxdb.sql | ||
for i in dashboards/dashboard*.json; do | ||
sed -i.bak "s@${from}@${to}@g" $i | ||
done | ||
sed -i.bak "s@${from}@${to}@g" pypowerwall.env | ||
if [ -d "dashboards" ] | ||
then | ||
for i in dashboards/*.json; do | ||
sed -i.bak "s@${from}@${to}@g" $i | ||
done | ||
if ${PRINT_WARNING:-true}; then | ||
echo "WARNING: the following files will be recreated from templates" | ||
echo " using TZ=$TZ; any local changes will be lost." | ||
printf -- " - %s\n" "${TEMPLATES[@]%.template}" | ||
echo | ||
read -r -p "Continue anyway? [y/N] " response | ||
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then | ||
exit 1 | ||
fi | ||
} | ||
fi | ||
|
||
for template in "${TEMPLATES[@]}"; do | ||
envsubst '$TZ' < "${template}" > "${template%.template}" | ||
done | ||
|
||
# Replace TZ values | ||
updatetz "${CURRENT}" "${NEW}" | ||
updatetz "${DEFAULT}" "${NEW}" | ||
|
||
# Record new TZ value | ||
echo "${NEW}" > tz | ||
# Record TZ value | ||
echo "${TZ}" > tz |
Oops, something went wrong.