#!/bin/bash
# (c) 2002-2003 Newisys, Inc.  All rights reserved.
#
# Example shell script to set up ADS configuration on a set of Service Processors
# so that users can be authenticated against a Microsoft Active Directory Service.
#
# Requires: 
#    sp-ips.txt file with list of IP addresses for each Service Processor to connect to.
#    To be run from an SSH client. 
#    other requirements detailed below
# See documentation for more information about commands.
#
# This loop sets up the Service Processors' DNS configurations. 
for ip in `cat sp-ips.txt` ; do
   echo "Enabling DNS for IP: $ip";
   ssh $ip sp enable dns --nameserver 10.10.31.1 --nameserver 10.10.31.2 --searchdomain SW-AD-TEST.LOCAL
   if [ $? != 0 ]; then
      echo Error enabling DNS for SP $ip 
   fi    
done

# Changing the DNS configuration causes the
# SSH daemon to restart.
# Allow time for it to come back up.
echo Giving SSH daemons time to restart ...
sleep 15
for ip in `cat sp-ips.txt` ; do
   echo "Changing DNS configuration for IP: $ip";
   # Assuming our system clock is accurate, 
   # set the Service Processors clock against ours. 
   # The "sp set date" command requires a UTC date 
   # of the form YYYY-MM-DD HH-MM-SS using a 24 hour # clock format.
   ssh $ip sp set date \"`date --utc "+%Y-%m -%d %H:%M:%S"`\"
   
   # ADS configuration requires a pre-fabricated 
   # keytab file to exist on the Service Processor. Since we have a 
   # trusted host setup, we can scp from the client 
   # without a login.
   scp sp.keytab $ip:/home/manager
   
   # Now set up ADS.
   ssh $ip access enable service ads \
    --keytab /home/manager/sp.keytab \
    --ou "cn=Users,dc=SW-AD-TEST,dc=LOCAL" \
    --server sw-test-dc \
    --domain SW-AD-TEST.LOCAL \
    --logon sample-sp
   if [ $? != 0 ]; then
      echo Error configuring DNS for SP $ip 
   fi
   
   # Remove the keytab.
   ssh $ip rm -f /home/manager/sp.keytab
done