Modules/InitRD - Support for optional files (dbclient in this case)
authorJohn Hodge <[email protected]>
Sun, 9 Feb 2014 07:13:44 +0000 (15:13 +0800)
committerJohn Hodge <[email protected]>
Sun, 9 Feb 2014 07:13:44 +0000 (15:13 +0800)
KernelLand/Modules/Filesystems/InitRD/GenerateInitRD.php
KernelLand/Modules/Filesystems/InitRD/files.lst

index 44c005a..3229ef2 100644 (file)
@@ -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);
 }
 
index f4832c4..b5890f9 100644 (file)
@@ -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"

UCC git Repository :: git.ucc.asn.au