- // Startup
- string CDROM = _config->FindDir("Acquire::cdrom::mount","/cdrom/");
- if (CDROM[0] == '.')
- CDROM= SafeGetCWD() + '/' + CDROM;
-
- cout << "Using CD-ROM mount point " << CDROM << endl;
-
- // Read the database
- Configuration Database;
- string DFile = _config->FindFile("Dir::State::cdroms");
- if (FileExists(DFile) == true)
- {
- if (ReadConfigFile(Database,DFile) == false)
- return _error->Error("Unable to read the cdrom database %s",
- DFile.c_str());
- }
-
- // Unmount the CD and get the user to put in the one they want
- if (_config->FindB("APT::CDROM::NoMount",false) == false)
- {
- cout << "Unmounting CD-ROM" << endl;
- UnmountCdrom(CDROM);
-
- // Mount the new CDROM
- Prompt("Please insert a Disc in the drive and press any key");
- cout << "Mounting CD-ROM" << endl;
- if (MountCdrom(CDROM) == false)
- {
- cout << "Failed to mount the cdrom." << endl;
- return false;
- }
- }
-
- // Hash the CD to get an ID
- cout << "Identifying.. " << flush;
- string ID;
- if (IdentCdrom(CDROM,ID) == false)
- {
- cout << endl;
- return false;
- }
-
- cout << '[' << ID << ']' << endl;
-
- cout << "Scanning Disc for index files.. " << flush;
- // Get the CD structure
- vector<string> List;
- string StartDir = SafeGetCWD();
- if (FindPackages(CDROM,List) == false)
- {
- cout << endl;
- return false;
- }
-
- chdir(StartDir.c_str());
-
- if (_config->FindB("Debug::aptcdrom",false) == true)
- {
- cout << "I found:" << endl;
- for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
- {
- cout << *I << endl;
- }
- }
-
- // Fix up the list
- DropBinaryArch(List);
- DropRepeats(List);
- cout << "Found " << List.size() << " package index files." << endl;
-
- if (List.size() == 0)
- return _error->Error("Unable to locate any package files, perhaps this is not a Debian Disc");
-
- // Check if the CD is in the database
- string Name;
- if (Database.Exists("CD::" + ID) == false ||
- _config->FindB("APT::CDROM::Rename",false) == true)
- {
- // Try to use the CDs label if at all possible
- if (FileExists(CDROM + "/.disk/info") == true)
- {
- ifstream F(string(CDROM+ "/.disk/info").c_str());
- if (!F == 0)
- getline(F,Name);
-
- if (Name.empty() == false)
- {
- cout << "Found label '" << Name << "'" << endl;
- Database.Set("CD::" + ID + "::Label",Name);
- }
- }
-
- if (_config->FindB("APT::CDROM::Rename",false) == true ||
- Name.empty() == true)
- {
- cout << "Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'";
- while (1)
- {
- Name = PromptLine("");
- if (Name.empty() == false &&
- Name.find('"') == string::npos &&
- Name.find(':') == string::npos &&
- Name.find('/') == string::npos)
- break;
- cout << "That is not a valid name, try again " << endl;
- }
- }
- }
- else
- Name = Database.Find("CD::" + ID);
-
- string::iterator J = Name.begin();
- for (; J != Name.end(); J++)
- if (*J == '/' || *J == '"' || *J == ':')
- *J = '_';
-
- Database.Set("CD::" + ID,Name);
- cout << "This Disc is called '" << Name << "'" << endl;
-
- // Copy the package files to the state directory
- if (CopyPackages(CDROM,Name,List) == false)
- return false;
-
- ReduceSourcelist(CDROM,List);
-
- // Write the database and sourcelist
- if (_config->FindB("APT::cdrom::NoAct",false) == false)
- {
- if (WriteDatabase(Database) == false)
- return false;
-
- cout << "Writing new source list" << endl;
- if (WriteSourceList(Name,List) == false)
- return false;
- }
-
- // Print the sourcelist entries
- cout << "Source List entries for this Disc are:" << endl;
- for (vector<string>::iterator I = List.begin(); I != List.end(); I++)
- {
- string::size_type Space = (*I).find(' ');
- if (Space == string::npos)
- return _error->Error("Internal error");
-
- cout << "deb \"cdrom:" << Name << "/" << string(*I,0,Space) <<
- "\" " << string(*I,Space+1) << endl;
- }
-
- return true;