init.cc 5.5 KB

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