自动安装脚本

LAMP自动安装脚本,为工作的时候,天天敲命令,autoinstall。

很垃圾的、没有什么华丽的语言、N年后,看看自己写的,能笑什么样、

安装程序就不拿出来了、代码如下:

<code>

#!/bin/sh

#autoinstall 自动安装脚本
#本脚本用于hrjd server安装使用
#跑去文档,傻瓜式安装。
#没有自动判断文件功能
#应该遵循文件名称,不然报错
#注意错误提示,及时排错
#所有安装文件必须放在/root/hrjd下面

#2010.10.09 by:key1088

#jiance code
ls /usr/cis7|grep server > test1
ps aux|grep httpd|grep -v grep >> test1
if [ -s test1 ];then
rm -f test1
echo -e " 33[31m----------------jiance-------------- 33[0m"
echo -e " 33[33m------server----- 33[0m"
ps aux|grep server|grep -v grep
echo -e " 33[33m------lowlessip----- 33[0m"
ps aux|grep lowlessip|grep -v grep
echo -e " 33[33m------guard----- 33[0m"
ps aux|grep guard|grep -v grep
echo -e " 33[33m------httpd port----- 33[0m"
netstat -an|grep :80
echo -e " 33[33m------mysql port----- 33[0m"
netstat -an|grep :3306
echo -e " 33[33m------mode----- 33[0m"
lsmod |grep blackwhite
echo -e " 33[33m------mybridge----- 33[0m"
ifconfig mybridge|grep "inet addr:"
echo -e " 33[31m----------------jiance-------------- 33[0m"
exit
fi
#setup code
cd /root/hrjd/
printf "Start Auto Install hrjd Server SoftWare      33[32m[ok] 33[0mn"
printf " 33[32m----------------bridge setuping------------------- 33[0mn"
tar zxvf bridge-utils-1.0.6.tar.gz
cd bridge-utils-1.0.6
printf " 33[32m----------------configure --prefix=/usr------------------- 33[0mn"
./configure --prefix=/usr
printf " 33[32m----------------make------------------- 33[0mn"
make
printf " 33[32m----------------make install------------------- 33[0mn"
make install
printf " 33[32m----------------make done------------------- 33[0mn"
cd /etc/sysconfig/network-scripts/
if [ -f ifcfg-eth0 ]; then
echo "DEVICE=eth0" > ifcfg-eth0
echo "ONBOOT=yes" >> ifcfg-eth0
echo "TYPE=Ethernet" >> ifcfg-eth0
echo "BRIDGE=mybridge" >> ifcfg-eth0
echo -e " 33[32mifcfg-eth0 config ok 33[0m"
fi
if [ -f ifcfg-eth1 ]; then
echo "DEVICE=eth1" > ifcfg-eth1
echo "ONBOOT=yes" >> ifcfg-eth1
echo "TYPE=Ethernet" >> ifcfg-eth1
echo "BRIDGE=mybridge" >> ifcfg-eth1
echo -e " 33[32mifcfg-eth1 config ok 33[0m"
fi
if [ -f ifcfg-eth2 ]; then
echo "DEVICE=eth2" > ifcfg-eth2
echo "ONBOOT=yes" >> ifcfg-eth2
echo "TYPE=Ethernet" >> ifcfg-eth2
echo "BRIDGE=mybridge" >> ifcfg-eth2
echo -e " 33[32mifcfg-eth2 config ok 33[0m"
fi
if [ -f ifcfg-eth3 ]; then
echo "DEVICE=eth3" > ifcfg-eth3
echo "ONBOOT=yes" >> ifcfg-eth3
echo "TYPE=Ethernet" >> ifcfg-eth3
echo "BRIDGE=mybridge" >> ifcfg-eth3
echo -e " 33[32mifcfg-eth3 config ok 33[0m"
fi
if [ -f ifcfg-eth4 ]; then
echo "DEVICE=eth4" > ifcfg-eth4
echo "ONBOOT=yes" >> ifcfg-eth4
echo "TYPE=Ethernet" >> ifcfg-eth4
echo "BRIDGE=mybridge" >> ifcfg-eth5
echo -e " 33[32mifcfg-eth4 config ok 33[0m"
fi
if [ -f ifcfg-eth5 ]; then
echo "DEVICE=eth5" > ifcfg-eth5
echo "ONBOOT=yes" >> ifcfg-eth5
echo "TYPE=Ethernet" >> ifcfg-eth5
echo "BRIDGE=mybridge" >> ifcfg-eth5
echo -e " 33[32mifcfg-eth5 config ok 33[0m"
fi
echo "DEVICE=mybridge" > ifcfg-mybridge
echo "BOOTPROTO=static" >> ifcfg-mybridge
echo "ONBOOT=yes" >> ifcfg-mybridge
echo "TYPE=Bridge" >> ifcfg-mybridge
echo "NETMASK=255.255.255.0" >> ifcfg-mybridge
echo "IPADDR=192.168.0.204" >> ifcfg-mybridge
echo "GATEWAY=192.168.0.1" >> ifcfg-mybridge
echo "STP=on" >> ifcfg-mybridge
if [ -f ifcfg-mybridge ]; then
echo -e " 33[32mifcfg-mybridge config ok 33[0m"
fi
printf " 33[32m----------------bridge Done------------------- 33[0mn"
cd /root/hrjd
printf " 33[32m----------------MySql Setup------------------- 33[0mn"
cp my.cnf /etc/my.cnf
rpm -ivh mysql-client-5.0.22-0.i386.rpm
sleep 1
rpm -ivh mysql-devel-5.0.22-0.i386.rpm
sleep 1
rpm -ivh mysql-shared-5.0.22-0.i386.rpm
sleep 1
rpm -ivh mysql-server-5.0.22-0.i386.rpm
ps aux|grep mysql|grep -v grep > test1
if [ -s test1 ];then
echo -e " 33[32m----mysql runing ok---- 33[0mn"
mysqladmin -u root password 123
mysql -uroot -p123 -e "grant all on *.* to 'root'@'%' identified by '123'"
mysql -uroot -p123 -e "flush privileges"
iptables -F
rm -r test1
echo -e " 33[32m----------------MySql Setup Done-------------- 33[0mn"
else
echo -e " 33[31m----mysql no runing---- 33[0mn"
echo -e " 33[31m----mysql Setup error"
fi
printf " 33[32m---------------Apache Setup------------------- 33[0mn"
tar zxvf httpd-2.2.9.tar.gz
cd httpd-2.2.9
printf " 33[32m------------Apache ./config------------------- 33[0mn"
./configure --prefix=/usr/local/apache2 --enable-so -enable-rewrite
printf " 33[32m----------------Apache make------------------- 33[0mn"
make
printf " 33[32m----------Apache make install----------------- 33[0mn"
make install
cd /root/hrjd
cp -a ruqinjiance/ /usr/local/apache2/htdocs/
mv /usr/local/apache2/conf/httpd.conf /usr/local/apache2/conf/httpd.conf.bak
cp -a httpd.conf /usr/local/apache2/conf/httpd.conf
printf " 33[32m-------------Apache Setup Done---------------- 33[0mn"
printf " 33[32m-----------------PHP Setup-------------------- 33[0mn"
tar zxvf php-5.2.11.tar.gz
cd php-5.2.11
printf " 33[32m----------------PHP ./config ----------------- 33[0mn"
./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/bin/mysql --with-config-file-path=/usr/local/apache2/conf --enable-sockets
make
make install
cd /root/hrjd
mv /usr/local/php5/php.ini /usr/local/php5/php.ini.bak
cp php.ini /usr/local/php5/php.ini
printf " 33[32m----------------PHP Setup Done----------------- 33[0mn"
printf " 33[32m---------------HRJD SERVER Setup--------------- 33[0mn"
cp /root/hrjd/hrjd.tar /usr/hrjd.tar
cd /usr
tar xvf hrjd.tar
cd /root/hrjd
chmod 755 rc.local
mv /etc/rc.d/rc.local /etc/rc.d/rc.local.bak
cp /root/hrjd/rc.local /etc/rc.d/rc.local
ls /dev/|grep hda > test1
if [ -s test1 ];then
echo -e " 33[32m------------IDE HD ID--------------"
hdparm -i /dev/hda|grep SerialNo
echo -e "------------IDE HD ID-------------- 33[0m"
rm -rf test1
else
chmod 777 sata
echo -e " 33[32m------------SAST HD ID--------------"
./sata
echo -e "------------SAST HD ID-------------- 33[0m"
fi
printf "HRJD Server setup ok"
getchar() {
    stty cbreak -echo
    dd if=/dev/tty bs=1 count=1 2> /dev/null
    stty -cbreak echo
}
printf " 33[32m-----------------press any key reboot----------------- 33[0m"
ret=`getchar`
echo
reboot

</code>