Automatic install of marketplace bindings?

I use an eclipse marketplace in my configuration and I like to have it loaded after every restart of my OH server.

I tried to achieve this by editing the addons.cfg file the following way:
binding = …,market:binding-3965440
binding = …,binding-3965440
binding = …,3965440

None of them worked.

The marketplace itself is being loaded automatically via this line:
misc = …,market

Is it possible at all to auto-load marketplace addons via this way at all?

Thanks,
Boby

1 Like

No idea anyone?

IMHO no!
However, if you download the .jar and put it into the addons-folder it will be installed after each restart. Using the .jar like that, you have to remove this file and paste the new one in case of an update!

Thank you, I‘ll try that!

LG,
Robert

@Boby did you found a solution except putting the jar into the addons-folder?

Nope, but finally I opened an issue on Github for this feature request:


I don’t know anything about the infrastructure inside openhab, but when I can install “normal” bindings via PaperUI and also via an entry in the addons.cfg, then I assume it should be easy to do this for marketplace bindings as well.

I am not the original author of this but I can’t find the link to where I found it. Either way this should do what you want. I have been using it for a really long time with no issues. It will scan through your addons.cfg file and when it matches up with the market bindings, it will parse that info and install them. Note the format of the names, in the addons.cfg file, it must be put this way otherwise it won’t work.

create a rules file
marketbinding.rules

rule "System Start scan for market binding addons"
when 
    System started
then
	createTimer(now.plusSeconds(20), [|
		logInfo("marketbinding.rules", "Starting Market Binding Script" )
		executeCommandLine("bash /etc/openhab2/scripts/marketbinding.sh")		
	])	
end

Add this file to your scripts folder. Note you need to change your IP address and port if you have changed it.

marketbinding.sh

#!/bin/bash
content=`cat /etc/openhab2/services/addons.cfg`
regex="(market:[^, $]*)"
ip="192.168.1.2"
port="8080"
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"

Now edit the addons.cfg in your services folder. Assuming you want to add the market bindinds for bluetooth and tinyB you would enter the following. Make sure to keep the lines commented it will work that way. If you uncomment you will get an error…

# Begin Market Binding Section
#Although commented, the below text will be picked up by a script to install market bindings on startup. See marketbinding.rules

#Bluetooth Binding
# market:binding-3694484

#Bluetooth Binding Tiny B Transport
# market:binding-3769218
2 Likes

Love this - at last, thank you, a simple solution!!

Took me 2 mins to apply these with quick copy paste and now a reboot is a seamless experience :slight_smile: