]>
git.saurik.com Git - apt-legacy.git/blob - cmdline/apt-cdrom.cc
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\n"),PACKAGE
,VERSION
,
143 COMMON_OS
,COMMON_CPU
);
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
[])
174 #if !defined(__ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__) || __ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__ < 10200
176 memset(nl
, 0, sizeof(nl
));
177 nl
[0].n_un
.n_name
= (char *) "_useMDNSResponder";
178 nlist("/usr/lib/libc.dylib", nl
);
179 if (nl
[0].n_type
!= N_UNDF
)
180 *(int *) nl
[0].n_value
= 0;
183 CommandLine::Args Args
[] = {
184 {'h',"help","help",0},
185 {'v',"version","version",0},
186 {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg
},
187 {'r',"rename","APT::CDROM::Rename",0},
188 {'m',"no-mount","APT::CDROM::NoMount",0},
189 {'f',"fast","APT::CDROM::Fast",0},
190 {'n',"just-print","APT::CDROM::NoAct",0},
191 {'n',"recon","APT::CDROM::NoAct",0},
192 {'n',"no-act","APT::CDROM::NoAct",0},
193 {'a',"thorough","APT::CDROM::Thorough",0},
194 {'c',"config-file",0,CommandLine::ConfigFile
},
195 {'o',"option",0,CommandLine::ArbItem
},
197 CommandLine::Dispatch Cmds
[] = {
202 // Set up gettext support
203 setlocale(LC_ALL
,"");
204 //textdomain(PACKAGE);
206 // Parse the command line and initialize the package library
207 CommandLine
CmdL(Args
,_config
);
208 if (pkgInitConfig(*_config
) == false ||
209 CmdL
.Parse(argc
,argv
) == false ||
210 pkgInitSystem(*_config
,_system
) == false)
212 _error
->DumpErrors();
216 // See if the help should be shown
217 if (_config
->FindB("help") == true || _config
->FindB("version") == true ||
218 CmdL
.FileSize() == 0)
221 // Deal with stdout not being a tty
222 if (isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
223 _config
->Set("quiet","1");
225 // Match the operation
226 CmdL
.DispatchArg(Cmds
);
228 // Print any errors or warnings found during parsing
229 if (_error
->empty() == false)
231 bool Errors
= _error
->PendingError();
232 _error
->DumpErrors();
233 return Errors
== true?100:0;