PHP as a FAI script

senaque at thepla.net senaque at thepla.net
Mon Feb 17 04:56:38 CET 2003


Hi folks, 

I've managed to hack in php support by modifying the do_script() function in 
/usr/lib/fai/nfsroot/usr/share/fai/subroutines ( or in /usr/share/fai/subroutines - if you 
want to rebuild the fai nfsroot, I think ). In the do_script() function, add another section 
to the case statement as following:

# after expect statement #
#
*"php"*)
    echo "Executing   php: $file"
    echo "=====   php: $file   =====" >> $LOGDIR/php.log 2>&1
    ./$file >> $LOGDIR/php.log 2>&1
    check_status $file $? | tee -a $LOGDIR/php.log
    ;;
#
# before *) default statement #

Also, you will have to have php support in the nfsroot environment, and the only way I 
could achieve this is to chroot into the nfsroot (/usr/lib/fai/nfsroot) and install the php 
tools there manually (with apt-get install on debian woody), as adding it to the 
/etc/fai/fai.conf NFSROOT_PACKAGES variable did not work:

chroot /usr/lib/fai/nfsroot
apt-get update
apt-get install php4-cgi php4-mysql
# double-check that extension=mysql.so is enabled in php cgi configuration.
vi /etc/php4/cgi/php.ini
exit

This should then allow the fai-install nfsroot client to be able to execute php scripts 
from command line for example:

/fai/scripts/DEFAULT/S50:
#!/usr/bin/php4 -q
<?php
echo "Hello world!\n";
echo "$newclasses\n"; # doesnt work
?>

However, I now want to be able to pass/set variables in the /fai/scripts/DEFAULT/S20 
file (the cfengine script which modifies lots of files) with my own values retrieved using 
php from mysql on the FAI server (for example ${rootpw} or even my own ones 
${hostsallow}, etc.) Could anyone give me an idea as to how to do this? I'm not too 
familiar with cfengine, but I cannot see how the S20 script is able to use the ${rootpw} 
variable within cfengine's scope. There might also be other ways to do this? (like 
calling my php scripts from within S20 and returning/echoing output back to cfengine 
as usuable variables?

Hope this will help anyone looking at doing something similar at present or in the future 
which may eventually allow basic FAI administration interface via web/mysql, or even 
the retrieving of settings from server via http (instead of nfs,etc). Any help with this will 
be greatly appreciated.

Regards,

Senaque
---
E-MAIL: senaque at thepla.net
IRC: #FAI @ irc.freenode.net
WWW: http://www.sf.net/users/senaque/




More information about the linux-fai mailing list