From 169413dcf101ca39aebc2bf46991c27c1e439259 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Jan 2010 16:43:20 +0100 Subject: cmdline/apt-cdrom.cc: add --auto-detect --- cmdline/apt-cdrom.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 3 deletions(-) (limited to 'cmdline') diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index d804c55e5..fc949ce7b 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -98,6 +98,39 @@ OpProgress* pkgCdromTextStatus::GetOpProgress() return &Progress; }; /*}}}*/ +// SetupAutoDetect /*{{{*/ +bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, int &i) +{ + bool Debug = _config->FindB("Debug::Acquire::cdrom", false); + + vector v = UdevCdroms.Scan(); + if (i >= v.size()) + return false; + + if (Debug) + clog << "Looking at devce " << i + << " DeviveName: " << v[i].DeviceName + << " IsMounted: '" << v[i].Mounted << "'" + << " MountPoint: '" << v[i].MountPath << "'" + << endl; + + if (v[i].Mounted) + { + // set the right options + _config->Set("Acquire::cdrom::mount", v[i].MountPath); + _config->Set("APT::CDROM::NoMount", true); + } else { + MountCdrom("/var/lib/apt/media", v[i].DeviceName); + MountCdrom("/var/lib/apt/media", v[i].DeviceName); + _config->Set("Acquire::cdrom::mount", "/var/lib/apt/media"); + _config->Set("APT::CDROM::NoMount", true); + } + i++; + + return true; +} + /*}}}*/ + // DoAdd - Add a new CDROM /*{{{*/ // --------------------------------------------------------------------- /* This does the main add bit.. We show some status and things. The @@ -106,12 +139,25 @@ OpProgress* pkgCdromTextStatus::GetOpProgress() verify them. Then rewrite the database files */ bool DoAdd(CommandLine &) { - bool res = false; + pkgUdevCdromDevices UdevCdroms; pkgCdromTextStatus log; pkgCdrom cdrom; - res = cdrom.Add(&log); + bool res = false; + + bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); + int count = 0; + + if (AutoDetect && UdevCdroms.Dlopen()) + { + while (AutoDetectCdrom(UdevCdroms, count)) + res &= cdrom.Add(&log); + } else { + res = cdrom.Add(&log); + } + if(res) cout << _("Repeat this process for the rest of the CDs in your set.") << endl; + return res; } /*}}}*/ @@ -120,10 +166,24 @@ bool DoAdd(CommandLine &) /* */ bool DoIdent(CommandLine &) { + pkgUdevCdromDevices UdevCdroms; string ident; pkgCdromTextStatus log; pkgCdrom cdrom; - return cdrom.Ident(ident, &log); + bool res = true; + + bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); + int count = 0; + + if (AutoDetect && UdevCdroms.Dlopen()) + { + while (AutoDetectCdrom(UdevCdroms, count)) + res &= cdrom.Ident(ident, &log); + } else { + return cdrom.Ident(ident, &log); + } + + return res; } /*}}}*/ // ShowHelp - Show the help screen /*{{{*/ @@ -164,6 +224,7 @@ int main(int argc,const char *argv[]) /*{{{*/ { CommandLine::Args Args[] = { {'h',"help","help",0}, + {'a',"auto-detect","Acquire::cdrom::AutoDetect",0}, {'v',"version","version",0}, {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg}, {'r',"rename","APT::CDROM::Rename",0}, -- cgit v1.2.3-70-g09d2 From fb503892e3e05132bb7db369440402ff81ea5f8d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Jan 2010 20:36:13 +0100 Subject: * cmdline/apt-cdrom.cc: - fixed signed/unsigned warning - create /media mount point if needed - fix initialization for res in DoAdd() * methods/cdrom.cc: - make AptMountPoint a variable --- apt-pkg/cdrom.cc | 2 -- cmdline/apt-cdrom.cc | 17 ++++++++++------- methods/cdrom.cc | 13 +++++++------ 3 files changed, 17 insertions(+), 15 deletions(-) (limited to 'cmdline') diff --git a/apt-pkg/cdrom.cc b/apt-pkg/cdrom.cc index 3467f49d7..96d4e9c91 100644 --- a/apt-pkg/cdrom.cc +++ b/apt-pkg/cdrom.cc @@ -829,8 +829,6 @@ bool pkgCdrom::Add(pkgCdromStatus *log) /*{{{*/ } } - - // Unmount and finish if (_config->FindB("APT::CDROM::NoMount",false) == false) { log->Update(_("Unmounting CD-ROM...\n"), STEP_LAST); diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index fc949ce7b..494a7d8df 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -99,7 +99,7 @@ OpProgress* pkgCdromTextStatus::GetOpProgress() }; /*}}}*/ // SetupAutoDetect /*{{{*/ -bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, int &i) +bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, unsigned int &i) { bool Debug = _config->FindB("Debug::Acquire::cdrom", false); @@ -120,9 +120,12 @@ bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, int &i) _config->Set("Acquire::cdrom::mount", v[i].MountPath); _config->Set("APT::CDROM::NoMount", true); } else { - MountCdrom("/var/lib/apt/media", v[i].DeviceName); - MountCdrom("/var/lib/apt/media", v[i].DeviceName); - _config->Set("Acquire::cdrom::mount", "/var/lib/apt/media"); + const char* AptMountPoint = "/media/apt"; + if (!FileExists(AptMountPoint)) + mkdir(AptMountPoint, 0750); + if(MountCdrom(AptMountPoint, v[i].DeviceName) == false) + _error->Warning(_("Failed to mount '%s' to '%s'"), v[i].DeviceName.c_str(), AptMountPoint); + _config->Set("Acquire::cdrom::mount", AptMountPoint); _config->Set("APT::CDROM::NoMount", true); } i++; @@ -142,10 +145,10 @@ bool DoAdd(CommandLine &) pkgUdevCdromDevices UdevCdroms; pkgCdromTextStatus log; pkgCdrom cdrom; - bool res = false; + bool res = true; bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); - int count = 0; + unsigned int count = 0; if (AutoDetect && UdevCdroms.Dlopen()) { @@ -173,7 +176,7 @@ bool DoIdent(CommandLine &) bool res = true; bool AutoDetect = _config->FindB("Acquire::cdrom::AutoDetect"); - int count = 0; + unsigned int count = 0; if (AutoDetect && UdevCdroms.Dlopen()) { diff --git a/methods/cdrom.cc b/methods/cdrom.cc index 0e78851ff..c8ec322ee 100644 --- a/methods/cdrom.cc +++ b/methods/cdrom.cc @@ -116,23 +116,24 @@ bool CDROMMethod::AutoDetectAndMount(URI Get, string &NewID) return false; // check if we have the mount point - if (!FileExists("/media/apt")) - mkdir("/media/apt", 0755); + const char* AptMountPoint = "/media/apt"; + if (!FileExists(AptMountPoint)) + mkdir(AptMountPoint, 0750); // now try mounting for (unsigned int i=0; i < v.size(); i++) { if (!v[i].Mounted) { - if(MountCdrom("/media/apt", v[i].DeviceName)) + if(MountCdrom(AptMountPoint, v[i].DeviceName)) { - if (IsCorrectCD(Get, "/media/apt", NewID)) + if (IsCorrectCD(Get, AptMountPoint, NewID)) { MountedByApt = true; - CDROM = "/media/apt"; + CDROM = AptMountPoint; return true; } else { - UnmountCdrom("/media/apt"); + UnmountCdrom(AptMountPoint); } } } -- cgit v1.2.3-70-g09d2 From ffee221b8d1df28768d30762d72a11289ae747dc Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Tue, 26 Jan 2010 21:08:41 +0100 Subject: add Dir::Media::MountPath config option --- apt-pkg/init.cc | 3 ++- cmdline/apt-cdrom.cc | 6 +++--- doc/examples/configure-index | 7 +++++++ methods/cdrom.cc | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) (limited to 'cmdline') diff --git a/apt-pkg/init.cc b/apt-pkg/init.cc index 2544b8025..6310aff11 100644 --- a/apt-pkg/init.cc +++ b/apt-pkg/init.cc @@ -65,11 +65,12 @@ bool pkgInitConfig(Configuration &Cnf) Cnf.Set("Dir::Etc::vendorlist","vendors.list"); Cnf.Set("Dir::Etc::vendorparts","vendors.list.d"); Cnf.Set("Dir::Etc::main","apt.conf"); - Cnf.Set("Dir::ETc::netrc", "auth.conf"); + Cnf.Set("Dir::Etc::netrc", "auth.conf"); Cnf.Set("Dir::Etc::parts","apt.conf.d"); Cnf.Set("Dir::Etc::preferences","preferences"); Cnf.Set("Dir::Etc::preferencesparts","preferences.d"); Cnf.Set("Dir::Bin::methods","/usr/lib/apt/methods"); + Cnf.Set("Dir::Media::MountPath","/media/apt"); // State Cnf.Set("Dir::Log","var/log/apt"); diff --git a/cmdline/apt-cdrom.cc b/cmdline/apt-cdrom.cc index 494a7d8df..988a58f20 100644 --- a/cmdline/apt-cdrom.cc +++ b/cmdline/apt-cdrom.cc @@ -120,11 +120,11 @@ bool AutoDetectCdrom(pkgUdevCdromDevices &UdevCdroms, unsigned int &i) _config->Set("Acquire::cdrom::mount", v[i].MountPath); _config->Set("APT::CDROM::NoMount", true); } else { - const char* AptMountPoint = "/media/apt"; + string AptMountPoint = _config->FindDir("Dir::Media::MountPath"); if (!FileExists(AptMountPoint)) - mkdir(AptMountPoint, 0750); + mkdir(AptMountPoint.c_str(), 0750); if(MountCdrom(AptMountPoint, v[i].DeviceName) == false) - _error->Warning(_("Failed to mount '%s' to '%s'"), v[i].DeviceName.c_str(), AptMountPoint); + _error->Warning(_("Failed to mount '%s' to '%s'"), v[i].DeviceName.c_str(), AptMountPoint.c_str()); _config->Set("Acquire::cdrom::mount", AptMountPoint); _config->Set("APT::CDROM::NoMount", true); } diff --git a/doc/examples/configure-index b/doc/examples/configure-index index 317acddf6..0b0025fca 100644 --- a/doc/examples/configure-index +++ b/doc/examples/configure-index @@ -331,6 +331,13 @@ Dir "/" Terminal "term.log"; History "history.log"; }; + + // Media + Media + { + // Media AutoDetect mount path + MountPath "/media/apt"; + }; }; // Things that effect the APT dselect method diff --git a/methods/cdrom.cc b/methods/cdrom.cc index c8ec322ee..4bbc01c2c 100644 --- a/methods/cdrom.cc +++ b/methods/cdrom.cc @@ -116,9 +116,9 @@ bool CDROMMethod::AutoDetectAndMount(URI Get, string &NewID) return false; // check if we have the mount point - const char* AptMountPoint = "/media/apt"; + string AptMountPoint = _config->FindDir("Dir::Media::MountPath"); if (!FileExists(AptMountPoint)) - mkdir(AptMountPoint, 0750); + mkdir(AptMountPoint.c_str(), 0750); // now try mounting for (unsigned int i=0; i < v.size(); i++) -- cgit v1.2.3-70-g09d2