Im trying to make a linux installer but with php. thing is, I get the menus and options working but lets say I want to go back to a menu, the script crashes. Not sure why..nyone know what im doing wrong?
Thanks.
<?
/*
PHP Linux Distro Installer
*/
/* Globals */
global $servernum;
global $servernum_min;
global $servernum_swap;
/*-- Functions --*/
function read() {
$fp=fopen("php://stdin", "r");
$input=fgets($fp, 255);
fclose($fp);
return str_replace("\n", "", $input);
}
/* function used to pause runtime and loopback for X.X amount of seconds. From IGN Bot: [url]http://www.ign.com*/[/url]
function pause($delaytime) { // delay should be in seconds
sleep(intval($delaytime));$micro_seconds=intval(($delaytime-intval($delaytime))*2000000);
$start = gettimeofday();do{$stop = gettimeofday();
$timePassed = 2000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec'];
}
while ($timePassed < $micro_seconds);
}
function exit_script() {
return;
}
function show_option1() {
return;
}
function install_kernel() {
return;
}
function install_base() {
return;
}
function bootloader() {
return;
}
function write_fstab() {
return;
}
function write_mtab() {
return;
}
function create_partition($partition) {
passthru("fdisk ".$partition);
return;
}
function create_filesystem() {
return;
}
function create_swap($swap_part) {
passthru("mkswap ".$swap_part);
passthru("swapon ".$swap_part);
return;
}
function install_packages() {
return;
}
function change_root_password($root_pass) {
return;
}
function add_user($user, $shell, $user_pass, $group) {
/*
Options:
* -d home directory
* -s starting program (shell)
* -p password
* -g (primary group assigned to the users)
* -G (Other groups the user belongs to)
* -m (Create the user's home directory
Example: To add a new user with
* a primary group of users
* a second group mgmt
* starting shell /bin/bash
* password of xxxx
* home directory of roger
* create home directory
* a login name of roger
useradd -gusers -Gmgmt -s/bin/shell -pxxxx -d/home/roger -m roger
*/
passthru("useradd -g".$group." -s".$shell." -p".$user_pass." -d/home/".$user." -m ".$user);
return;
}
function reboot_system() {
exec("shutdown -r now");
return;
}
function show_welcome() {
printf("================================================================\n");
printf(" \n\n");
printf("°°°±²ÛÛ²±° Welcome to the PHP Linux Distro Installer °±²ÛÛ²±°°°\n");
printf(" \n\n");
printf(" This is the PHP Linux Distro Installer. It was built to help\n");
printf(" simplify a linux installer for those who want to create there\n");
printf(" own Linux Distros. Here you will be prompted for options on\n");
printf(" how you want to install this distro. Please Select from the \n");
printf(" options below\n");
printf(" \n\n");
printf("================================================================\n\n");
printf(" What do you want to do? \n");
printf("1: Load Swap\n2: Minimum Install - Base Files Only\n3: Full Install\n4: Custom Install\n5: Exit\n");
printf("Choose [1-4]: ");
}
/* Welcome Screen */
show_welcome();
$servernum = trim(read());
$servernum=strval($servernum);
if ($servernum == 1) {
printf("================================================================\n");
printf(" \n\n");
printf("°°°°°°°°°°°°°°°°°°°°±²ÛÛ²±° Load Swap °±²ÛÛ²±°°°°°°°°°°°°°°°°°°°°\n");
printf(" \n\n");
printf(" Please Seelct the correct swap partition to load\n");
printf(" \n\n");
printf("================================================================\n\n");
printf(" What Partition to load? \n");
printf("1: /dev/hda1\n2: /dev/hda2\n3: /dev/hdb1\n4: /dev/hdb2\n5: Back\n");
printf("Choose [1-5]: ");
$servernum_swap = trim(read());
$servernum_swap=strval($servernum_swap);
//Loops back to main menu here
if ($servernum_swap == 5) {
show_welcome();
$servernum = "";
$servernum = trim(read());
$servernum=strval($servernum);
return;
}
return;
}
if ($servernum == 2) {
printf("================================================================\n");
printf(" \n\n");
printf("°°°°°°°°°°°°°°°°°±²ÛÛ²±° Minimum Install °±²ÛÛ²±°°°°°°°°°°°°°°°°°\n");
printf(" \n\n");
printf(" You have choosen the minimum install, this will only install the\n");
printf(" base linux files.");
printf(" \n\n");
printf("================================================================\n\n");
printf(" Continue with install? \n");
printf("1: Yes\n2: No\n3: Exit\n");
printf("Choose [1-3]: ");
$servernum_min = trim(read());
$servernum_min=strval($servernum_min);
if ($servernum_min == 1) {
printf("You have Selected Yes: Exiting script, not done!\n");
exit_script();
return;
}
//Loops back to main menu here
if ($servernum_min == 2) {
show_welcome();
$servernum = "";
$servernum = trim(read());
$servernum=strval($servernum);
return;
}
if ($servernum_min == 3) {
printf("Exiting script!\n");
exit_script();
return;
}
return;
}
if ($servernum == 3) {
printf("Exiting script!\n");
exit_script();
return;
}
if ($servernum == 4) {
printf("Exiting script!\n");
exit_script();
return;
}
if ($servernum == 5) {
printf("Exiting script!\n");
exit_script();
return;
}
?>
sorry the php tags kept striping out stuff, so I ahd to use the code tag