#!/bin/bash

ssh-keyscan github.yandex-team.ru >> /root/.ssh/known_hosts
ssh-keyscan arcadia-ro.yandex.ru >> /root/.ssh/known_hosts

mkdir -p /srv/salt_repos
cd /srv/salt_repos
git clone -b master --single-branch https://github.yandex-team.ru/salt-media/common

# For arcadia
REPO=disk
if [ "${YANDEX_ENVIRONMENT}" = "testing" ]; then
    REPO=${REPO}-testing
fi

# Arcadia
svn checkout svn+ssh://robot-disk-cloud@arcadia-ro.yandex.ru/arc/trunk/arcadia/disk/admin/salt/${REPO} disk

mkdir -p /srv/salt/reactor
ln -s /etc/salt/pki/master/master_sign.pub.${ENVIRONMENT} /etc/salt/pki/master/master_sign.pub
mkdir /etc/salt/public
ln -s /etc/salt/pki/master/master_sign.pub.${ENVIRONMENT} /etc/salt/public/master_sign.pub
ln -sf /etc/ssl/allCAs.pem /etc/ldap/certs/cafile.pem
rm -f /etc/cron.d/salt-backup /etc/monrun/conf.d/push-client* /etc/monrun/conf.d/cauth_cache.conf

echo $ENVIRONMENT > /etc/yandex/environment.type
echo "prestart hook executer successfully"
