init.cc 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 <apt-pkg/init.h>
  10. #include <apt-pkg/fileutl.h>
  11. #include <apt-pkg/error.h>
  12. #include <apti18n.h>
  13. #include <config.h>
  14. #include <cstdlib>
  15. #include <sys/stat.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.Set("APT::Architecture", COMMON_ARCH);
  32. Cnf.Set("APT::Build-Essential::", "build-essential");
  33. Cnf.Set("APT::Install-Recommends", true);
  34. Cnf.Set("APT::Install-Suggests", false);
  35. Cnf.Set("Dir","/");
  36. // State
  37. Cnf.Set("Dir::State","var/lib/apt/");
  38. /* Just in case something goes horribly wrong, we can fall back to the
  39. old /var/state paths.. */
  40. struct stat St;
  41. if (stat("/var/lib/apt/.",&St) != 0 &&
  42. stat("/var/state/apt/.",&St) == 0)
  43. Cnf.Set("Dir::State","var/state/apt/");
  44. Cnf.Set("Dir::State::lists","lists/");
  45. Cnf.Set("Dir::State::cdroms","cdroms.list");
  46. Cnf.Set("Dir::State::mirrors","mirrors/");
  47. // Cache
  48. Cnf.Set("Dir::Cache","var/cache/apt/");
  49. Cnf.Set("Dir::Cache::archives","archives/");
  50. Cnf.Set("Dir::Cache::srcpkgcache","srcpkgcache.bin");
  51. Cnf.Set("Dir::Cache::pkgcache","pkgcache.bin");
  52. // Configuration
  53. Cnf.Set("Dir::Etc","etc/apt/");
  54. Cnf.Set("Dir::Etc::sourcelist","sources.list");
  55. Cnf.Set("Dir::Etc::sourceparts","sources.list.d");
  56. Cnf.Set("Dir::Etc::vendorlist","vendors.list");
  57. Cnf.Set("Dir::Etc::vendorparts","vendors.list.d");
  58. Cnf.Set("Dir::Etc::main","apt.conf");
  59. Cnf.Set("Dir::Etc::netrc", "auth.conf");
  60. Cnf.Set("Dir::Etc::parts","apt.conf.d");
  61. Cnf.Set("Dir::Etc::preferences","preferences");
  62. Cnf.Set("Dir::Etc::preferencesparts","preferences.d");
  63. Cnf.Set("Dir::Etc::trusted", "trusted.gpg");
  64. Cnf.Set("Dir::Etc::trustedparts","trusted.gpg.d");
  65. Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods");
  66. Cnf.Set("Dir::Media::MountPath","/media/apt");
  67. // State
  68. Cnf.Set("Dir::Log","var/log/apt");
  69. Cnf.Set("Dir::Log::Terminal","term.log");
  70. Cnf.Set("Dir::Log::History","history.log");
  71. Cnf.Set("Dir::Ignore-Files-Silently::", "~$");
  72. Cnf.Set("Dir::Ignore-Files-Silently::", "\\.disabled$");
  73. Cnf.Set("Dir::Ignore-Files-Silently::", "\\.bak$");
  74. Cnf.Set("Dir::Ignore-Files-Silently::", "\\.dpkg-[a-z]+$");
  75. // Translation
  76. Cnf.Set("APT::Acquire::Translation", "environment");
  77. bool Res = true;
  78. // Read an alternate config file
  79. const char *Cfg = getenv("APT_CONFIG");
  80. if (Cfg != 0)
  81. {
  82. if (RealFileExists(Cfg) == true)
  83. Res &= ReadConfigFile(Cnf,Cfg);
  84. else
  85. _error->WarningE("RealFileExists",_("Unable to read %s"),Cfg);
  86. }
  87. // Read the configuration parts dir
  88. string Parts = Cnf.FindDir("Dir::Etc::parts");
  89. if (DirectoryExists(Parts) == true)
  90. Res &= ReadConfigDir(Cnf,Parts);
  91. else
  92. _error->WarningE("DirectoryExists",_("Unable to read %s"),Parts.c_str());
  93. // Read the main config file
  94. string FName = Cnf.FindFile("Dir::Etc::main");
  95. if (RealFileExists(FName) == true)
  96. Res &= ReadConfigFile(Cnf,FName);
  97. if (Res == false)
  98. return false;
  99. if (Cnf.FindB("Debug::pkgInitConfig",false) == true)
  100. Cnf.Dump();
  101. #ifdef APT_DOMAIN
  102. if (Cnf.Exists("Dir::Locale"))
  103. {
  104. bindtextdomain(APT_DOMAIN,Cnf.FindDir("Dir::Locale").c_str());
  105. bindtextdomain(textdomain(0),Cnf.FindDir("Dir::Locale").c_str());
  106. }
  107. #endif
  108. return true;
  109. }
  110. /*}}}*/
  111. // pkgInitSystem - Initialize the _system calss /*{{{*/
  112. // ---------------------------------------------------------------------
  113. /* */
  114. bool pkgInitSystem(Configuration &Cnf,pkgSystem *&Sys)
  115. {
  116. Sys = 0;
  117. string Label = Cnf.Find("Apt::System","");
  118. if (Label.empty() == false)
  119. {
  120. Sys = pkgSystem::GetSystem(Label.c_str());
  121. if (Sys == 0)
  122. return _error->Error(_("Packaging system '%s' is not supported"),Label.c_str());
  123. }
  124. else
  125. {
  126. signed MaxScore = 0;
  127. for (unsigned I = 0; I != pkgSystem::GlobalListLen; I++)
  128. {
  129. signed Score = pkgSystem::GlobalList[I]->Score(Cnf);
  130. if (Score > MaxScore)
  131. {
  132. MaxScore = Score;
  133. Sys = pkgSystem::GlobalList[I];
  134. }
  135. }
  136. if (Sys == 0)
  137. return _error->Error(_("Unable to determine a suitable packaging system type"));
  138. }
  139. return Sys->Initialize(Cnf);
  140. }
  141. /*}}}*/