2 #include <mach-o/nlist.h>
5 // -*- mode: cpp; mode: fold -*-
7 // $Id: apt-cdrom.cc,v 1.45 2003/11/19 23:50:51 mdz Exp $
8 /* ######################################################################
10 APT CDROM - Tool for handling APT's CDROM database.
12 Currently the only option is 'add' which will take the current CD
13 in the drive and add it into the database.
15 ##################################################################### */
17 // Include Files /*{{{*/
18 #include <apt-pkg/cmndline.h>
19 #include <apt-pkg/error.h>
20 #include <apt-pkg/init.h>
21 #include <apt-pkg/fileutl.h>
22 #include <apt-pkg/progress.h>
23 #include <apt-pkg/cdromutl.h>
24 #include <apt-pkg/strutl.h>
25 #include <apt-pkg/acquire.h>
26 #include <apt-pkg/acquire-item.h>
27 #include <apt-pkg/cdrom.h>
31 //#include "indexcopy.h"
48 class pkgCdromTextStatus : public pkgCdromStatus
51 OpTextProgress Progress;
52 void Prompt(const char *Text);
53 string PromptLine(const char *Text);
54 bool AskCdromName(string &name);
57 virtual void Update(string text, int current);
58 virtual bool ChangeCdrom();
59 virtual OpProgress* GetOpProgress();
62 void pkgCdromTextStatus::Prompt(const char *Text)
65 cout << Text << ' ' << flush;
66 read(STDIN_FILENO,&C,1);
71 string pkgCdromTextStatus::PromptLine(const char *Text)
73 cout << Text << ':' << endl;
80 bool pkgCdromTextStatus::AskCdromName(string &name)
82 cout << _("Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'") << flush;
83 name = PromptLine("");
89 void pkgCdromTextStatus::Update(string text, int current)
92 cout << text << flush;
95 bool pkgCdromTextStatus::ChangeCdrom()
97 Prompt(_("Please insert a Disc in the drive and press enter"));
101 OpProgress* pkgCdromTextStatus::GetOpProgress()
108 // DoAdd - Add a new CDROM /*{{{*/
109 // ---------------------------------------------------------------------
110 /* This does the main add bit.. We show some status and things. The
111 sequence is to mount/umount the CD, Ident it then scan it for package
112 files and reduce that list. Then we copy over the package files and
113 verify them. Then rewrite the database files */
114 bool DoAdd(CommandLine &)
117 pkgCdromTextStatus log;
119 res = cdrom.Add(&log);
121 cout << _("Repeat this process for the rest of the CDs in your set.") << endl;
125 // DoIdent - Ident a CDROM /*{{{*/
126 // ---------------------------------------------------------------------
128 bool DoIdent(CommandLine &)
131 pkgCdromTextStatus log;
133 return cdrom.Ident(ident, &log);
137 // ShowHelp - Show the help screen /*{{{*/
138 // ---------------------------------------------------------------------
142 ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
143 COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
144 if (_config->FindB("version") == true)
148 "Usage: apt-cdrom [options] command\n"
150 "apt-cdrom is a tool to add CDROM's to APT's source list. The\n"
151 "CDROM mount point and device information is taken from apt.conf\n"
155 " add - Add a CDROM\n"
156 " ident - Report the identity of a CDROM\n"
159 " -h This help text\n"
160 " -d CD-ROM mount point\n"
161 " -r Rename a recognized CD-ROM\n"
163 " -f Fast mode, don't check package files\n"
164 " -a Thorough scan mode\n"
165 " -c=? Read this configuration file\n"
166 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
172 int main(int argc,const char *argv[])
175 memset(nl, 0, sizeof(nl));
176 nl[0].n_un.n_name = (char *) "_useMDNSResponder";
177 nlist("/usr/lib/libc.dylib", nl);
178 if (nl[0].n_type != N_UNDF)
179 *(int *) nl[0].n_value = 0;
181 CommandLine::Args Args[] = {
182 {'h',"help","help",0},
183 {'v',"version","version",0},
184 {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg},
185 {'r',"rename","APT::CDROM::Rename",0},
186 {'m',"no-mount","APT::CDROM::NoMount",0},
187 {'f',"fast","APT::CDROM::Fast",0},
188 {'n',"just-print","APT::CDROM::NoAct",0},
189 {'n',"recon","APT::CDROM::NoAct",0},
190 {'n',"no-act","APT::CDROM::NoAct",0},
191 {'a',"thorough","APT::CDROM::Thorough",0},
192 {'c',"config-file",0,CommandLine::ConfigFile},
193 {'o',"option",0,CommandLine::ArbItem},
195 CommandLine::Dispatch Cmds[] = {
200 // Set up gettext support
201 setlocale(LC_ALL,"");
204 // Parse the command line and initialize the package library
205 CommandLine CmdL(Args,_config);
206 if (pkgInitConfig(*_config) == false ||
207 CmdL.Parse(argc,argv) == false ||
208 pkgInitSystem(*_config,_system) == false)
210 _error->DumpErrors();
214 // See if the help should be shown
215 if (_config->FindB("help") == true || _config->FindB("version") == true ||
216 CmdL.FileSize() == 0)
219 // Deal with stdout not being a tty
220 if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
221 _config->Set("quiet","1");
223 // Match the operation
224 CmdL.DispatchArg(Cmds);
226 // Print any errors or warnings found during parsing
227 if (_error->empty() == false)
229 bool Errors = _error->PendingError();
230 _error->DumpErrors();
231 return Errors == true?100:0;