Addon.cfg load market binding?

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.

6 Likes