#!/bin/bash

set -e

chmod +x /usr/bin/sensor-ds18b20

# Function to get location of config.txt
function get_config_txt {
        if [ -f /boot/firmware/config.txt ]; then
                echo "/boot/firmware/config.txt"
        else
                echo "/boot/config.txt"
        fi
}

config_txt=$(get_config_txt)
cnt=$(grep -c "dtoverlay=w1-gpio,gpiopin=17,pullup=1" "$config_txt" || echo 0)
if [[ "$cnt" -eq 0 ]]; then
  echo -e "# Enable 1-Wire interface on pin 17\ndtoverlay=w1-gpio,gpiopin=17,pullup=1" | tee -a "$config_txt" > /dev/null
fi

#DEBHELPER#

exit 0
