Skip to content

Instantly share code, notes, and snippets.

@koter84
Last active January 27, 2023 14:38
Show Gist options
  • Save koter84/86790850aa63354bda56d041de31dc70 to your computer and use it in GitHub Desktop.
Save koter84/86790850aa63354bda56d041de31dc70 to your computer and use it in GitHub Desktop.
#!/bin/bash
self_file="$0"
self_source_url="https://raw.githubusercontent.com/koter84/HomeAssistant_Blueprints_Update/main/blueprints_update.sh"
# print info function
function _blueprint_update_info
{
echo "$@"
}
# create a temp file for downloading
_tempfile=$(mktemp -t blueprints_update.XXXXXX)
# start message
_blueprint_update_info "> ${self_file}"
# update
wget -q -O "${_tempfile}" "${self_source_url}"
wget_result=$?
if [ "${wget_result}" != "0" ]
then
_blueprint_update_info "! something went wrong while downloading, exiting..."
_blueprint_update_info
exit
fi
self_diff=$(diff "${self_file}" "${_tempfile}")
if [ "${self_diff}" == "" ]
then
_blueprint_update_info "-> self up-2-date"
else
cp "${_tempfile}" "${self_file}"
chmod +x "${self_file}"
_blueprint_update_info "-! self updated!"
exit
fi
_blueprint_update_info
@SirGoodenough
Copy link

SirGoodenough commented Dec 16, 2022

Thanks for this @koter84 .I did some initial troubleshooting with you on this and it looks great here.

I've noticed that blueprint filenames that have spaces or non alpha characters get confused and comes back with non-matching filename. I think this worked at one time, it is not now from this gist version anyway.

Another thing that seemed confused was if I add custom- to a source url, it finds it, updates it, but the url is not in the file when it comes back. Instead we get - source_url: and a blank which fails syntax in HA. I'm pretty sure that was fine early on as well.

I'm thinking perhaps an in-between version is posted here.

Also if there is a way the shell can return a flag if there are updates needed or not would be great. I'm not really wanting to have it just update when I'm not there when it tuns in a timer. I would prefer it runs on the timer, returns some data that we can grab in HA to do a persistent_notification that updates need to be checked. (Webhook with some json message(s), perhaps?)

An enhancement request would be another switch that takes a filename so a single file could be checked or updated as opposed to all.

@koter84
Copy link
Author

koter84 commented Jan 25, 2023

i have made a full github repository for this script, which you can find on https://github.com/koter84/HomeAssistant_Blueprints_Update/

i'm currently fixing some errors and adding a couple of features, once i commit that to the new repository i'll update this script to auto-update to that repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment