]>
git.saurik.com Git - apt.git/blob - cmdline/apt-cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-cdrom.cc,v 1.45 2003/11/19 23:50:51 mdz Exp $
4 /* ######################################################################
6 APT CDROM - Tool for handling APT's CDROM database.
8 Currently the only option is 'add' which will take the current CD
9 in the drive and add it into the database.
11 ##################################################################### */
13 // Include Files /*{{{*/
14 #include <apt-pkg/cmndline.h>
15 #include <apt-pkg/error.h>
16 #include <apt-pkg/init.h>
17 #include <apt-pkg/fileutl.h>
18 #include <apt-pkg/progress.h>
19 #include <apt-pkg/cdromutl.h>
20 #include <apt-pkg/strutl.h>
21 #include <apt-pkg/acquire.h>
22 #include <apt-pkg/acquire-item.h>
23 #include <apt-pkg/cdrom.h>
27 //#include "indexcopy.h"
43 class pkgCdromTextStatus
: public pkgCdromStatus
/*{{{*/
46 OpTextProgress Progress
;
47 void Prompt(const char *Text
);
48 string
PromptLine(const char *Text
);
49 bool AskCdromName(string
&name
);
52 virtual void Update(string text
, int current
);
53 virtual bool ChangeCdrom();
54 virtual OpProgress
* GetOpProgress();
57 void pkgCdromTextStatus::Prompt(const char *Text
)
60 cout
<< Text
<< ' ' << flush
;
61 read(STDIN_FILENO
,&C
,1);
66 string
pkgCdromTextStatus::PromptLine(const char *Text
)
68 cout
<< Text
<< ':' << endl
;
75 bool pkgCdromTextStatus::AskCdromName(string
&name
)
77 cout
<< _("Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'") << flush
;
78 name
= PromptLine("");
84 void pkgCdromTextStatus::Update(string text
, int current
)
87 cout
<< text
<< flush
;
90 bool pkgCdromTextStatus::ChangeCdrom()
92 Prompt(_("Please insert a Disc in the drive and press enter"));
96 OpProgress
* pkgCdromTextStatus::GetOpProgress()
101 // DoAdd - Add a new CDROM /*{{{*/
102 // ---------------------------------------------------------------------
103 /* This does the main add bit.. We show some status and things. The
104 sequence is to mount/umount the CD, Ident it then scan it for package
105 files and reduce that list. Then we copy over the package files and
106 verify them. Then rewrite the database files */
107 bool DoAdd(CommandLine
&)
110 pkgCdromTextStatus log
;
112 res
= cdrom
.Add(&log
);
114 cout
<< _("Repeat this process for the rest of the CDs in your set.") << endl
;
118 // DoIdent - Ident a CDROM /*{{{*/
119 // ---------------------------------------------------------------------
121 bool DoIdent(CommandLine
&)
124 pkgCdromTextStatus log
;
126 return cdrom
.Ident(ident
, &log
);
129 // ShowHelp - Show the help screen /*{{{*/
130 // ---------------------------------------------------------------------
134 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,VERSION
,
135 COMMON_ARCH
,__DATE__
,__TIME__
);
136 if (_config
->FindB("version") == true)
140 "Usage: apt-cdrom [options] command\n"
142 "apt-cdrom is a tool to add CDROM's to APT's source list. The\n"
143 "CDROM mount point and device information is taken from apt.conf\n"
147 " add - Add a CDROM\n"
148 " ident - Report the identity of a CDROM\n"
151 " -h This help text\n"
152 " -d CD-ROM mount point\n"
153 " -r Rename a recognized CD-ROM\n"
155 " -f Fast mode, don't check package files\n"
156 " -a Thorough scan mode\n"
157 " -c=? Read this configuration file\n"
158 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
163 int main(int argc
,const char *argv
[]) /*{{{*/
165 CommandLine::Args Args
[] = {
166 {'h',"help","help",0},
167 {'v',"version","version",0},
168 {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg
},
169 {'r',"rename","APT::CDROM::Rename",0},
170 {'m',"no-mount","APT::CDROM::NoMount",0},
171 {'f',"fast","APT::CDROM::Fast",0},
172 {'n',"just-print","APT::CDROM::NoAct",0},
173 {'n',"recon","APT::CDROM::NoAct",0},
174 {'n',"no-act","APT::CDROM::NoAct",0},
175 {'a',"thorough","APT::CDROM::Thorough",0},
176 {'c',"config-file",0,CommandLine::ConfigFile
},
177 {'o',"option",0,CommandLine::ArbItem
},
179 CommandLine::Dispatch Cmds
[] = {
184 // Set up gettext support
185 setlocale(LC_ALL
,"");
188 // Parse the command line and initialize the package library
189 CommandLine
CmdL(Args
,_config
);
190 if (pkgInitConfig(*_config
) == false ||
191 CmdL
.Parse(argc
,argv
) == false ||
192 pkgInitSystem(*_config
,_system
) == false)
194 _error
->DumpErrors();
198 // See if the help should be shown
199 if (_config
->FindB("help") == true || _config
->FindB("version") == true ||
200 CmdL
.FileSize() == 0)
203 // Deal with stdout not being a tty
204 if (isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
205 _config
->Set("quiet","1");
207 // Match the operation
208 CmdL
.DispatchArg(Cmds
);
210 // Print any errors or warnings found during parsing
211 if (_error
->empty() == false)
213 bool Errors
= _error
->PendingError();
214 _error
->DumpErrors();
215 return Errors
== true?100:0;