00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _PASSENGER_RESOURCE_LOCATOR_H_
00026 #define _PASSENGER_RESOURCE_LOCATOR_H_
00027
00028 #include <string>
00029 #include <IniFile.h>
00030 #include <Exceptions.h>
00031 #include <Utils.h>
00032
00033 namespace Passenger {
00034
00035 using namespace boost;
00036
00037
00038
00039
00040
00041 class ResourceLocator {
00042 private:
00043 string agentsDir;
00044 string helperScriptsDir;
00045 string resourcesDir;
00046 string docDir;
00047 string rubyLibDir;
00048 string compilableSourceDir;
00049 string apache2Module;
00050
00051 string getOption(const string &file, const IniFileSectionPtr §ion, const string &key) const {
00052 if (section->hasKey(key)) {
00053 return section->get(key);
00054 } else {
00055 throw RuntimeException("Option '" + key + "' missing in file " + file);
00056 }
00057 }
00058
00059 public:
00060 ResourceLocator(const string &rootOrFile) {
00061 FileType rootOrFileType = getFileType(rootOrFile);
00062 if (rootOrFileType == FT_DIRECTORY || rootOrFileType == FT_NONEXISTANT) {
00063 string root = rootOrFile;
00064 bool nativelyPackaged = !fileExists(root + "/Rakefile") ||
00065 !fileExists(root + "/DEVELOPERS.TXT");
00066
00067 if (nativelyPackaged) {
00068 agentsDir = "/usr/lib/phusion-passenger/agents";
00069 helperScriptsDir = "/usr/share/phusion-passenger/helper-scripts";
00070 resourcesDir = "/usr/share/phusion-passenger";
00071 docDir = "/usr/share/doc/phusion-passenger";
00072 rubyLibDir = "";
00073 compilableSourceDir = "/usr/share/phusion-passenger/compilable-source";
00074 apache2Module = "/usr/lib/apache2/modules/mod_passenger.so";
00075 } else {
00076 agentsDir = root + "/agents";
00077 helperScriptsDir = root + "/helper-scripts";
00078 resourcesDir = root + "/resources";
00079 docDir = root + "/doc";
00080 rubyLibDir = root + "/lib";
00081 compilableSourceDir = root;
00082 apache2Module = root + "ext/apache2/mod_passenger.so";
00083 }
00084
00085 } else {
00086 string file = rootOrFile;
00087 IniFileSectionPtr options = IniFile(file).section("locations");
00088 agentsDir = getOption(file, options, "agents");
00089 helperScriptsDir = getOption(file, options, "helper_scripts");
00090 resourcesDir = getOption(file, options, "resources");
00091 docDir = getOption(file, options, "doc");
00092 rubyLibDir = getOption(file, options, "rubylib");
00093 compilableSourceDir = getOption(file, options, "compilable_source");
00094 apache2Module = getOption(file, options, "apache2_module");
00095 }
00096 }
00097
00098 string getAgentsDir() const {
00099 return agentsDir;
00100 }
00101
00102 string getHelperScriptsDir() const {
00103 return helperScriptsDir;
00104 }
00105
00106 string getSpawnServerFilename() const {
00107 return getHelperScriptsDir() + "/passenger-spawn-server";
00108 }
00109
00110 string getResourcesDir() const {
00111 return resourcesDir;
00112 }
00113
00114 string getDocDir() const {
00115 return docDir;
00116 }
00117
00118
00119 string getRubyLibDir() const {
00120 return rubyLibDir;
00121 }
00122
00123 string getCompilableSourceDir() const {
00124 return compilableSourceDir;
00125 }
00126
00127 string getApache2ModuleFilename() const {
00128 return apache2Module;
00129 }
00130 };
00131
00132
00133 }
00134
00135 #endif