Newer
Older
openhab / install.sh
#!/bin/bash

# get user id
uid=$(id -u)

# get architecture
arc=$(uname -m)

if [ ! -f "openhab.conf" ]; then
	cp openhab.conf.example openhab.conf

	# create directories
	mkdir -p data/conf
	mkdir -p data/userdata
	mkdir -p data/addons

	# replace uid and gid in config file
	sed -i "/^OPENHAB_USER/c\\\OPENHAB_USER_ID=${uid}" openhab.conf

	# db passwords
	pw1=$(</dev/urandom tr -dc A-Za-z0-9 | head -c 28)
	pw2=$(</dev/urandom tr -dc A-Za-z0-9 | head -c 28)

	# replace default passwords
	sed -i "/^OPENHAB_DATABASE_ROOT/c\\\OPENHAB_DATABASE_ROOT=${pw1}" openhab.conf
	sed -i "/^OPENHAB_DATABASE_PASSWORD/c\\\OPENHAB_DATABASE_PASSWORD=${pw2}" openhab.conf

	# replace architecture dependend
	if [[ $arc == "x86_64" ]]; then
		sed -i "/^OPENHAB_ARCH=/c\\\OPENHAB_ARCH=amd64" openhab.conf
	elif [[ $arc == *"armv"* ]]; then
		sed -i "/^OPENHAB_ARCH=/c\\\OPENHAB_ARCH=armhf" openhab.conf
		sed -i "/^#OPENHAB_MEMORY_LIMIT=/c\\\OPENHAB_MEMORY_LIMIT=512m" openhab.conf
	else
		echo "unsupportet architecture"
		exit 1
	fi
else
	echo "Config already exists!"
fi