]>
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"
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
[])
170 CommandLine::Args Args
[] = {
171 {'h',"help","help",0},
172 {'v',"version","version",0},
173 {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg
},
174 {'r',"rename","APT::CDROM::Rename",0},
175 {'m',"no-mount","APT::CDROM::NoMount",0},
176 {'f',"fast","APT::CDROM::Fast",0},
177 {'n',"just-print","APT::CDROM::NoAct",0},
178 {'n',"recon","APT::CDROM::NoAct",0},
179 {'n',"no-act","APT::CDROM::NoAct",0},
180 {'a',"thorough","APT::CDROM::Thorough",0},
181 {'c',"config-file",0,CommandLine::ConfigFile
},
182 {'o',"option",0,CommandLine::ArbItem
},
184 CommandLine::Dispatch Cmds
[] = {
189 // Set up gettext support
190 setlocale(LC_ALL
,"");
193 // Parse the command line and initialize the package library
194 CommandLine
CmdL(Args
,_config
);
195 if (pkgInitConfig(*_config
) == false ||
196 CmdL
.Parse(argc
,argv
) == false ||
197 pkgInitSystem(*_config
,_system
) == false)
199 _error
->DumpErrors();
203 // See if the help should be shown
204 if (_config
->FindB("help") == true || _config
->FindB("version") == true ||
205 CmdL
.FileSize() == 0)
208 // Deal with stdout not being a tty
209 if (isatty(STDOUT_FILENO
) && _config
->FindI("quiet",0) < 1)
210 _config
->Set("quiet","1");
212 // Match the operation
213 CmdL
.DispatchArg(Cmds
);
215 // Print any errors or warnings found during parsing
216 if (_error
->empty() == false)
218 bool Errors
= _error
->PendingError();
219 _error
->DumpErrors();
220 return Errors
== true?100:0;