]> git.saurik.com Git - apt.git/blame - cmdline/apt-cdrom.cc
merge with lp:~mvo/apt/apt-sid to get the complete fr
[apt.git] / cmdline / apt-cdrom.cc
CommitLineData
83d89a9f
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
a3f6ea20 3// $Id: apt-cdrom.cc,v 1.45 2003/11/19 23:50:51 mdz Exp $
83d89a9f
AL
4/* ######################################################################
5
18444708
AL
6 APT CDROM - Tool for handling APT's CDROM database.
7
8 Currently the only option is 'add' which will take the current CD
9 in the drive and add it into the database.
83d89a9f
AL
10
11 ##################################################################### */
12 /*}}}*/
13// Include Files /*{{{*/
14#include <apt-pkg/cmndline.h>
15#include <apt-pkg/error.h>
16#include <apt-pkg/init.h>
83d89a9f
AL
17#include <apt-pkg/fileutl.h>
18#include <apt-pkg/progress.h>
65ae8fab 19#include <apt-pkg/cdromutl.h>
cdcc6d34 20#include <apt-pkg/strutl.h>
a75c6a6e
MZ
21#include <apt-pkg/acquire.h>
22#include <apt-pkg/acquire-item.h>
23#include <apt-pkg/cdrom.h>
83d89a9f 24#include <config.h>
b2e465d6
AL
25#include <apti18n.h>
26
a75c6a6e 27//#include "indexcopy.h"
143abaeb 28
233c2b66 29#include <locale.h>
83d89a9f 30#include <iostream>
18444708 31#include <fstream>
83d89a9f
AL
32#include <vector>
33#include <algorithm>
83d89a9f
AL
34#include <sys/stat.h>
35#include <fcntl.h>
36#include <dirent.h>
37#include <unistd.h>
38#include <stdio.h>
39 /*}}}*/
40
076d01b0
AL
41using namespace std;
42
92fcbfc1 43class pkgCdromTextStatus : public pkgCdromStatus /*{{{*/
83d89a9f 44{
a75c6a6e
MZ
45protected:
46 OpTextProgress Progress;
47 void Prompt(const char *Text);
48 string PromptLine(const char *Text);
49 bool AskCdromName(string &name);
50
51public:
52 virtual void Update(string text, int current);
53 virtual bool ChangeCdrom();
54 virtual OpProgress* GetOpProgress();
8a579291 55};
83d89a9f 56
a75c6a6e 57void pkgCdromTextStatus::Prompt(const char *Text)
83d89a9f 58{
a75c6a6e
MZ
59 char C;
60 cout << Text << ' ' << flush;
61 read(STDIN_FILENO,&C,1);
62 if (C != '\n')
63 cout << endl;
83d89a9f 64}
4dfaa253 65
a75c6a6e 66string pkgCdromTextStatus::PromptLine(const char *Text)
83d89a9f 67{
a75c6a6e 68 cout << Text << ':' << endl;
83d89a9f 69
a75c6a6e
MZ
70 string Res;
71 getline(cin,Res);
83d89a9f
AL
72 return Res;
73}
18444708 74
a75c6a6e 75bool pkgCdromTextStatus::AskCdromName(string &name)
83d89a9f 76{
cdd5a135 77 cout << _("Please provide a name for this Disc, such as 'Debian 5.0.3 Disk 1'") << flush;
a75c6a6e 78 name = PromptLine("");
83d89a9f 79
83d89a9f
AL
80 return true;
81}
83d89a9f 82
83d89a9f 83
a75c6a6e 84void pkgCdromTextStatus::Update(string text, int current)
18444708 85{
a75c6a6e
MZ
86 if(text.size() > 0)
87 cout << text << flush;
18444708 88}
4dfaa253 89
8a579291 90bool pkgCdromTextStatus::ChangeCdrom()
83d89a9f 91{
4a5e5089 92 Prompt(_("Please insert a Disc in the drive and press enter"));
18444708
AL
93 return true;
94}
83d89a9f 95
8a579291 96OpProgress* pkgCdromTextStatus::GetOpProgress()
a75c6a6e
MZ
97{
98 return &Progress;
99};
83d89a9f 100 /*}}}*/
83d89a9f
AL
101// DoAdd - Add a new CDROM /*{{{*/
102// ---------------------------------------------------------------------
4dfaa253
AL
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 */
83d89a9f
AL
107bool DoAdd(CommandLine &)
108{
a75c6a6e
MZ
109 bool res = false;
110 pkgCdromTextStatus log;
111 pkgCdrom cdrom;
112 res = cdrom.Add(&log);
113 if(res)
4a5e5089 114 cout << _("Repeat this process for the rest of the CDs in your set.") << endl;
a75c6a6e 115 return res;
83d89a9f
AL
116}
117 /*}}}*/
b2e465d6
AL
118// DoIdent - Ident a CDROM /*{{{*/
119// ---------------------------------------------------------------------
120/* */
121bool DoIdent(CommandLine &)
122{
a75c6a6e
MZ
123 string ident;
124 pkgCdromTextStatus log;
125 pkgCdrom cdrom;
126 return cdrom.Ident(ident, &log);
b2e465d6
AL
127}
128 /*}}}*/
83d89a9f
AL
129// ShowHelp - Show the help screen /*{{{*/
130// ---------------------------------------------------------------------
131/* */
132int ShowHelp()
133{
5b28c804
OS
134 ioprintf(cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION,
135 COMMON_ARCH,__DATE__,__TIME__);
04aa15a8 136 if (_config->FindB("version") == true)
b2e465d6
AL
137 return 0;
138
139 cout <<
140 "Usage: apt-cdrom [options] command\n"
141 "\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"
144 "and /etc/fstab.\n"
145 "\n"
146 "Commands:\n"
147 " add - Add a CDROM\n"
148 " ident - Report the identity of a CDROM\n"
149 "\n"
150 "Options:\n"
151 " -h This help text\n"
152 " -d CD-ROM mount point\n"
153 " -r Rename a recognized CD-ROM\n"
154 " -m No mounting\n"
155 " -f Fast mode, don't check package files\n"
156 " -a Thorough scan mode\n"
157 " -c=? Read this configuration file\n"
a2884e32 158 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
b2e465d6
AL
159 "See fstab(5)\n";
160 return 0;
83d89a9f
AL
161}
162 /*}}}*/
92fcbfc1 163int main(int argc,const char *argv[]) /*{{{*/
83d89a9f
AL
164{
165 CommandLine::Args Args[] = {
166 {'h',"help","help",0},
04aa15a8 167 {'v',"version","version",0},
83d89a9f
AL
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},
c60d151b 172 {'n',"just-print","APT::CDROM::NoAct",0},
18444708 173 {'n',"recon","APT::CDROM::NoAct",0},
c60d151b
AL
174 {'n',"no-act","APT::CDROM::NoAct",0},
175 {'a',"thorough","APT::CDROM::Thorough",0},
83d89a9f
AL
176 {'c',"config-file",0,CommandLine::ConfigFile},
177 {'o',"option",0,CommandLine::ArbItem},
178 {0,0,0,0}};
179 CommandLine::Dispatch Cmds[] = {
180 {"add",&DoAdd},
b2e465d6 181 {"ident",&DoIdent},
83d89a9f 182 {0,0}};
67111687
AL
183
184 // Set up gettext support
185 setlocale(LC_ALL,"");
186 textdomain(PACKAGE);
187
83d89a9f
AL
188 // Parse the command line and initialize the package library
189 CommandLine CmdL(Args,_config);
b2e465d6
AL
190 if (pkgInitConfig(*_config) == false ||
191 CmdL.Parse(argc,argv) == false ||
192 pkgInitSystem(*_config,_system) == false)
83d89a9f
AL
193 {
194 _error->DumpErrors();
195 return 100;
196 }
197
198 // See if the help should be shown
5633a7c2 199 if (_config->FindB("help") == true || _config->FindB("version") == true ||
83d89a9f
AL
200 CmdL.FileSize() == 0)
201 return ShowHelp();
a9a5908d
AL
202
203 // Deal with stdout not being a tty
a3f6ea20 204 if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
a9a5908d 205 _config->Set("quiet","1");
83d89a9f
AL
206
207 // Match the operation
208 CmdL.DispatchArg(Cmds);
209
210 // Print any errors or warnings found during parsing
211 if (_error->empty() == false)
212 {
213 bool Errors = _error->PendingError();
214 _error->DumpErrors();
215 return Errors == true?100:0;
216 }
217
218 return 0;
219}
92fcbfc1 220 /*}}}*/