# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.

VAGRANTFILE_API_VERSION = 2

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "sl68-nocm-0.1.0.box"
  config.vm.box_url = "http://sldist.fnal.gov/linux/fermi/contrib/vagrant/fermi-kerberized-ssh/box/virtualbox/sl68-nocm-0.1.0.box"
  #config.vm.box = "bento/centos-6.8"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  #config.vm.synced_folder "/Users", "/Users"
  #DISABLE synced folders, uncomment as needed
  config.vm.synced_folder ".", "/vagrant",disabled: true

  config.vm.provider "virtualbox" do |vb|
    # Customize the amount of memory on the VM:
    vb.memory = 1024 * 1
    vb.cpus = 1
    vb.name = "fermi-kerberized-ssh"
  end
  config.vm.define "fermi-kerberized-ssh" 

  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  config.vm.provision "shell", inline: "yum -y update" 
  config.vm.provision "shell", inline: "yum -y install krb5-workstation" 
  config.vm.provision "shell", inline: "wget --no-verbose http://computing.fnal.gov/authentication/krb5conf/Linux/krb5.conf -O /etc/krb5.conf"
  
  $script = <<'SCRIPT'
  PLATFORM_RELEASE=$(sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release) 
  MOTD_RELEASE=$(grep -v '\---' /etc/motd | sed 's/^.* \([0-9]\.[0-9]\).*/\1/')
  if [ -n $MOTD_RELEASE ] ; then
    sed -i -e "s/$MOTD_RELEASE/$PLATFORM_RELEASE/" /etc/motd
  else
    cp -a /etc/redhat-release /etc/motd
  fi
SCRIPT

  config.vm.provision "shell", inline:  $script 

  config.vm.provision "shell", inline: "chkconfig --level 2345 kdump off ;
                                        chkconfig --level 2345 mdmonitor off ;
                                        chkconfig --level 2345 netfs off ;
                                        chkconfig --level 2345 nfslock off ;
                                        service nfslock stop 1>/dev/null ;
                                        chkconfig --level 2345 postfix off ;
                                        service postfix stop 1>/dev/null ;
                                        chkconfig --level 2345 rpcbind off ;
                                        service rpcbind stop 1>/dev/null ;
                                        chkconfig --level 2345 rpcgssd off ; 
                                       "


  config.vm.provision "shell", inline: "echo '...PROVISIONING COMPLETE  '"

  config.vm.post_up_message = "** To Login to VM 

  * for 'Linux' or 'Mac' host

     'vagrant ssh' 

  * for 'Windows' host

     bring up VirtualBox gui with 'fermi_kerberized_ssh' VM 
     Use vagrant/vagrant as login/pw

** After Login to VM -- kerberos_user is your Fermi kerberos principal 

     'kinit kerberos_user'
     'ssh some_user@host.fnal.gov'


"
end
