#! /usr/bin/php -q * * This script takes a "cliKey" as first argument and uses that to look up the path of the script to include in the end. * See configuration of this feature in $TYPO3_CONF_VARS['SC_OPTIONS']['GLOBAL']['cliKeys']. * The point is to have only ONE script dealing with the environment initialization while the actual processing is all a developer should care for. * */ if (PHP_SAPI!='cli') { die('Not called from a command line interface (eg. a shell or scheduler).'.chr(10)); } // Defining circumstances for CLI mode: define('TYPO3_cliMode', TRUE); // Get path to this script $temp_PATH_thisScript = isset($_SERVER['argv'][0]) ? $_SERVER['argv'][0] : (isset($_ENV['_']) ? $_ENV['_'] : $_SERVER['_']); // Figure out if the path is relative $relativePath = FALSE; if (stristr(PHP_OS,'win') && !stristr(PHP_OS,'darwin')) { // Windows if (!preg_match('/^([A-Z]:)?\\\/', $temp_PATH_thisScript)) { $relativePath = TRUE; } } else { // *nix, et al if ($temp_PATH_thisScript{0} != '/') { $relativePath = TRUE; } } // Resolve path if ($relativePath) { $workingDirectory = $_SERVER['PWD'] ? $_SERVER['PWD'] : getcwd(); if ($workingDirectory) { $temp_PATH_thisScript = $workingDirectory.'/'.ereg_replace('\.\/','',$temp_PATH_thisScript); if (!@is_file($temp_PATH_thisScript)) { die ('Relative path found, but an error occured during resolving of the absolute path: '.$temp_PATH_thisScript.chr(10)); } } else { die ('Relative path found, but resolving absolute path is not supported on this platform.'.chr(10)); } } // Define absolute path to this script define('PATH_thisScript',$temp_PATH_thisScript); if (!isset($_SERVER['argv'][1])) { die ('The first argument must be a valid key.'.chr(10)); } // First argument is a key that points to the script configuration define('TYPO3_cliKey', $_SERVER['argv'][1]); // Include init file: require(dirname(PATH_thisScript).'/init.php'); if (defined('TYPO3_cliInclude')) { include(TYPO3_cliInclude); } else { die('No include file configured for key "'.TYPO3_cliKey.'".'.chr(10)); } ?>