Sophie

Sophie

distrib > Mandriva > 10.2 > x86_64 > by-pkgid > ff3ee324c0567e1c25614ef618e7dd7f > files > 21

clusterautosetup-2.1-5mdk.src.rpm

#!/bin/sh
# version 2.1 
# plz report error : clic-dev-public@mandrakesoft.com


###################################################################################
# set variables
###################################################################################
CONFFILE="/etc/clusterclient.conf"
if  [ ! -f ${CONFFILE} ]; then
	echo "Cant find ${CONFFILE} !"
	exit 1
fi
. ${CONFFILE}

WORK_DIR="/tmp/setupclient"

echo " - Using ${NEXT_SERVERIP} tftpserver"

###################################################################################
# retrieve auth_pub.pem id_rsa.pub machines.LINUX from SERVER
###################################################################################
retrieve_key() {
echo " - Getting $KEY_AUTH and $KEY_SSH Key"
cd ${WORK_DIR}
tftp ${NEXT_SERVERIP} >1 <<EOF
get $KEY_AUTH
get $KEY_SSH
EOF
}


###################################################################################
# retrieve mpi key 
###################################################################################
retrieve_mpi() {
echo " - Getting machines.LINUX file for MPI"
cd ${WORK_DIR}
tftp ${NEXT_SERVERIP} >1 <<EOF
get $MPI_COMPUTER
get $LAM_NODE
EOF

}

###################################################################################
# check existence of ~/.ssh directory
###################################################################################
check_sshdir() {
echo " - Checking ssh dir for user"
if [ ! -d ${USER_SSH_DIR} ]; then
	mkdir ${USER_SSH_DIR}
fi
}

###################################################################################
# updating ~/.ssh/authorized_keys on client nodes
###################################################################################
update_sshkey_client() {
echo " - Updating sshkey for user"
check_sshdir
if [ -f  ${USER_SSH_DIR}/authorized_keys ]; then 
	cp -f ${USER_SSH_DIR}/authorized_keys ${USER_SSH_DIR}/authorized_keys.${DATE}.sauv
else
	touch ${USER_SSH_DIR}/authorized_keys
fi

CHECK_KEY="`grep ${NEXT_SERVER} ${WORK_DIR}/${KEY_SSH}`"
if [ -z "${CHECK_KEY}" ]; then
	cat ${WORK_DIR}/${KEY_SSH} >>  ${USER_SSH_DIR}/authorized_keys
else
	grep -vi ${NEXT_SERVER} ${USER_SSH_DIR}/authorized_keys.${DATE}.sauv > ${USER_SSH_DIR}/authorized_keys 
	cat ${WORK_DIR}/${KEY_SSH} >>  ${USER_SSH_DIR}/authorized_keys
fi
}

###################################################################################
# replace auth_pub.pem key
###################################################################################
update_authdkey_client() {
	echo " - Updating ${KEY_AUTH} key"
cp -f ${WORK_DIR}/${KEY_AUTH} /etc/${KEY_AUTH}
}

###################################################################################
# replace with good machine.LINUX file
###################################################################################
update_mpimachine_client() {
echo " - Updating ${MPI_COMPUTER} list"
cp -f ${MPICH_DIR}/${MPI_COMPUTER} ${MPICH_DIR}/${MPI_COMPUTER}.${DATE}.sauv
cp -f ${LAM_NODES_FILE} ${LAM_NODES_FILE}.${DATE}.sauv
cp -f ${WORK_DIR}/${MPI_COMPUTER} ${MPICH_DIR}/${MPI_COMPUTER}
cp -f ${WORK_DIR}/${LAM_NODE} ${LAM_NODES_FILE}
}

###################################################################################
# removing some anoying service for a cluster node
###################################################################################
service_adjust() {
echo " - Stopping anoying services"
chkconfig_stop() {
chkconfig --level 2345 $1 off
}

stop_service() {
CHECK_SERVICE_STAT=`pidof ${1}`
if [ ! -z "${CHECK_SERVICE_STAT}" ]; then
        echo "- stoping ${1} service:"
        ${INITRD}/${1} stop
fi
}

check_service() {
if [ -f ${INITRD}/${1} ]; then
	stop_service ${1}
	chkconfig_stop ${1}
fi
}

# stopping started anoying services
check_service alsa
check_service anacron
check_service linuxconf
check_service netfs
check_service atd
check_service crond
check_service kheader
check_service rawdevices
check_service partmon
check_service sound
check_service numlock
check_service usb
check_service usbd
check_service kudzu
check_service harddrake
check_service ntpd
}

###################################################################################
# recup nisdomainname
###################################################################################
recup_nisdomain() {
cp -f ${NETWORKFILE} ${NETWORKFILE}.${DATE}
grep -vi NISDOMAIN ${NETWORKFILE}.${DATE} > ${NETWORKFILE}
echo "NISDOMAIN=${NISDOMAIN}" >> ${NETWORKFILE}
nisdomainname ${NISDOMAIN}
}


###################################################################################
# setup nis client 
###################################################################################
nis_config() {
echo " - Adjusting NIS configuration"
recup_nisdomain
CHECK_YPCONF=`grep ${NISSERVER} /etc/yp.conf`

if [ -z "${CHECK_YPCONF}" ]; then
	# echo "server ${NISSERVER} broadcast" >> /etc/yp.conf
	echo "domain ${NISDOMAIN} server ${NISSERVER}" > /etc/yp.conf
	nisdomainname ${NISDOMAIN}
fi

service ypbind restart
service autofs restart
}

###################################################################################
# active rsh service
###################################################################################
activrsh() {
RSHXINETD="/etc/xinetd.d/rsh"
if [ ! -z ${RSHXINETD} ]; then 
echo " - RSH enable" 
perl -pi -e 's/disable.*/disable \= no/' ${RSHXINETD}
service xinetd restart 
fi
}


###################################################################################
# recup domain and hostname
###################################################################################
recup_domain() {
cp -f ${NETWORKFILE} ${NETWORKFILE}.${DATE}
grep -vi DOMAINNAME ${NETWORKFILE}.${DATE} > ${NETWORKFILE}
echo "DOMAINNAME=${DOMAIN}" >> ${NETWORKFILE}
domainname ${DOMAIN}
}

recup_hostname() {
cp -f ${NETWORKFILE} ${NETWORKFILE}.${DATE}
grep -vi HOSTNAME ${NETWORKFILE}.${DATE} > ${NETWORKFILE}
rm -rf /etc/sysconfig/network-scripts/draknet_conf*
}


###################################################################################
# recup ntp server conf
###################################################################################
sync_time() {
echo    " - Getting NTP server configuration "
echo -n "   |- NTP Server is "
cd ${WORK_DIR}
tftp ${NEXT_SERVERIP} >1 <<EOF
get $NTPFILE
EOF
NTP=$(cat ${WORK_DIR}/$NTPFILE)
echo $NTP
ntpdate $NTP
}

restart() {
sync_time
retrieve_key
retrieve_mpi
update_sshkey_client
update_authdkey_client
update_mpimachine_client
}

pamdX() {
cat > /etc/pam.d/xserver <<EOF
#%PAM-1.0
auth       sufficient   /lib/security/pam_rootok.so
auth       required     /lib/security/pam_permit.so
account    required     /lib/security/pam_permit.so
EOF
}

add_bg_xdm() {
XDMCONFIG_DIR="/etc/X11/xdm"
TESTBG=`grep /etc/X11/clic-1024.jpg ${XDMCONFIG_DIR}/Xsetup_0`
if [ -z "${TESTBG}" ]; then
echo " - Configuring XDM background"
cat > ${XDMCONFIG_DIR}/Xsetup_0 <<EOF
if [ -x /etc/X11/xinit/fixkeyboard ]; then
       /etc/X11/xinit/fixkeyboard
fi
/usr/X11R6/bin/xsetbg /etc/X11/clic-1024.jpg
EOF
echo "xlogin*geometry: 400x250-30-340" >> ${XDMCONFIG_DIR}/Xresources
fi
}

#########################
# setup client pbs
#########################
pbs_set() {
/usr/bin/setup_pbs_client ${NEXT_SERVER}
}

###################################################################################
# fix alternatives entries
# Done due to strange alternative bug
###################################################################################
fix_alternatives() {
update-alternatives --auto cpp
}

###################################################################################
# all functions
###################################################################################
all() {
fix_alternatives
sync_time
recup_domain
retrieve_key
retrieve_mpi
update_sshkey_client
update_authdkey_client
update_mpimachine_client
service_adjust
recup_hostname
pbs_set
pamdX
add_bg_xdm
nis_config
activrsh
}

###################################################################################
###################################################################################
#       		MAIN PROGRAM
###################################################################################
###################################################################################

if [ -z $IPOFCLIENT ]; then
echo "!!!!!!!!!!!!!! ERROR !!!!!!!!!!!"
echo "Network is not working !"
echo "Exiting !"
exit 1
fi

###################################################################################
# create Working directory
###################################################################################
if [ ! -d "${WORK_DIR}" ] ; then 
	mkdir ${WORK_DIR}
	else 
		if [ -z ${WORK_DIR} ]; then 
		echo "Be carefull WORK_DIR has not been set !"
		exit 1
		else
		rm -rf ${WORK_DIR}/*
		fi
fi


###################################################################################
# function call by clusterautosetup
###################################################################################
if [ $# -lt 1 ]; then
	echo 
        echo " usage $0: {activrsh|recup_domain|sync_time|retrieve_mpi"
	echo "            update_mpimachine_client|retrieve_key_client|"
	echo "		  update_authdkey_client|recup_hostname"
        echo "            update_sshkey|nis_config|service_adjust|all}"
	echo
        echo " HELP:" 
        echo " |-----------------------------------------------------------------|"
	echo " | activrsh:               active the rsh service on node          |"
	echo " | recup_domain:           retrieve the domain name for node       |"
	echo " | sync_time:              synchronize time with server            |"
	echo " | retrieve_mpi:           get the machines.LINUX file from server |"
	echo " | update_mpimachine:      update the file on node                 |"
	echo " | retrieve_key:           get ssh_key and authd_key from server   |"
	echo " | update_authdkey_client: update authd key on node                |"
	echo " | update_sshkey_client:   update ssh key on node                  |"
	echo " | nis_config:             configure node with nis domain          |"
	echo " | recup_hostname:         set hostname                            |"
	echo " | service_adjust:         disable anoying on node                 |"
	echo " | all:                    all above                               |"
        echo " |-----------------------------------------------------------------|"
	echo
	else
	$1
fi