]>
git.saurik.com Git - apt-legacy.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"
44 class pkgCdromTextStatus
: public pkgCdromStatus
47 OpTextProgress Progress
;
48 void Prompt(const char *Text
);
49 string
PromptLine(const char *Text
);
50 bool AskCdromName(string
&name
);
53 virtual void Update(string text
, int current
);
54 virtual bool ChangeCdrom();
55 virtual OpProgress
* GetOpProgress();
58 void pkgCdromTextStatus::Prompt(const char *Text
)
61 cout
<< Text
<< ' ' << flush
;
62 read(STDIN_FILENO
,&C
,1);
67 string
pkgCdromTextStatus::PromptLine(const char *Text
)
69 cout
<< Text
<< ':' << endl
;
76 bool pkgCdromTextStatus::AskCdromName(string
&name
)
78 cout
<< _("Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'") << flush
;
79 name
= PromptLine("");
85 void pkgCdromTextStatus::Update(string text
, int current
)
88 cout
<< text
<< flush
;
91 bool pkgCdromTextStatus::ChangeCdrom()
93 Prompt(_("Please insert a Disc in the drive and press enter"));
97 OpProgress
* pkgCdromTextStatus::GetOpProgress()
104 // DoAdd - Add a new CDROM /*{{{*/
105 // ---------------------------------------------------------------------
106 /* This does the main add bit.. We show some status and things. The
107 sequence is to mount/umount the CD, Ident it then scan it for package
108 files and reduce that list. Then we copy over the package files and
109 verify them. Then rewrite the database files */
110 bool DoAdd(CommandLine
&)
113 pkgCdromTextStatus log
;
115 res
= cdrom
.Add(&log
);
117 cout
<< _("Repeat this process for the rest of the CDs in your set.") << endl
;
121 // DoIdent - Ident a CDROM /*{{{*/
122 // ---------------------------------------------------------------------
124 bool DoIdent(CommandLine
&)
127 pkgCdromTextStatus log
;
129 return cdrom
.Ident(ident
, &log
);
133 // ShowHelp - Show the help screen /*{{{*/
134 // ---------------------------------------------------------------------
138 ioprintf(cout
,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE
,VERSION
,
139 COMMON_OS
,COMMON_CPU
,__DATE__
,__TIME__
);
140 if (_config
->FindB("version") == true)
144 "Usage: apt-cdrom [options] command\n"
146 "apt-cdrom is a tool to add CDROM's to APT's source list. The\n"
147 "CDROM mount point and device information is taken from apt.conf\n"
151 " add - Add a CDROM\n"
152 " ident - Report the identity of a CDROM\n"
155 " -h This help text\n"
156 " -d CD-ROM mount point\n"
157 " -r Rename a recognized CD-ROM\n"
159 " -f Fast mode, don't check package files\n"
160 " -a Thorough scan mode\n"
161 " -c=? Read this configuration file\n"
162 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
168 int main_(int argc
,const char *argv
[]);
169 int main(int argc
,const char *argv
[]) {
170 _exit(main_(argc
, argv
));
172 int main_(int argc
,const char *argv
[])
174 CommandLine::Args Args
[] = {
175 {'h',"help","help",0},
176 {'v',"version","version",0},
177 {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg
},
178 {'r',"rename","APT::CDROM::Rename",0},
179 {'m',"no-mount","APT::CDROM::NoMount",0},
180 {'f',"fast","APT::CDROM::Fast",0},
181 {'n',"just-print","APT::CDROM::NoAct",0},
182 {'n',"recon","APT::CDROM::NoAct",0},
183 {'n',"no-act","APT::CDROM::NoAct",0},
184 {'a',"thorough","APT::CDROM::Thorough",0},
185 {'c',"config-file",0,CommandLine::ConfigFile
},
186 {'o',"option",0,CommandLine::ArbItem
},
188 CommandLine::Dispatch Cmds
[] = {
193 // Set up gettext support
194 setlocale(LC_ALL
,"");
195 //textdomain(PACKAGE);
197 // Parse the command line and initialize the package library
198 CommandLine
CmdL(Args
,_config
);
199 if (pkgInitConfig(*_config
) == false ||
200 CmdL
.Parse(argc
,argv
) == false ||
201 pkgInitSystem(*_config
,_system
) == false)
203 _error
->DumpErrors();
207 // See if the help should be shown
208 if (_config
->FindB("help") == true || _config
->FindB("version") == true ||
209 CmdL
.FileSize() == 0)
212 // Deal with stdout not being a tty
213 if (isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
214 _config
->Set("quiet","1");
216 // Match the operation
217 CmdL
.DispatchArg(Cmds
);
219 // Print any errors or warnings found during parsing
220 if (_error
->empty() == false)
222 bool Errors
= _error
->PendingError();
223 _error
->DumpErrors();
224 return Errors
== true?100:0;