-
-
Save luukdobber/cb803f32c791b9c5fc4ee63a903be3da to your computer and use it in GitHub Desktop.
Install HA Core commit as custom component
This file contains hidden or 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
| #!/bin/bash | |
| # curl -o- -L https://gist.githubusercontent.com/luukdobber/cb803f32c791b9c5fc4ee63a903be3da/raw/core_integration_commit | bash /dev/stdin -d domain -c 12345 | |
| while getopts d:c: flag | |
| do | |
| case "${flag}" in | |
| d) domain="${OPTARG}";; | |
| c) commit_hash="${OPTARG}";; | |
| esac | |
| done | |
| function info () { echo -e "${GREEN_COLOR}INFO: $1${NO_COLOR}";} | |
| function error () { echo -e "${RED_COLOR}ERROR: $1${NO_COLOR}"; if [ "$2" != "false" ]; then exit 1;fi; } | |
| current_dir="${PWD}" | |
| tmp_git_dir=/tmp/core_git | |
| set -e | |
| clean_up () { | |
| ARG=$? | |
| info "Cleaning up" | |
| cd "$current_dir" | |
| rm -rf "${tmp_git_dir}" | |
| exit $ARG | |
| } | |
| trap clean_up EXIT | |
| if [ -z "$(command -v "git")" ]; then | |
| error "'git' is not installed" | |
| fi | |
| if [ -z "$(command -v "jq")" ]; then | |
| error "'jq' is not installed" | |
| fi | |
| info "Current dir is ${current_dir}" | |
| if [[ -z "${domain}" ]]; then | |
| error "Missing domain (-d) argument"; | |
| fi | |
| if [[ -z "${commit_hash}" ]]; then | |
| error "Missing commit hash (-c) argument"; | |
| fi | |
| if [[ ! -f ".HA_VERSION" ]]; then | |
| error "Not a Home Assistant folder!" | |
| fi | |
| info "Cloning core to " | |
| git clone --depth 1 https://github.com/luukdobber/ha-core.git "${tmp_git_dir}" | |
| cd "${tmp_git_dir}" | |
| info "Checking out commit#${commit_hash}" | |
| git fetch --depth 1 origin "${commit_hash}" | |
| git checkout "${commit_hash}" | |
| if [[ ! -d "${tmp_git_dir}/homeassistant/components/${domain}" ]]; then | |
| error "Integration with ${domain} does not exist in commit #${commit_hash}" | |
| fi | |
| info "Removing current folder ${current_dir}/custom_components/${domain}" | |
| rm -rf "${current_dir}/custom_components/${domain}" | |
| info "Copying integration files" | |
| mkdir -p "${current_dir}/custom_components" | |
| mv "${tmp_git_dir}/homeassistant/components/${domain}" "${current_dir}/custom_components/" | |
| if [[ -f "${current_dir}/custom_components/${domain}/strings.json" ]]; then | |
| mkdir -p "${current_dir}/custom_components/${domain}/translations" | |
| mv "${current_dir}/custom_components/${domain}/strings.json" "${current_dir}/custom_components/${domain}/translations/en.json" | |
| fi | |
| jq --arg commit_hash "${commit_hash}" '.version = $commit_hash' "${current_dir}/custom_components/${domain}/manifest.json" > tmp && mv -f tmp "${current_dir}/custom_components/${domain}/manifest.json" | |
| info "DONE!" | |
| info "You now need to restart Home Assistant" | |
| info "NOTE: If the commit changed anything outside of it´s own folder this method will not work." | |
| info "If you want to remove this, you need to delete the ${current_dir}/custom_components/${domain} folder" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment