init.cc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: init.cc,v 1.20 2003/02/09 20:31:05 doogie Exp $
  4. /* ######################################################################
  5. Init - Initialize the package library
  6. ##################################################################### */
  7. /*}}}*/
  8. // Include files /*{{{*/
  9. #include<config.h>
  10. #include <apt-pkg/init.h>
  11. #include <apt-pkg/fileutl.h>
  12. #include <apt-pkg/error.h>
  13. #include <cstdlib>
  14. #include <sys/stat.h>
  15. #include <apti18n.h>
  16. /*}}}*/
  17. #define Stringfy_(x) # x
  18. #define Stringfy(x) Stringfy_(x)
  19. const char *pkgVersion = VERSION;
  20. const char *pkgLibVersion = Stringfy(APT_PKG_MAJOR) "."
  21. Stringfy(APT_PKG_MINOR) "."
  22. Stringfy(APT_PKG_RELEASE);
  23. // pkgInitConfig - Initialize the configuration class /*{{{*/
  24. // ---------------------------------------------------------------------
  25. /* Directories are specified in such a way that the FindDir function will
  26. understand them. That is, if they don't start with a / then their parent
  27. is prepended, this allows a fair degree of flexability. */
  28. bool pkgInitConfig(Configuration &Cnf)
  29. {
  30. // General APT things
  31. Cnf.CndSet("APT::Architecture", COMMON_ARCH);
  32. if (Cnf.Exists("APT::Build-Essential") == false)
  33. Cnf.Set("APT::Build-Essential::", "build-essential");
  34. Cnf.CndSet("APT::Install-Recommends", true);
  35. Cnf.CndSet("APT::Install-Suggests", false);
  36. Cnf.CndSet("Dir","/");
  37. // State
  38. Cnf.CndSet("Dir::State","var/lib/apt/");
  39. /* Just in case something goes horribly wrong, we can fall back to the
  40. old /var/state paths.. */
  41. struct stat St;
  42. if (stat("/var/lib/apt/.",&St) != 0 &&
  43. stat("/var/state/apt/.",&St) == 0)
  44. Cnf.CndSet("Dir::State","var/state/apt/");
  45. Cnf.CndSet("Dir::State::lists","lists/");
  46. Cnf.CndSet("Dir::State::cdroms","cdroms.list");
  47. Cnf.CndSet("Dir::State::mirrors","mirrors/");
  48. // Cache
  49. Cnf.CndSet("Dir::Cache","var/cache/apt/");
  50. Cnf.CndSet("Dir::Cache::archives","archives/");
  51. Cnf.CndSet("Dir::Cache::srcpkgcache","srcpkgcache.bin");
  52. Cnf.CndSet("Dir::Cache::pkgcache","pkgcache.bin");
  53. // Configuration
  54. Cnf.CndSet("Dir::Etc","etc/apt/");
  55. Cnf.CndSet("Dir::Etc::sourcelist","sources.list");
  56. Cnf.CndSet("Dir::Etc::sourceparts","sources.list.d");
  57. Cnf.CndSet("Dir::Etc::vendorlist","vendors.list");
  58. Cnf.CndSet("Dir::Etc::vendorparts","vendors.list.d");
  59. Cnf.CndSet("Dir::Etc::main","apt.conf");
  60. Cnf.CndSet("Dir::Etc::netrc", "auth.conf");
  61. Cnf.CndSet("Dir::Etc::parts","apt.conf.d");
  62. Cnf.CndSet("Dir::Etc::preferences","preferences");
  63. Cnf.CndSet("Dir::Etc::preferencesparts","preferences.d");
  64. Cnf.CndSet("Dir::Etc::trusted", "trusted.gpg");
  65. Cnf.CndSet("Dir::Etc::trustedparts","trusted.gpg.d");
  66. Cnf.CndSet("Dir::Bin::methods","/usr/lib/apt/methods");
  67. Cnf.CndSet("Dir::Bin::solvers::","/usr/lib/apt/solvers");
  68. Cnf.CndSet("Dir::Media::MountPath","/media/apt");
  69. // State
  70. Cnf.CndSet("Dir::Log","var/log/apt");
  71. Cnf.CndSet("Dir::Log::Terminal","term.log");
  72. Cnf.CndSet("Dir::Log::History","history.log");
  73. if (Cnf.Exists("Dir::Ignore-Files-Silently") == false)
  74. {
  75. Cnf.Set("Dir::Ignore-Files-Silently::", "~$");
  76. Cnf.Set("Dir::Ignore-Files-Silently::", "\\.disabled$");
  77. Cnf.Set("Dir::Ignore-Files-Silently::", "\\.bak$");
  78. Cnf.Set("Dir::Ignore-Files-Silently::", "\\.dpkg-[a-z]+$");
  79. }
  80. // Default cdrom mount point
  81. Cnf.CndSet("Acquire::cdrom::mount", "/media/cdrom/");
  82. bool Res = true;
  83. // Read an alternate config file
  84. const char *Cfg = getenv("APT_CONFIG");
  85. if (Cfg != 0)
  86. {
  87. if (RealFileExists(Cfg) == true)
  88. Res &= ReadConfigFile(Cnf,Cfg);
  89. else
  90. _error->WarningE("RealFileExists",_("Unable to read %s"),Cfg);
  91. }
  92. // Read the configuration parts dir
  93. std::string Parts = Cnf.FindDir("Dir::Etc::parts");
  94. if (DirectoryExists(Parts) == true)
  95. Res &= ReadConfigDir(Cnf,Parts);
  96. else
  97. _error->WarningE("DirectoryExists",_("Unable to read %s"),Parts.c_str());
  98. // Read the main config file
  99. std::string FName = Cnf.FindFile("Dir::Etc::main");
  100. if (RealFileExists(FName) == true)
  101. Res &= ReadConfigFile(Cnf,FName);
  102. if (Res == false)
  103. return false;
  104. if (Cnf.FindB("Debug::pkgInitConfig",false) == true)
  105. Cnf.Dump();
  106. #ifdef APT_DOMAIN
  107. if (Cnf.Exists("Dir::Locale"))
  108. {
  109. bindtextdomain(APT_DOMAIN,Cnf.FindDir("Dir::Locale").c_str());
  110. bindtextdomain(textdomain(0),Cnf.FindDir("Dir::Locale").c_str());
  111. }
  112. #endif
  113. return true;
  114. }
  115. /*}}}*/
  116. // pkgInitSystem - Initialize the _system calss /*{{{*/
  117. // ---------------------------------------------------------------------
  118. /* */
  119. bool pkgInitSystem(Configuration &Cnf,pkgSystem *&Sys)
  120. {
  121. Sys = 0;
  122. std::string Label = Cnf.Find("Apt::System","");
  123. if (Label.empty() == false)
  124. {
  125. Sys = pkgSystem::GetSystem(Label.c_str());
  126. if (Sys == 0)
  127. return _error->Error(_("Packaging system '%s' is not supported"),Label.c_str());
  128. }
  129. else
  130. {
  131. signed MaxScore = 0;
  132. for (unsigned I = 0; I != pkgSystem::GlobalListLen; I++)
  133. {
  134. signed Score = pkgSystem::GlobalList[I]->Score(Cnf);
  135. if (Score > MaxScore)
  136. {
  137. MaxScore = Score;
  138. Sys = pkgSystem::GlobalList[I];
  139. }
  140. }
  141. if (Sys == 0)
  142. return _error->Error(_("Unable to determine a suitable packaging system type"));
  143. }
  144. return Sys->Initialize(Cnf);
  145. }
  146. /*}}}*/