Installing market bindings automagically doesn’t work (yet) with addons.cfg, so I created the following rule to install them manually after each server start (which I just assume is always preceded by an openhab update):
rule "Systemstart"
when
System started
then
[...]
Thread::sleep(30000)
executeCommandLine("/etc/openhab2/marketbindings.sh")
end
Contents of /etc/openhab2/marketbindings.sh:
curl -X POST -H "Content-Type: text/plain" --data "id=market:binding-3670618" http://192.168.1.253:8080/rest/extensions/market:binding-3670618/install
curl -X POST -H "Content-Type: text/plain" --data "id=market:binding-3499123" http://192.168.1.253:8080/rest/extensions/market:binding-3499123/install
Here I add the eBUS 2.0 Binding and the Openhab Xiaomi Mi IO Binding, but this works with any binding.
Not very beautiful, but working!
Don’t forget to put the binding id in both the link and the submitted data & put in your own server’s IP.
This is actually a nice idea. We could change your script to read the addons.cfg and iterate over the market bindings. This way we still have a single location to install bindings.
An even nicer idea! Took me a while, since regex in bash is highly non-intuitive (no global capture, no non-greedy matches, no line break matches), but finally got it working using a few hacks:
#!/bin/bash
content=`cat /etc/openhab2/services/addons.cfg`
regex="(market:[^, $]*)"
ip="YOUR IP"
port="YOUR PORT"
install_extensions() {
local s=$1 regex=$2
while [[ $s =~ $regex ]]; do
read extension < <(echo "${BASH_REMATCH[1]}" | grep "market:")
read blen < <(echo "$extension" | wc -c)
if [ $blen -gt 8 ];
then
curl -X POST -H "Content-Type: text/plain" --data "id=$extension" http://$ip:$port/rest/extensions/$extension/install
fi
s=${s#*"${BASH_REMATCH[1]}"}
done
}
install_extensions "$content" "$regex"
This scans addons.cfg for any extensions beginning with “market:” and installs them. The string length check is not really necessary, this just prevents empty entries like “market:,” from being installed.
Might be wrong topic - I dont use addon.cfg only PaperUI - would there be a similar approach to install via paperUI binding installs? (even if its not reading a file)
Yes I understand that - but am looking for an option as no matter I usually install the market bindings again after an update - if there was a scripted way id love it.
What I do is download the bindings from the upstream place (usually the maven repository of the successful builds) into my addons directory. Before starting openHAB, that is: