#!/bin/bash

# Get host information
HOST=`hostname -f`
GROUP=`curl -fs "http://c.yandex-team.ru/api/hosts/$HOST?format=yaml" | grep 'group' | awk '{print $NF}'`
GROUP_HOSTS="/tmp/groups2hosts"
CORE_DC_VLAN=`ip ro | grep default | awk '{print $3}'`



if [ -f "/etc/yandex/environment.type" ]; then
        ENVIR=`cat /etc/yandex/environment.type`
else
        echo 'No /etc/yandex/environment.type, trying detect env by conductor group'
        preenvir=`echo $GROUP | awk -F\- '{print $NF}'`
        if [[ "$preenvir" == "testing" ]] || [[ "$preenvir" == "prestable" ]]; then
                ENVIR=`echo $preenvir`
        else
                ENVIR="production"
        fi
fi

rm /etc/distributed-flock.json
ln -s  /etc/distributed-flock-${ENVIR}.json  /etc/distributed-flock.json
