netapp autologin.sh script

#!/bin/bash

#setup autologin

ERRLOG='autologin.errorlog'

function key {
hostname=`hostname`

#determine mode
echo -n "clustermode? (y/n) : "
read mode
if [ $mode == "y" ]
then
echo "clustermode"
echo -n "username : "
read user

#get the current index to determine the next one
echo "getting index..."
echo "admin password needed..."
index=`ssh admin@$name security login publickey show | grep -i index | wc -l ` >/dev/null 2>>$ERRLOG
((index+=1))

#check for available pubkey and exit if negative
#add authmethod and key
if cat $HOME/.ssh/id_dsa.pub > /dev/null 2>>$ERRLOG
then
set `cat $HOME/.ssh/id_dsa.pub`
echo "admin password needed..."
ssh admin@$name security login create -username $user -application ssh -authmethod publickey -profile admin >/dev/null 2>>$ERRLOG
echo "adding key with index $index"
echo "admin password needed..."
ssh admin@$name security login publickey create -username $user -index $index -publickey \"$@\" >/dev/null 2>>$ERRLOG
else
if cat $HOME/.ssh/id_rsa.pub > /dev/null 2>>$ERRLOG
then
key=`cat $HOME/.ssh/id_rsa.pub`
echo "admin password needed..."
ssh admin@$name security login create -username $user -application ssh -authmethod publickey -profile admin >/dev/null 2>>$ERRLOG
echo "adding key with index $index"
echo "admin password needed..."
ssh admin@$name security login publickey create -username $user -index $index -publickey "$key1 $key2 $key3" >/dev/null 2>>$ERRLOG

else
echo "no public keys found"
echo "run ssh-keygen -t rsa or ssh-keygen -t dsa"
echo exiting
exit
fi
fi

#install licenses
echo "Adding license keys for cmode..."
for i in `cat cmodelicenses`
do
ssh $user@$name license add $i >/dev/null 2>>$ERRLOG
done
ssh $user@$name license show
else
#install nfs license mount the rootvolume and create authorized_keys
echo "7-mode"
ip=`cat /etc/hosts|grep $hostname | cut -f1 -d" "`
echo "setting up autologin to $name for $ip"
echo "provide root-password for $name"
echo "adding licenses..."
set `cat ./7modelicenses`
echo "root password needed..."
ssh $name license add $* > /dev/null 2>>$ERRLOG
echo "exporting and mounting vol0..."
echo "root password needed..."
ssh $name exportfs -i -o rw,root=$ip,nosuid /vol/vol0
mkdir -p /mnt/$name
mount $name:/vol/vol0 /mnt/$name
mkdir -p /mnt/$name/etc/sshd/root/.ssh
echo "copy public key..."
if cat $HOME/.ssh/id_dsa.pub > /dev/null 2>>$ERRLOG
then
cat $HOME/.ssh/id_dsa.pub >> /mnt/$name/etc/sshd/root/.ssh/authorized_keys
else
if cat $HOME/.ssh/id_rsa.pub > /dev/null 2>>$ERRLOG
then
cat $HOME/.ssh/id_rsa.pub >> /mnt/$name/etc/sshd/root/.ssh/authorized_keys
else
echo "no public keys found"
echo "run ssh-keygen -t rsa or ssh-keygen -t dsa"
echo exiting
exit
fi
fi
echo "unmounting vol0..."
umount -f /mnt/$name
echo "done!"
fi
}

function check {
if [ $mode == "y" ]
then
echo "try to connect with : ssh ${user}@${name}"
else
echo "try to connect with : ssh root@$name"
fi
}

#main
#gather info
echo "setup autologin for netapp filers 7-mode and cmode"

echo -n "filer (name/ip) : "
read name

#echo -n "is autologin configured for $name (y/n)? : "
#read input
#if [ $input == "y" ]
# then
# :
# echo "done!"
# else
echo -n "set autologin (y/n) ? : "
read input
if [ $input == "n" ]
then
:
else
key
check
# fi
fi
echo "Check autologin.errorlog for errors"

This entry was posted in linux, netapp, scripts. Bookmark the permalink.

Comments are closed.