|
|

楼主 |
发表于 2006-10-13 13:11:42
|
显示全部楼层
自动安装的相关脚本,因为有些设置必须到系统第一次重新启动之后等相关软件启动起来之后才能够设置,比如要导入mysql的数据库,
这个我没有想到好的方法,只能自己来编写一个一次性执行的脚本了.
内容如下,
preseed中调用的是conf.sh
[PHP]
#ls
apt.conf config_binary dists install pics tools
autorun.bat config_installer doc isolinux pool
autorun.inf debian indices md5sum.txt scripts
[/PHP]
我的脚本都放在了scripts目录下面了
[php]
ls
cleanup.sh config.sh firstreboot.sh php.ini
config_misc_once.sh default htdocs.tar.gz wn.sql
[/php]
conf.sh
这个脚本是在系统安装的时候,grub安装之后,在重启前,会执行的脚本.
这里我进行了一些预配置,比如把www文件解开放到了特定的目录下面了.
还设置了init脚本,创造一个执行一次的环境,rc脚本里面的一些动作
实际上下面的echo并没有起作用,或者说至少我们在屏幕上看不到这些echo,
当时写了没有改过来
[PHP]
#this file called by preseed,just before reboot,this is last install stage
#it copy files to overide ,or set the first reboot setting
#after first reboot ,will sh firstreboot.sh,this is rc.d scripts
#firstreboot.sh->config_misc_once.sh->cleanup.sh
#cleanup.sh will clean up firstreboot.sh and it links,then rm config_misc_once,then rm cleanup.sh itself
cd /cdrom/scripts/
tar zxf htdocs.tar.gz -C /target/var/www/
cp wn.sql /target/
cp /cdrom/scripts/php.ini /target/etc/php5/apache2/
cp /cdrom/scripts/default /target/etc/apache2/sites-available/default
echo "set apache php ok@@"
cp /cdrom/scripts/firstreboot.sh /target/etc/init.d/
cd /target/etc/rc0.d/
ln -s ../init.d/firstreboot.sh K99firstreboot.sh
cd /target/etc/rc1.d/
ln -s ../init.d/firstreboot.sh K99firstreboot.sh
cd /target/etc/rc2.d/
ln -s ../init.d/firstreboot.sh S99firstreboot.sh
cd /target/etc/rc3.d/
ln -s ../init.d/firstreboot.sh S99firstreboot.sh
cd /target/etc/rc4.d/
ln -s ../init.d/firstreboot.sh S99firstreboot.sh
cd /target/etc/rc5.d/
ln -s ../init.d/firstreboot.sh S99firstreboot.sh
cd /target/etc/rc6.d/
ln -s ../init.d/firstreboot.sh K99firstreboot.sh
echo -e "set first reboot.sh ok\n"
echo -e "cp config_misc_once.sh cleanup.sh\n"
cp /cdrom/scripts/config_misc_once.sh /target/
cp /cdrom/scripts/cleanup.sh /target/
echo -e "rebooting now\n"
[/PHP]
config_misc_once.sh
所有需要在系统第一次重新启动时设置的内容都放到这里吧
[PHP]
#all your preconfigs are needed to put in this file
#after first reboot ,will sh firstreboot.sh,this is rc.d scripts
#firstreboot.sh->config_misc_once.sh->cleanup.sh
#cleanup.sh will clean up firstreboot.sh and it links,then rm config_misc_once,then rm cleanup.sh itself
echo -e "dump to mysql\n"
mysqladmin create sugarcrm
mysqladmin -u root password '1'
mysql --user=root --password=1 <wn.sql
echo -e "dump to mysql ok\n"
[/PHP]
firstreboot.sh
看得出来从cron的启动脚本改过来的,呵呵
[PHP]
#!/bin/sh
#
#after first reboot ,will sh firstreboot.sh,this is rc.d scripts
#firstreboot.sh->config_misc_once.sh->cleanup.sh
#cleanup.sh will clean up firstreboot.sh and it links,then rm config_misc_once,then rm cleanup.sh itself
#test -f /usr/sbin/cron || exit 0
#LSBNAMES='-l' # Uncomment for LSB name support in /etc/cron.d/
case "$1" in
start) echo -n "Starting first time setting system"
/config_misc_once.sh
/cleanup.sh
echo "."
;;
stop) echo -n "Stopping first time setting system"
echo "."
;;
*) echo "setting failed"
exit 1
;;
esac
exit 0
[/PHP]
cleanup.sh
如其名,
做清理,所谓一次性的设置,设置完了以后要清理掉这些设置脚本.
主要是删除这些文件和脚本,也包括cleanup.sh
奇怪吧,
在cleanup.sh里面删除cleanup.sh,但是这个的确是能够正常工作的.
可能脚本都是一行一行的读的.到最后一行删除自己的时候脚本文件已经读完了.
[PHP]
#do cleanup configs
#after first reboot ,will sh firstreboot.sh,this is rc.d scripts
#firstreboot.sh->config_misc_once.sh->cleanup.sh
#cleanup.sh will clean up firstreboot.sh and it links,then rm config_misc_once,then rm /etc/init.d/firstreboot.sh
#then rm cleanup.sh itself
unlink /etc/rc0.d/K99firstreboot.sh
unlink /etc/rc1.d/K99firstreboot.sh
unlink /etc/rc2.d/S99firstreboot.sh
unlink /etc/rc3.d/S99firstreboot.sh
unlink /etc/rc4.d/S99firstreboot.sh
unlink /etc/rc5.d/S99firstreboot.sh
unlink /etc/rc6.d/K99firstreboot.sh
rm /config_misc_once.sh /etc/init.d/firstreboot.sh /wn.sql /cleanup.sh
[/PHP]
需要注意的是,在安装过程中执行脚本的时候
/target才是安装完系统的根目录,所以要拷贝到新系统的根目录的话
只能拷贝到/target,当系统安装完成的时候,重新启动,就会在根目录下面发现这个脚本 |
|