#!/bin/bash
##Change client part at desktop like /media/nfs /mdia/smb instead of/nfsclient /smbclient thanks born 2010/12/25
#
##Add some justices of user input fix bug in /etc/exports.2011/01/26
#
##Rewirte some codes and add function ip_check() to make things better 2011/05/09
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
clear
if test "$EUID" != 0 ; then
echo -e "\033[42;37;5m This Shell Need SuperUser Private!!! \033[0m "
exit
fi
function welcome()
{
SuSEfirewall2 off >/dev/null 2>&1
echo -e "\033[42;37;5m #####The IP of Your UUT is:###### \033[0m "
for i in {0,1,2,3} ###,4,5,6,7,8,9} #多种IP表达的可能 eth0 eth1 eth2...
do
MYIP="eth$i"
ifconfig $MYIP >/dev/null 2>&1
if [ $? == 0 ] ;then
ifconfig $MYIP | grep 'inet ' | sed 's/^.*addr://g'| sed 's/Bcast.*$//g'
fi
done
#born point this place
mkdir -p /media/nfs
mkdir -p /media/smb
echo "************************************************"
echo "*Select which services do you want establish: *"
echo "* (1): SMB Server *"
echo "* (2): SMB Client *"
echo "* *"
echo "* (3): NFS Server *"
echo "* (4): NFS Client *"
echo "* *"
echo "* (5): Map Windows Sever(FTP) *"
echo "* (6): exit *"
echo "************************************************"
read -p "Your Choice is :" choice
case $choice in
"1")
s_smb
;;
"2")
c_smb
;;
"3")
s_nfs
;;
"4")
c_nfs
;;
"5")
m_window
;;
"6")
exit
;;
*)
echo -e "\033[42;37;5m @@@@@@@@@Error Input!PLZ Check@@@@@@@@@@@ \033[0m "
exit
;;
esac
}
function s_smb()
{
configfile=/etc/samba/smb.conf
test -e /smbserver && echo || mkdir -p /smbserver
#mkdir /smbserver
touch /smbserver/hellosmb
echo "Hello this is a smb test!! " >> /smbserver/hellosmb && date >> /smbserver/hellosmb
useradd -m smb
echo "############PassWord############"
echo -e "Now ,you'd asgin PSW for user(smb): \n "
##passwd cmlinux compaq
smbpasswd -a smb
chown smb /smbserver
chmod 777 /smbserver
echo "############Justice############"
if [ "`grep -c "smbserver" $configfile`" == "1" ] ;then
echo "@@@Write Faild@@@@...."
echo "***********Can't Write Into smb.Conf****** "
else
echo "########Write into smb.Conf successfully#####"
echo "[smb]
comment = smbshare test
path = /smbserver
writeable = yes
read only = no
browsable = yes
valid user = smb
guest ok = ok" >> $configfile
fi
echo "############StartSMB############"
/etc/init.d/smb restart
sleep 5
/etc/init.d/smb start
/etc/init.d/smb start
echo "############Status############"
/etc/init.d/smb status
}
#检查IP的合法性(但不包括 正确性)
function ip_check()
{
read -p "Input the IP of NFS/SMB server: " ip
echo "$ip" > /tmp/iptemp
cat /tmp/iptemp | awk 'BEGIN {FS="."} {if(NF != 4) print "ERROR IP@_@";
else
for ( i=1;i<= NF;i++ )
###***//test2= `echo $i | grep '[^0-9]'`
###***//if (test2 !="")
if ( $i < 255 && $i > 0 ) print "GOOD!";
else print "ERROR IP@_@"; }'| grep -c "ERROR IP@_@" >0 && echo "IP输入错误请重新输入" && ip_check
}
#else printf("%d number of [%s] check pass^_^\n",i,$ip)}'
function c_smb()
{
test -e /media/smb && echo || mkdir -p /media/smb
ip_check;
mount -t cifs //$ip/smb /media/smb -o username=smb
exeresult;
}
function s_nfs()
{
echo "#############NFS_BEGIN#################"
if [ "`grep -c "*(rw)" /etc/exports `" == "0" ] ;then
echo "/nfs *(rw)" >> /etc/exports
echo "Write Success!"
else
echo "Write Failed!"
fi
test -e /nfs && echo || mkdir -p /nfs
chmod 777 /nfs
touch /nfs/helloword
echo "Hello this is a nfs test!! " >> /nfs/hellonfs && date >> /nfs/hellonfs
chkconfig -a nfsserver
/etc/init.d/nfsserver restart
rpcinfo -p localhost | grep nfs
echo "##############NFS SUCCESSFULL#######################"
}
function c_nfs()
{
test -e /media/nfs && echo || mkdir -p /media/nfs
ip_check;
mount -t nfs $ip:/nfs /media/nfs
exeresult;
}
function m_window()
{
echo "挂在SCIT服务器,请确保接入局域网并自动获取IP(DHCP)"
mount -t cifs //10.106.170.99/hnbdrd /media/nfs/ -o username=ecmms/ksscit,passwd=Foxconn123
exeresult;
}
function exeresult()
{
if [ $? == "0" ];then
echo
echo -e "\033[42;37;5m #### MOUNTING SUCCESS ^_^ #### \033[0m "
echo
exit 0
else
echo
echo -e "\033[42;37;5m #### MOUNTING FAILED @_@ #### \033[0m "
exit 1
fi
}
welcome;
posted on 2011-05-13 08:47
Nietzsche 阅读(37)
评论(0) 编辑 收藏 引用