2011年3月17日 星期四

build a phplist all-in-one disc iso

[root@HTS099 ~]# mkdir -p /burn/phplist-centos
[root@HTS099 ~]# cd /burn


#可能會有某些檔案在Linux Copy會有錯誤,建議可以在Windows上COPY下來後再傳過來
[root@HTS099 burn]# cp -R /media/CENTOS55\ i386\ DVD/* /burn/phplist-centos/.
[root@HTS099 phplist-centos]# cd /burn/phplist-centos/
[root@HTS099 phplist-centos]# ls -la /media/CENTOS_5.5\ i386\ DVD/.
./ ../ .discinfo .treeinfo
[root@HTS099 phplist-centos]# cp /media/CENTOS_5.5\ i386\ DVD/.discinfo /burn/phplist-centos/.
[root@HTS099 phplist-centos]# cp /media/CENTOS_5.5\ i386\ DVD/.treeinfo /burn/phplist-centos/.
製作安裝光碟需要將isolinux移出來
[root@HTS099 phplist-centos]# cp -R isolinux /burn/.

#建立這個目前主要是擺放此次要額外安裝的相關檔案原始壓縮檔
[root@HTS099 phplist-cab]# mkdir extras

#複製原始phpMyAdmin的壓縮檔到extras
[root@HTS099 html]# ls -l /root/Downloads/phpMyAdmin-2.11.11.3-all-languages.tar.gz
-rw-r--r--. 1 root root 4316983 Mar 17 13:33 /root/Downloads/phpMyAdmin-2.11.11.3-all-languages.tar.gz
[root@HTS099 html]# cp /root/Downloads/phpMyAdmin-2.11.11.3-all-languages.tar.gz /burn/phplist-centos/extras/.

#複製原始phplist的壓縮檔到extras(備份用)
[root@HTS099 phplist-cab]# ls -l ~/Downloads/phplist*
-rw-r--r--. 1 root root 2317926 Mar 14 11:34 /root/Downloads/phplist-2.10.13.tgz
[root@HTS099 phplist-cab]# cp /root/Downloads/phplist-2.10.13.tgz /burn/phplist-centos/extras/.

#複製phplist自動安裝相關所需的設定檔跟壓縮檔到extras(建置用)
[root@HTS099 ~]#cd /burn/phplist-centos/extras
[root@HTS099 ~]#cp -R /extras /burn/phplist-centos/.
[root@HTS099 ~]#ls -l /burn/phplist-centos/
-rw-r--r--. 1 root root 129 Apr 17 11:24 creation.sql [mysql 權限設定]
-rw-r--r--. 1 root root 103903 Apr 17 11:24 libmcrypt-2.5.7-4.el4.centos.i386.rpm [phpMyAdmin安裝必要套件]
-rw-r--r--. 1 root root 92788 Apr 17 11:24 libmcrypt-devel-2.5.7-4.el4.centos.i386.rpm
[phpMyAdmin安裝必要套件]
-rw-r--r--. 1 root root 176419 Apr 17 11:24 libmhash-0.9.1-1.2.el5.rf.i386.rpm [phpMyAdmin安裝必要套件]
-rw-r--r--. 1 root root 88202 Apr 17 11:24 mcrypt-2.6.8-1.el5.i386.rpm phpMyAdmin安裝必要套件]
-rwxr-xr-x. 1 root root 40890 Apr 17 11:24 migration.sh [安裝光碟自動安裝後,postscript執行安裝phplist及phpMyAdmin必要scripts檔]
-rw-r--r--. 1 root root 2317926 Apr 17 11:24 phplist-2.10.13.tgz [phplist安裝包]
-rw-r--r--. 1 root root 5206 Apr 17 11:24 phplist.cnf [給migration.sh執行時的設定檔,內存phplist必要設定]
-rw-r--r--. 1 root root 993136 Apr 17 11:24 php-mbstring-5.1.6-3.el4s1.10.i386.rpm
[phpMyAdmin安裝必要套件]
-rw-r--r--. 1 root root 15115 Apr 17 11:24 php-mcrypt-5.1.6-1.el4.centos.i386.rpm [phpMyAdmin安裝必要套件]
-rw-r--r--. 1 root root 4316983 Apr 17 11:24 phpMyAdmin-2.11.11.3-all-languages.tar.gz [phpMyAdmin安裝包]
-rw-r--r--. 1 root root 3642 Apr 17 11:24 sysproc.php [phplist新增systool選單功能的網頁]
-rw-r--r--. 1 root root 3278 Apr 17 11:24 systool.php
[phplist新增systool選單功能的網頁]


#製作kickstart file
[root@HTS099 ~]# cp /root/ks.cfg /burn/phplist-centos/ks.cfg
#
# Kickstart configuration file
#

#linux ks=cdrom:/ks.cfg ipaddr=172.16.43.144 gateway=172.16.43.1 netmask=255.255.255.0 ListRoot=[pageroot] StoreAcc=[ftpuser] StoreIP=[ftphost] StorePass=[ftppass] SecureType=gmail
#
#after installation , you could access the page via
# http://[172.16.43.144]/[pageroot]/lists
# the administrator could maintance the server via
# http://[172.16.43.144]/[pageroot]/lists/admin
# user: admin , default password: phplist
#
# This helps the RedHat anaconda installation program to automatically
# configure and install Linux on your machine.
#

# set the language to US english
#lang en_US
key --skip
lang en_US.UTF-8
langsupport en_US
keyboard us

# default is a general 3 button ps/2 mouse
mouse generic3ps/2

# set the timezone to EDT
#timezone America/New_York
timezone Asia/Taipei --utc

# set a root password -- you can also encrypt this
#rootpw _some_password_
rootpw redhat
#rootpw --iscrypted $1$lvU6kOK5$wzGy5BlTgkfyXjFO8C0Qo0
selinux --disabled
firewall --disabled

# uncomment to have the system reboot after install has completed
reboot

# install in text mode
text

# use the Lilo boot loader, turn on the linear flag, and write it into
# the master boot record
#bootloader --useLilo --linear --location=mbr
bootloader --location=mbr --driveorder=sda --append="rhgb quiet"


# uncomment to have the user confirms each dialog
#interactive

# this is like interactive but the user confirms each page not each dialog
#autostep

# install Linux, don't upgrade
install
# install from the cdrom
cdrom

# clear all of the existing partitions from the disk and make new ones
clearpart --all --initlabel
part /boot --fstype ext3 --size 52
part swap --size 1024
part / --fstype ext3 --size 10240 --grow

# You can configure network settings here. I am working toward using
# dhcp an pump to get the configs for a certain host and then fix them
# statically at the end of the installation process.
#network --bootproto static --ip ... --netmask ... --gateway ... --nameserver ...
#network --bootproto static --ip 172.16.43.144 --netmask 255.255.255.0 --gateway 172.16.43.1 --nameserver 168.95.1.1

# configure how passwords are stored
auth --useshadow --enablemd5

# setup a medium strength firewall and allow ssh incoming connections
#firewall --medium --ssh

# skip the x windows configuration
skipx

#
# The following lists the RPMs that will be installed by the system.
# The @ lines are sort-of macros which are defined in the
# RedHat/base/comps file on the cdrom. I've added nc and zsh at the
# end because I wanted them and they weren't in any of the @ lines.
#
# An alternative to this list would be to list the specific RPMs to
# install although that might get big. You will need to check this
# list carefully since we are going to pair down the RPMs so they fill
# on one CD.
#
%packages
#@X Window System
#@Network Support
#@Spelling
#@NFS File Server
#@DNS Name Server
#@Network Managed Workstation
#@Emacs
#@Utilities
#@Software Development
#nc
#zsh
#@office
#@development-libs
@editors
#@gnome-software-development
@text-internet
#@x-software-development
#@gnome-desktop
#@dialup
@core
@base
#@games
@java
@base-x
#@graphics
@web-server
#@printing
#@sound-and-video
#@admin-tools
#@development-tools
#@graphical-internet
@mysql
#mesa-libGLU-devel
#kexec-tools
#device-mapper-multipath
#xorg-x11-utils
#xorg-x11-server-Xnest
#xorg-x11-server-Xvfb
#libsane-hpaio
#imake
php
php-mysql
#for phpMyAdmin
php-common
php-mbstring
php-imap
-sysreport
#
# The following commands are executed at the end of the installation
# process by /bin/sh while you are chrooted into the new system. This
# allows you to add user accounts, turn on or off autobooted software,
# etc..
#
# Note that at the end of the script I have an example of how to get
# input from the user. I'd like to hear if anyone has better ways of
# doing this. My way basically uses the 3rd virtual terminal to both
# echo to and read from. It works.
#

%post --nochroot
# cdrom is exist at /tmp/cdrom when "--nochroot"
mkdir -p /mnt/sysimage/mnt/source
mount -t iso9660 /tmp/cdrom /mnt/sysimage/mnt/source
mkdir -p /mnt/sysimage/extras
cp -R /mnt/sysimage/mnt/source/extras/* /mnt/sysimage/extras/.

%post
# Replace with ftaylor's (working) code.
#eval $(cat /proc/cmdline | awk '{print $NF}')
eval $(sed 's/ /\n/g' /proc/cmdline | grep '^ipaddr=')
eval $(sed 's/ /\n/g' /proc/cmdline | grep '^gateway=')
eval $(sed 's/ /\n/g' /proc/cmdline | grep '^netmask=')
eval $(sed 's/ /\n/g' /proc/cmdline | grep '^dns=')
#$Recovery=mysql backup main file name in ftp server that you would like D/L
#eval $(sed 's/ /\n/g' /proc/cmdline | grep '^Recovery=')
#$LISTROOT=phplist web page root folder
eval $(sed 's/ /\n/g' /proc/cmdline | grep '^ListRoot=')
#ftp account infomation
eval $(sed 's/ /\n/g' /proc/cmdline | grep '^StoreIP=')
eval $(sed 's/ /\n/g' /proc/cmdline | grep '^StoreAcc=')
eval $(sed 's/ /\n/g' /proc/cmdline | grep '^StorePass=')
eval $(sed 's/ /\n/g' /proc/cmdline | grep '^SecureType=')

if [ "$SecureType" == "" ]; then
SecureType="simple"
fi

if [ "$ListRoot" == "" ]; then
ListRoot="phplist"
fi


mkdir -p /extras/recovery
mkdir -p /extras/backup

chmod 775 /extras
chmod 775 /extras/recovery
chmod 775 /extras/backup
chown root.apache /extras
chown root.apache /extras/recovery
chown root.apache /extras/backup


# turn off packages that we don't want running
#echo Turning off some packages
#/sbin/chkconfig --level 0123456 apmd off
#/sbin/chkconfig --level 0123456 sendmail off
#/sbin/chkconfig --level 0123456 lpd off
#/sbin/chkconfig --level 0123456 xfs off
#/sbin/chkconfig --level 0123456 gpm off
#/sbin/chkconfig --level 0123456 wine off

# turning on packages that we need
#echo Turning on some packages
#/sbin/chkconfig --level 345 ntpd on

# Maybe add a ntp server to the ntp.conf
#echo Adding entries to ntp.conf
#cat >> /etc/ntp.conf << EOF
#server my.good.ntp.home.com
#EOF
# Maybe add some entries to the sudoers file
#echo Adding some entries to the sudoers file
#cat >> /etc/sudoers << EOF
#me ALL = (ALL) ALL
#EOF

# example of user i/o if necessary
#
# # redirect IO to the 3rd terminal -- thanks Charles.
# exec < /dev/tty3 > /dev/tty3
#
# echo -n "Enter something: "
# read yn
# echo "We got $yn"

###############################################################################
# network setting #
###############################################################################
echo "DEVICE=eth0" > /etc/sysconfig/network-scripts/ifcfg-eth0
echo "ONBOOT=yes" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "IPADDR=$ipaddr" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "NETMASK=$netmask" >> /etc/sysconfig/network-scripts/ifcfg-eth0
echo "GATEWAY=$gateway" >> /etc/sysconfig/network-scripts/ifcfg-eth0
#chattr +i /etc/sysconfig/network-scripts/ifcfg-eth0

echo "NETWORKING=yes" > /etc/sysconfig/network
echo "NETWORKING_IPV6=no" >> /etc/sysconfig/network
echo "HOSTNAME=PHPLIST" >> /etc/sysconfig/network
#chattr +i /etc/sysconfig/network

echo "search example.com" > /etc/resolv.conf
if ["$dns" = ""]; then
echo "nameserver 168.95.1.1" >> /etc/resolv.conf
else
echo "nameserver $dns" >> /etc/resolv.conf
fi
#chattr +i /etc/resolv.conf


###############################################################################
# copy phplist and build it #
###############################################################################


#setup phplist
chkconfig mysqld on
chkconfig httpd on
service mysqld start


tar -zxvf /extras/phplist-2.10.13.tgz -C /
#cp -f /extras/php.ini /etc/php.ini
ln -s /phplist-2.10.13/public_html /var/www/html/$ListRoot


#/usr/bin/mysqladmin -u root password 'rootcab'
#/usr/bin/mysql -u root --password='rootcab' < /extras/creation.sql

service httpd start

#sudoers
cp /etc/sudoers /etc/sudoers.org
cat /etc/sudoers | sed '/Defaults\x20\x20\x20\x20requiretty/ s/^/#/' > /etc/sudoers

cat >> /etc/sudoers << EOF
Cmnd_Alias BOOTING = /sbin/init
apache ALL=BOOTING,NOPASSWD:ALL
EOF

#setup phpMyAdmin
/bin/tar -zxvf /extras/phpMyAdmin-2.11.11.3-all-languages.tar.gz -C /
ln -s /phpMyAdmin-2.11.11.3-all-languages /var/www/html/phpMyAdmin
rpm -ivh /extras/libmcrypt-2.5.7-4.el4.centos.i386.rpm
rpm -ivh /extras/libmcrypt-devel-2.5.7-4.el4.centos.i386.rpm
rpm -ivh /extras/php-mcrypt-5.1.6-1.el4.centos.i386.rpm
rpm -ivh /extras/libmhash-0.9.1-1.2.el5.rf.i386.rpm
rpm -ivh /extras/mcrypt-2.6.8-1.el5.i386.rpm
#cp /extras/config.inc.php /phpMyAdmin-2.11.11.3-all-languages/.


#restore mysql
#cp -f /extras/storeFROMdb.sh /root/storeFROMdb.sh
#cp -f /extras/recoveryTOcab.sh /root/recoveryTOcab.sh
#if [ "$Recovery" != "" ]; then
# mkdir -p /root/recovery
# openvt -sw -- wget http://www.cab.org.tw/$Recovery.tar.gz -O /root/recovery/$Recovery.tar.gz
# /bin/tar -zxvf /root/recovery/$Recovery.tar.gz -C /root/recovery/
# /usr/bin/mysql -u root --password='rootcab' cab < /root/recovery/$Recovery.sql
## /root/recoveryTOcab.sh $Recovery
#fi

if [ "$StoreIP" != "" ] && [ "$StoreAcc" != "" ] && [ "$StorePass" != "" ]; then
/extras/migration.sh -c=/extras/phplist.cnf -t=$SecureType --listdir=\\\/$ListRoot --ftprtdir=\\\/extras -A=\\\/$ListRoot\\\/lists\\\/admin -H=\\\/$ListRoot\\\/lists --ftpuser=$StoreAcc --ftphost=$StoreIP --ftppass=$StorePass --ftpmode=binary > /root/migration.log
###############################################################################
# cron job #
###############################################################################
cat << EOF >> /etc/crontab
0 * * * * root /usr/sbin/ntpdate -b time.stdtime.gov.tw;/sbin/hwclock --systohc --utc
0 0 * * * root /extras/storeFROMdb.sh
EOF
else
/extras/migration.sh -c=/extras/phplist.cnf -t=$SecureType --listdir=\\\/$ListRoot --ftprtdir=\\\/extras -A=\\\/$ListRoot\\\/lists\\\/admin -H=\\\/$ListRoot\\\/lists >/root/migration.log

###############################################################################
# cron job #
###############################################################################
cat << EOF >> /etc/crontab
0 * * * * root /usr/sbin/ntpdate -b time.stdtime.gov.tw;/sbin/hwclock --systohc --utc
EOF
fi

###############################################################################
# rc.local #
###############################################################################

echo "/usr/sbin/ntpdate -b time.stdtime.gov.tw;/sbin/hwclock --systohc --utc" >> /etc/rc.local
# echo "0 18 * * * /root/storeFROMcab.sh root rootcab $StoreIP $StoreAcc $StorePass" >> /etc/rc.local

###############################################################################
# shutdown daemons #
###############################################################################
chkconfig apmd off
chkconfig bluetooth off
chkconfig cups off
chkconfig nfslock off
chkconfig pcscd off
chkconfig xfs off
chkconfig sendmail off


#copy a file for new menuitem in phplist
#cp -f /extras/systool.php /var/www/html/$ListRoot/lists/admin
#cp -f /extras/sysproc.php /var/www/html/$ListRoot/lists/admin


#準備燒錄
[root@HTS099 phplist-cab]# cp -rf /burn/phplist-centos/isolinux /burn/.

[root@HTS099 burn]# cd /burn
[root@HTS099 burn]# mkisofs -A "CENTOS_2-10-13_i386_DVD" -V "CENTOS_2-10-13_i386_DVD" -J -R -v -T -o phplist-centos.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table phplist-centos



Writing: Directory tree cleanup Start Block 534
Done with: Directory tree cleanup Block(s) 0
Writing: Extension record Start Block 534
Done with: Extension record Block(s) 1
Writing: The File(s) Start Block 535
0.30% done, estimate finish Thu Mar 17 13:47:11 2011
0.60% done, estimate finish Thu Mar 17 13:49:58 2011
0.89% done, estimate finish Thu Mar 17 13:49:02 2011
1.19% done, estimate finish Thu Mar 17 13:48:34 2011
1.49% done, estimate finish Thu Mar 17 13:48:18 2011


Total translation table size: 884504
Total rockridge attributes bytes: 389387
Total directory bytes: 602112
Path table size(bytes): 268
Done with: The File(s) Block(s) 1679275
Writing: Ending Padblock Start Block 1679810
Done with: Ending Padblock Block(s) 150
Max brk space used 3a5000
1679960 extents written (3281 MB)
[root@HTS099 burn]#
[root@HTS099 burn]# ll
total 3359932
drwxr-xr-x. 2 root root 4096 Mar 17 13:44 isolinux
drwxr-xr-x. 12 root root 4096 Mar 17 13:40 phplist-centos
-rw-r--r--. 1 root root 3440558080 Mar 17 13:52 phplist-centos.iso

#安裝使用
把ISO燒成光碟後,開機,可以發現熟悉的RHEL5開機
輸入:linux ks=cdrom:/ks.cfg ipaddr=...... netmask=.... gateway=.... ....
就會依剛才設定所分配的內容來安裝


#參考資料
http://ms.ntcb.edu.tw/~steven/article/install_dvd.htm
http://www.centos.org/docs/5/html/5.2/Installation_Guide/s1-kickstart2-startinginstall.html

沒有留言:

張貼留言

文章分類