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 if (getFileType(rootOrFile) == FT_DIRECTORY) {
00062 string root = rootOrFile;
00063 bool nativelyPackaged = !fileExists(root + "/Rakefile") ||
00064 !fileExists(root + "/DEVELOPERS.TXT");
00065
00066 if (nativelyPackaged) {
00067 agentsDir = "/usr/lib/phusion-passenger/agents";
00068 helperScriptsDir = "/usr/share/phusion-passenger/helper-scripts";
00069 resourcesDir = "/usr/share/phusion-passenger";
00070 docDir = "/usr/share/doc/phusion-passenger";
00071 rubyLibDir = "";
00072 compilableSourceDir = "/usr/share/phusion-passenger/compilable-source";
00073 apache2Module = "/usr/lib/apache2/modules/mod_passenger.so";
00074 } else {
00075 agentsDir = root + "/agents";
00076 helperScriptsDir = root + "/helper-scripts";
00077 resourcesDir = root + "/resources";
00078 docDir = root + "/doc";
00079 rubyLibDir = root + "/lib";
00080 compilableSourceDir = root;
00081 apache2Module = root + "ext/apache2/mod_passenger.so";
00082 }
00083
00084 } else {
00085 string file = rootOrFile;
00086 IniFileSectionPtr options = IniFile(file).section("locations");
00087 agentsDir = getOption(file, options, "agents");
00088 helperScriptsDir = getOption(file, options, "helper_scripts");
00089 resourcesDir = getOption(file, options, "resources");
00090 docDir = getOption(file, options, "doc");
00091 rubyLibDir = getOption(file, options, "rubylib");
00092 compilableSourceDir = getOption(file, options, "compilable_source");
00093 apache2Module = getOption(file, options, "apache2_module");
00094 }
00095 }
00096
00097 string getAgentsDir() const {
00098 return agentsDir;
00099 }
00100
00101 string getHelperScriptsDir() const {
00102 return helperScriptsDir;
00103 }
00104
00105 string getSpawnServerFilename() const {
00106 return getHelperScriptsDir() + "/passenger-spawn-server";
00107 }
00108
00109 string getResourcesDir() const {
00110 return resourcesDir;
00111 }
00112
00113 string getDocDir() const {
00114 return docDir;
00115 }
00116
00117
00118 string getRubyLibDir() const {
00119 return rubyLibDir;
00120 }
00121
00122 string getCompilableSourceDir() const {
00123 return compilableSourceDir;
00124 }
00125
00126 string getApache2ModuleFilename() const {
00127 return apache2Module;
00128 }
00129 };
00130
00131
00132 }
00133
00134 #endif