#!/usr/bin/env bash
set -euo pipefail

if [ "$(cat  out_adevtool_deps/soong/.intermediates/hardware/google/interfaces/thermal/pixel-thermal-ext_interface/has_development )" = "1" ]; then mkdir -p hardware/google/interfaces/thermal/aidl_api/pixel-thermal-ext/1 &&  cp -rf out_adevtool_deps/soong/.intermediates/hardware/google/interfaces/thermal/pixel-thermal-ext_interface/dump/. hardware/google/interfaces/thermal/aidl_api/pixel-thermal-ext/1 ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/hardware/google/interfaces/thermal/pixel-thermal-ext_interface/has_development )" = "1" ]; then echo "There is change between ToT version and the latest stable version. Freezing pixel-thermal-ext-V1." ; else echo "There is no change from the latest stable version of pixel-thermal-ext. Nothing happened." ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/hardware/google/interfaces/thermal/pixel-thermal-ext_interface/has_development )" = "1" ]; then out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m pixel-thermal-ext -parameter versions -remove-property hardware/google/interfaces/thermal/Android.bp ; fi
if [ "$(cat  out_adevtool_deps/soong/.intermediates/hardware/google/interfaces/thermal/pixel-thermal-ext_interface/has_development )" = "1" ]; then out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m pixel-thermal-ext -parameter versions_with_info -add-literal '{version: "1", imports: []}'  hardware/google/interfaces/thermal/Android.bp && out_adevtool_deps/host/linux-x86/bin/bpmodify -w -m pixel-thermal-ext -parameter frozen -set-bool true hardware/google/interfaces/thermal/Android.bp ; fi
