#!/bin/bash -

# Salt-Minion
#  command:
#    curl http://download.alphabets.cn/bin/setup.sh | sh -s -- hostname dnsserverip
#  params:
#    hostname
#    dnsserverip
#

############
# set dns server
####
sed -i "1s/^/search light.cn\n/" /etc/resolv.conf
sed -i "1s/^/nameserver $2\n/" /etc/resolv.conf

####
# set hostname
####
sed -i "s/HOSTNAME=.*/HOSTNAME=$1/g" /etc/sysconfig/network
hostname $1

############
# install epel
####
# rpm -Uvh http://download.alphabets.cn/lib/epel-release-7-5.noarch.rpm

####
# install salt-minion
####
yum -y install salt-minion

####
# set master address
####
sed -i "s/#master:.*/master: salt/g" /etc/salt/minion
sed -i "s/#id:.*/id: $1/g" /etc/salt/minion

####
# start service
####
systemctl start salt-minion
systemctl enable salt-minion

############
# install docker
####
yum -y install docker device-mapper

####
# enable docker api
####
sed -i "s/^OPTION.*/OPTIONS='--selinux-enabled -H tcp:\/\/127.0.0.1:2375 -H unix:\/\/\/var\/run\/docker.sock'/g" /etc/sysconfig/docker

####
# start service
####
systemctl start docker
systemctl enable docker

############
# install agent
####
yum -y install http://download.alphabets.cn/lib/zabbix-release-2.4-1.el7.noarch.rpm
yum -y install zabbix-agent

####
# config zabbix agent
####
sed -i "s/^Server=.*$/Server=zabbix.light.cn/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/^ServerActive=.*$/ServerActive=zabbix.light.cn/g" /etc/zabbix/zabbix_agentd.conf
sed -i "s/^Hostname=.*$/Hostname=$1/g" /etc/zabbix/zabbix_agentd.conf

####
# start service
####
systemctl start zabbix-agent
systemctl enable zabbix-agent
