#!/bin/bash
# Salt Minion 自动化部署

# 服务器命名规则：za-城市-线路
# 比如 北京 BGP，则命名为 za-bj-bgp
# 国外城市可以搜索该城市的常用缩写

server_name=$1

if [[ $# -ne 1 ]]
then
	echo "Usage: $0 Server_name"
	exit 1
fi

yum install -y salt-minion

sed -i 's/#master: salt/master: monitor.wy.net/g' /etc/salt/minion
sed -i 's/#master_port: 4506/master_port: 54506/g' /etc/salt/minion
sed -i 's/#tcp_pub_port: 4510/tcp_pub_port: 54510/g' /etc/salt/minion
sed -i 's/#tcp_pull_port: 4511/tcp_pull_port: 54511/g' /etc/salt/minion

echo ${server_name}.wy.net > /etc/salt/minion_id

iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 54510 -j ACCEPT
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 54511 -j ACCEPT
service iptables save

chkconfig salt-minion on
service salt-minion start
