init.cc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <apt-pkg/strutl.h>
  16. #include <apt-pkg/macros.h>
  17. #include <string.h>
  18. #include <cstdlib>
  19. #include <apti18n.h>
  20. /*}}}*/
  21. #define Stringfy_(x) # x
  22. #define Stringfy(x) Stringfy_(x)
  23. const char *pkgVersion = PACKAGE_VERSION;
  24. const char *pkgLibVersion = Stringfy(APT_PKG_MAJOR) "."
  25. Stringfy(APT_PKG_MINOR) "."
  26. Stringfy(APT_PKG_RELEASE);
  27. // pkgInitConfig - Initialize the configuration class /*{{{*/
  28. // ---------------------------------------------------------------------
  29. /* Directories are specified in such a way that the FindDir function will
  30. understand them. That is, if they don't start with a / then their parent
  31. is prepended, this allows a fair degree of flexability. */
  32. bool pkgInitConfig(Configuration &Cnf)
  33. {
  34. // General APT things
  35. Cnf.CndSet("APT::Architecture", COMMON_ARCH);
  36. if (Cnf.Exists("APT::Build-Essential") == false)
  37. Cnf.Set("APT::Build-Essential::", "build-essential");
  38. Cnf.CndSet("APT::Install-Recommends", true);
  39. Cnf.CndSet("APT::Install-Suggests", false);
  40. Cnf.CndSet("Dir","/");
  41. // State
  42. Cnf.CndSet("Dir::State", STATE_DIR + 1);
  43. Cnf.CndSet("Dir::State::lists","lists/");
  44. Cnf.CndSet("Dir::State::cdroms","cdroms.list");
  45. Cnf.CndSet("Dir::State::mirrors","mirrors/");
  46. // Cache
  47. Cnf.CndSet("Dir::Cache", CACHE_DIR + 1);
  48. Cnf.CndSet("Dir::Cache::archives","archives/");
  49. Cnf.CndSet("Dir::Cache::srcpkgcache","srcpkgcache.bin");
  50. Cnf.CndSet("Dir::Cache::pkgcache","pkgcache.bin");
  51. // Configuration
  52. Cnf.CndSet("Dir::Etc", CONF_DIR + 1);
  53. Cnf.CndSet("Dir::Etc::sourcelist","sources.list");
  54. Cnf.CndSet("Dir::Etc::sourceparts","sources.list.d");
  55. Cnf.CndSet("Dir::Etc::main","apt.conf");
  56. Cnf.CndSet("Dir::Etc::netrc", "auth.conf");
  57. Cnf.CndSet("Dir::Etc::parts","apt.conf.d");
  58. Cnf.CndSet("Dir::Etc::preferences","preferences");
  59. Cnf.CndSet("Dir::Etc::preferencesparts","preferences.d");
  60. Cnf.CndSet("Dir::Etc::trusted", "trusted.gpg");
  61. Cnf.CndSet("Dir::Etc::trustedparts","trusted.gpg.d");
  62. Cnf.CndSet("Dir::Bin::methods", LIBEXEC_DIR "/methods");
  63. Cnf.CndSet("Dir::Bin::solvers::",LIBEXEC_DIR "/solvers");
  64. Cnf.CndSet("Dir::Bin::planners::",LIBEXEC_DIR "/planners");
  65. Cnf.CndSet("Dir::Media::MountPath","/media/apt");
  66. // State
  67. Cnf.CndSet("Dir::Log", LOG_DIR + 1);
  68. Cnf.CndSet("Dir::Log::Terminal","term.log");
  69. Cnf.CndSet("Dir::Log::History","history.log");
  70. Cnf.CndSet("Dir::Log::Planner","eipp.log.xz");
  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. Cnf.Set("Dir::Ignore-Files-Silently::", "\\.save$");
  76. Cnf.Set("Dir::Ignore-Files-Silently::", "\\.orig$");
  77. Cnf.Set("Dir::Ignore-Files-Silently::", "\\.distUpgrade$");
  78. // Repository security
  79. Cnf.CndSet("Acquire::AllowInsecureRepositories", false);
  80. Cnf.CndSet("Acquire::AllowWeakRepositories", false);
  81. Cnf.CndSet("Acquire::AllowDowngradeToInsecureRepositories", false);
  82. // Default cdrom mount point
  83. Cnf.CndSet("Acquire::cdrom::mount", "/media/cdrom/");
  84. // The default user we drop to in the methods
  85. Cnf.CndSet("APT::Sandbox::User", "_apt");
  86. Cnf.CndSet("Acquire::IndexTargets::deb::Packages::MetaKey", "$(COMPONENT)/binary-$(ARCHITECTURE)/Packages");
  87. Cnf.CndSet("Acquire::IndexTargets::deb::Packages::flatMetaKey", "Packages");
  88. Cnf.CndSet("Acquire::IndexTargets::deb::Packages::ShortDescription", "Packages");
  89. Cnf.CndSet("Acquire::IndexTargets::deb::Packages::Description", "$(RELEASE)/$(COMPONENT) $(ARCHITECTURE) Packages");
  90. Cnf.CndSet("Acquire::IndexTargets::deb::Packages::flatDescription", "$(RELEASE) Packages");
  91. Cnf.CndSet("Acquire::IndexTargets::deb::Packages::Optional", false);
  92. Cnf.CndSet("Acquire::IndexTargets::deb::Translations::MetaKey", "$(COMPONENT)/i18n/Translation-$(LANGUAGE)");
  93. Cnf.CndSet("Acquire::IndexTargets::deb::Translations::flatMetaKey", "$(LANGUAGE)");
  94. Cnf.CndSet("Acquire::IndexTargets::deb::Translations::ShortDescription", "Translation-$(LANGUAGE)");
  95. Cnf.CndSet("Acquire::IndexTargets::deb::Translations::Description", "$(RELEASE)/$(COMPONENT) Translation-$(LANGUAGE)");
  96. Cnf.CndSet("Acquire::IndexTargets::deb::Translations::flatDescription", "$(RELEASE) Translation-$(LANGUAGE)");
  97. Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::MetaKey", "$(COMPONENT)/source/Sources");
  98. Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::flatMetaKey", "Sources");
  99. Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::ShortDescription", "Sources");
  100. Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::Description", "$(RELEASE)/$(COMPONENT) Sources");
  101. Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::flatDescription", "$(RELEASE) Sources");
  102. Cnf.CndSet("Acquire::IndexTargets::deb-src::Sources::Optional", false);
  103. Cnf.CndSet("Acquire::Changelogs::URI::Origin::Debian", "http://metadata.ftp-master.debian.org/changelogs/@CHANGEPATH@_changelog");
  104. Cnf.CndSet("Acquire::Changelogs::URI::Origin::Tanglu", "http://metadata.tanglu.org/changelogs/@CHANGEPATH@_changelog");
  105. Cnf.CndSet("Acquire::Changelogs::URI::Origin::Ubuntu", "http://changelogs.ubuntu.com/changelogs/pool/@CHANGEPATH@/changelog");
  106. Cnf.CndSet("Acquire::Changelogs::URI::Origin::Ultimedia", "http://packages.ultimediaos.com/changelogs/pool/@CHANGEPATH@/changelog.txt");
  107. Cnf.CndSet("Acquire::Changelogs::AlwaysOnline::Origin::Ubuntu", true);
  108. bool Res = true;
  109. // Read an alternate config file
  110. const char *Cfg = getenv("APT_CONFIG");
  111. if (Cfg != 0 && strlen(Cfg) != 0)
  112. {
  113. if (RealFileExists(Cfg) == true)
  114. Res &= ReadConfigFile(Cnf,Cfg);
  115. else
  116. _error->WarningE("RealFileExists",_("Unable to read %s"),Cfg);
  117. }
  118. // Read the configuration parts dir
  119. std::string const Parts = Cnf.FindDir("Dir::Etc::parts", "/dev/null");
  120. if (DirectoryExists(Parts) == true)
  121. Res &= ReadConfigDir(Cnf,Parts);
  122. else if (APT::String::Endswith(Parts, "/dev/null") == false)
  123. _error->WarningE("DirectoryExists",_("Unable to read %s"),Parts.c_str());
  124. // Read the main config file
  125. std::string const FName = Cnf.FindFile("Dir::Etc::main", "/dev/null");
  126. if (RealFileExists(FName) == true)
  127. Res &= ReadConfigFile(Cnf,FName);
  128. if (Res == false)
  129. return false;
  130. if (Cnf.FindB("Debug::pkgInitConfig",false) == true)
  131. Cnf.Dump();
  132. #ifdef APT_DOMAIN
  133. if (Cnf.Exists("Dir::Locale"))
  134. {
  135. bindtextdomain(APT_DOMAIN,Cnf.FindDir("Dir::Locale").c_str());
  136. bindtextdomain(textdomain(0),Cnf.FindDir("Dir::Locale").c_str());
  137. }
  138. #endif
  139. return true;
  140. }
  141. /*}}}*/
  142. // pkgInitSystem - Initialize the _system calss /*{{{*/
  143. // ---------------------------------------------------------------------
  144. /* */
  145. bool pkgInitSystem(Configuration &Cnf,pkgSystem *&Sys)
  146. {
  147. Sys = 0;
  148. std::string Label = Cnf.Find("Apt::System","");
  149. if (Label.empty() == false)
  150. {
  151. Sys = pkgSystem::GetSystem(Label.c_str());
  152. if (Sys == 0)
  153. return _error->Error(_("Packaging system '%s' is not supported"),Label.c_str());
  154. }
  155. else
  156. {
  157. signed MaxScore = 0;
  158. for (unsigned I = 0; I != pkgSystem::GlobalListLen; I++)
  159. {
  160. signed Score = pkgSystem::GlobalList[I]->Score(Cnf);
  161. if (Score > MaxScore)
  162. {
  163. MaxScore = Score;
  164. Sys = pkgSystem::GlobalList[I];
  165. }
  166. }
  167. if (Sys == 0)
  168. return _error->Error(_("Unable to determine a suitable packaging system type"));
  169. }
  170. return Sys->Initialize(Cnf);
  171. }
  172. /*}}}*/