#!/bin/sh

DEST="/etc/switchman.conf"

if [ -e /etc/yandex/environment.type ]; then
    YANDEX_ENV=$(cat /etc/yandex/environment.type)
fi

if [ -e /etc/yandex/environment.direct_sandbox ]; then
    YANDEX_ENV="sandbox"
fi

if [ "$YANDEX_ENV" = "" ]; then
    YANDEX_ENV="development"
fi

case "$YANDEX_ENV" in
    production)
        SOURCE="/etc/switchman/switchman.production.conf"
        ;;

    testing)
        SOURCE="/etc/switchman/switchman.testing.conf"
        ;;

    development)
        SOURCE="/etc/switchman/switchman.development.conf"
        ;;

    sandbox)
        SOURCE="/etc/switchman/switchman.empty.conf"
        ;;

    *)
        SOURCE="/etc/switchman/switchman.empty.conf"
        ;;
esac

if [ -e $SOURCE ]; then
    ln -s -f -T $SOURCE $DEST || true
fi

SWITCHMAN_LOGS_DIR=/var/log/switchman

if [ ! -d $SWITCHMAN_LOGS_DIR ]; then
    mkdir $SWITCHMAN_LOGS_DIR && chown ppc:ppc $SWITCHMAN_LOGS_DIR || true
fi

