#
# check snapcast account
#
if [ -z "$(grep ^snapserver /etc/group)" ]; then
    groupadd -g 315 snapserver
fi
if [ -z "$(grep ^snapserver /etc/passwd)" ]; then
    useradd -u 315 -g 315 -d /var/lib/snapserver -s /bin/bash -c "Snapcast server" snapserver
fi
if [ -z "$(groupmems -g audio -l | grep -w snapserver)" ]; then
    groupmems -g audio -a snapserver
fi


config() {
    NEW="$1"
    OLD="$(dirname $NEW)/$(basename $NEW .new)"
    # If there's no config file by that name, mv it over:
    if [ ! -r $OLD ]; then
	mv $NEW $OLD
    elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then # toss the redundant copy
	rm $NEW
    fi
    # Otherwise, we leave the .new copy for the admin to consider...
}
config etc/default/snapcast.new
config etc/snapserver.conf.new

