init.cc 7.8 KB

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