Last active
October 2, 2015 12:47
-
-
Save moos3/c6a1e0a2d94f8430fdd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
fn_distro(){ | |
arch=$(uname -m) | |
kernel=$(uname -r) | |
if [ -f /etc/lsb-release ]; then | |
os=$(lsb_release -s -d) | |
installer='apt-get' | |
elif [ -f /etc/debian_version ]; then | |
os="Debian $(cat /etc/debian_version)" | |
installer='apt-get' | |
elif [ -f /etc/redhat-release ]; then | |
os=`cat /etc/redhat-release` | |
installer='yum' | |
else | |
os="$(uname -s) $(uname -r)" | |
fi | |
} | |
fn_distro | |
echo "Setting postfix" | |
echo "current hostname is: $(hostname) Is this the correct FQDN ?[Y/n]" | |
read -e -n 1 yes_no | |
if [[ $yes_no == "n" ]];then | |
echo "please enter the correct hostname:" | |
read -e myhostname | |
elif [[ $yes_no == "y" || ! -n $yes_no || -z $yes_no ]];then | |
echo "proceeding with the following hostname: $(hostname)" | |
myhostname=`hostname` | |
fi | |
echo "Enter the domain which mail should be sent as:" | |
read -e mymaildomain | |
if [ -z $mymaildomain ];then | |
echo "You must have a domain name to send mail as" | |
exit 1; | |
fi | |
echo "Please enter any networks that you want to allow postfix to use. seperate with spaces ie. 172.16.0.0/16 10.0.0.0/8" | |
echo "default networks are localhost host only. Just press enter for localhost" | |
read -e mynetworks | |
if [[ ! -n $mynetworks || -z $mynetworks ]];then | |
mynetworks="" | |
fi | |
echo "setting up chef" | |
mkdir -p /var/chef-solo/cookbooks | |
mkdir -p /var/chef-solo/attributes | |
mkdir -p /var/chef-solo/cache | |
echo ' | |
file_cache_path "/var/chef-solo/cache" | |
cookbook_path "/var/chef-solo/cookbooks" | |
json_attribs "/var/chef-solo/attributes/node.json" | |
' > /var/chef-solo/solo.rb | |
echo "Installing GIT" | |
if [ $installer == 'apt-get' ];then | |
echo "my installer is: $installer" | |
apt-get install -y git | |
elif [ $installer == 'yum' ];then | |
echo "my installer is: $installer" | |
yum install git | |
else | |
echo "OS isn't supported" | |
exit 1 | |
fi | |
echo "Installing Chef" | |
`curl -L https://www.opscode.com/chef/install.sh | bash` | |
echo "fetching cookbooks" | |
git clone https://github.com/chef-cookbooks/postfix.git /var/chef-solo/cookbooks/postfix | |
echo -e " | |
{ | |
\"postfix\": { | |
\"mail_type\": \"master\", | |
\"main\": { | |
\"myhostname\": "\"$myhostname\"", | |
\"mydomain\": "\"$mymaildomain\"", | |
\"mynetworks\": [ | |
\"127.0.0.0/8\", | |
\"[::1]/128\", | |
\"[fe80::]/10\", | |
\""$mynetworks\"" | |
], | |
\"mydestination\": \"\", | |
\"inet_interfaces\": \"loopback-only\" | |
} | |
}, | |
\"run_list\": [ \"recipe[postfix]\"] | |
} | |
" > /var/chef-solo/attributes/node.json | |
echo "Running Provisioning" | |
chef-solo -c /var/chef-solo/solo.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment