From be059ef0a3a645906fcd4009733ecbbde4f0c9b8 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 9 Feb 2014 15:13:44 +0800 Subject: [PATCH] Modules/InitRD - Support for optional files (dbclient in this case) --- .../Filesystems/InitRD/GenerateInitRD.php | 69 ++++++++++++------- .../Modules/Filesystems/InitRD/files.lst | 2 + 2 files changed, 46 insertions(+), 25 deletions(-) diff --git a/KernelLand/Modules/Filesystems/InitRD/GenerateInitRD.php b/KernelLand/Modules/Filesystems/InitRD/GenerateInitRD.php index 44c005ab..3229ef23 100644 --- a/KernelLand/Modules/Filesystems/InitRD/GenerateInitRD.php +++ b/KernelLand/Modules/Filesystems/InitRD/GenerateInitRD.php @@ -30,34 +30,63 @@ $lStack = array( array("",array()) ); foreach($lines as $line) { $line = trim($line); - if($line[0] == "#") continue; + if($line == "" || $line[0] == "#") continue; // Directory if(preg_match('/^Dir\s+"([^"]+)"\s+{$/', $line, $matches)) { $new = array($matches[1], array()); array_push($lStack, $new); $lDepth ++; - continue; } // End of a block - if($line == "}") + elseif($line == "}") { $lDepth --; $lStack[$lDepth][1][] = array_pop($lStack); - continue; } // File - if(preg_match('/^File\s+"([^"]+)"(?:\s+"([^"]+)")?$/', $line, $matches)) + elseif(preg_match('/^((?:Opt)?)File\s+"([^"]+)"(?:\s+"([^"]+)")?$/', $line, $matches)) { - if( !isset($matches[2]) ) { - $matches[2] = $matches[1]; - $matches[1] = basename($matches[2]); + $isOptional = $matches[1]; + $dstfile = $matches[2]; + $path = isset($matches[3]) ? $matches[3] : ""; + + if( $path == "" ) { + $path = $dstfile; + $dstfile = basename($dstfile); + } + + // Parse path components + $path = str_replace("__EXT__", "$ACESSDIR/Externals/Output/$ARCH", $path); + $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path); + $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path); + $path = str_replace("__SRC__", "$ACESSDIR", $path); + + $gDependencies[] = $path; + + if( !file_exists($path) ) + { + if( $isOptional == "" ) + { + // Oops + echo "ERROR: '{$path}' does not exist\n", + exit(1); + } + else + { + // optional file + } + } + else + { + $lStack[$lDepth][1][] = array($dstfile, $path, $isOptional); } - $lStack[$lDepth][1][] = array($matches[1], $matches[2]); - continue; } - echo "ERROR: $line\n"; - exit(0); + else + { + echo "ERROR: $line\n"; + exit(0); + } } function hd($fp) @@ -114,19 +143,7 @@ EOF; { $path = $item[1]; - // Parse path components - $path = str_replace("__BIN__", "$ACESSDIR/Usermode/Output/$ARCH", $path); - $path = str_replace("__FS__", "$ACESSDIR/Usermode/Filesystem", $path); - $path = str_replace("__SRC__", "$ACESSDIR", $path); echo $path,"\n"; - // --- - - $gDependencies[] = $path; - - if(!file_exists($path)) { - echo "ERROR: '{$path}' does not exist\n", - exit(1); - } $size = filesize($path); $_sym = "_binary_".str_replace(array("/","-","."), "_", $path)."_start"; @@ -217,8 +234,10 @@ fclose($fp); if($gDepFile !== false) { $fp = fopen($gDepFile, "w"); - $line = $gOutputFile.":\t".implode(" ", $gDependencies); + $line = $gOutputFile.":\t".implode(" ", $gDependencies)."\n"; fputs($fp, $line); + foreach( $gDependencies as $dep ) + fputs($fp, "$dep: \n"); fclose($fp); } diff --git a/KernelLand/Modules/Filesystems/InitRD/files.lst b/KernelLand/Modules/Filesystems/InitRD/files.lst index f4832c42..b5890f9f 100644 --- a/KernelLand/Modules/Filesystems/InitRD/files.lst +++ b/KernelLand/Modules/Filesystems/InitRD/files.lst @@ -17,6 +17,8 @@ Dir "Bin" { File "__BIN__/Bin/telnet" File "__BIN__/Bin/irc" File "__BIN__/Bin/bomb" + + OptFile "__EXT__/bin/dbclient" } Dir "Libs" { File "__BIN__/Libs/ld-acess.so" -- 2.20.1