Zend - The PHP Company




Utilities

Add Code


Linux Executable+Dependencies Packager  

Type: application
Added by: 20after4
Entered: 07/09/2002
Last modified: 09/12/2001
Rating: - (fewer than 3 votes)
Views: 5022
This short script uses ldd to find the shared library dependencies for a given executable file, then the executable and all of the files that it depends on are packaged using tar. This is great for making backups or relocating an executable to another machine where necessary the libraries might be missing. You are free to use this script however you see fit as long as you agree to the following disclaimer: Disclaimer: this script is provided as is and without any warrenty, not even the implied warrenties of merchantability or fitness for a particular purpose. I explicitly disclaim responsibility for this script including any damages that might result from your use or misuse of the script.


#!/php/php -q
<?
/*
   package_exe.php Copyright (C) 2002 by Mukunda Modell
   url: http://www.20after4.net
   email: mukunda@20after4.net

 You are free to use this script however you see fit, however, you must keep this notice intact and you must agree to the following disclaimer:

 Disclaimer:
  this script is provided as is and without any warrenty, 
  not even the implied warrenties of merchantability or 
  fitness for a particular purpose.
  I explicitly disclaim responsibility for this script
  including any damages that might result from your use or
  misuse of the script.

 Usage:
 create a new file and paste this source code into it.
 Then make the file executable and run the program from
 the linux shell:
 /path/to/this/script.php /path/to/exe /path/to/archive

 exe is an executable file that you want to package.
 archive is the name of a tar file that will be created.

 once your archive is created you can copy the tar file to
 another machine and execute a command similar to this one to extract the archive:

cd /
tar -xvkf /path/to/archive.tar

(note: the -xvkf is important: the k prevents tar from overwriting and files that already exist)

*/
if (empty($argv[1]) || empty($argv[2]))
{
        echo 
"Usage:n----------npackage_exe executableFile archiveFilen----------nThe result is a tar archiveFile containing";
        echo 
" executableFilenand the sharedlibraries that it needs (according to ldd)nn";
}
else
{   
        
$list shell_exec("ldd $argv[1]");
        
$arr explode("=>"$list);
        
$files $argv[1];
        Echo 
"Finding shared library dependencies for $filesn------------------------------------------------n";
        for (
$i 0$i count($arr); $i++)
        {
                
$lib explode("("$arr[$i+1]);
                
$lib trim($lib[0]);
                echo 
$lib "n";
                
$files $files " " $lib;
        }
        
passthru"tar -cvhf $argv[2] $files");
}
?>


Usage Example


 create a new file and paste this source code into it.
 Then make the file executable and run the program from
 the linux shell:
 /path/to/this/script.php /path/to/exe /path/to/archive

 exe is an executable file that you want to package.
 archive is the name of a tar file that will be created.

 once your archive is created you can copy the tar file to
 another machine and execute a command similar to this one to extract the archive:


Rate This Script





Search



This Category All Categories