#!/bin/bash 
 
if [[ $EUID -ne 0 ]]; then 
   echo "This script must be run as root" 
   exit 1 
fi 
 
 
# install salt and set master in config file 
pacman --noconfirm -Sy salt-zmq 
sed -i -e"s/^#master\s*:\s*salt/master: salt.local.lan/" /etc/salt/minion 
sed -i -e"s/^#master_finger\s*:\s*\'\'/master_finger: \''xx:xx:xx:xx:xx:xx:xx'\'/" /etc/salt/minion 
 
# add local domain to minion_id 
echo -n "$HOSTNAME.local.lan" >> /etc/salt/minion_id 
 
 
 
# add logrotate config 
cat <<EOL >> /etc/logrotate.d/salt 
/var/log/salt/key /var/log/salt/master /var/log/salt/minion  { 
        nocompress 
        missingok 
        postrotate 
                /bin/kill -HUP \`cat /var/run/salt/salt-minion.pid 2>/dev/null\` 2> /dev/null || true 
        endscript 
} 
EOL 
 
systemctl restart logrotate


# show minion id 
MINION_ID=`cat /etc/salt/minion_id` 
echo "" 
echo "minion_id set to : $MINION_ID" 
echo "   => check that this hostname is declared in local dns" 
echo "" 
 
 
# enable & start service 
systemctl enable salt-minion 
systemctl start salt-minion 
sleep 2 
 
 
# final word 
echo "" 
ps ax | grep salt 
echo "" 
echo "" 
echo "type the following on the master to authorize this minion:" 
echo "salt-key -a $MINION_ID"

 
