]> git.saurik.com Git - apt-legacy.git/blob - cmdline/apt-cdrom.cc
Added many more packages (gnupg and friends), fixed repository signing, ported vim...
[apt-legacy.git] / cmdline / apt-cdrom.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: apt-cdrom.cc,v 1.45 2003/11/19 23:50:51 mdz Exp $
4 /* ######################################################################
5
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.
10
11 ##################################################################### */
12 /*}}}*/
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>
24 #include <config.h>
25 #include <apti18n.h>
26
27 //#include "indexcopy.h"
28
29 #include <locale.h>
30 #include <iostream>
31 #include <fstream>
32 #include <vector>
33 #include <algorithm>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <dirent.h>
37 #include <unistd.h>
38 #include <stdio.h>
39 /*}}}*/
40
41 using namespace std;
42
43 /*{{{*/
44 class pkgCdromTextStatus : public pkgCdromStatus
45 {
46 protected:
47 OpTextProgress Progress;
48 void Prompt(const char *Text);
49 string PromptLine(const char *Text);
50 bool AskCdromName(string &name);
51
52 public:
53 virtual void Update(string text, int current);
54 virtual bool ChangeCdrom();
55 virtual OpProgress* GetOpProgress();
56 };
57
58 void pkgCdromTextStatus::Prompt(const char *Text)
59 {
60 char C;
61 cout << Text << ' ' << flush;
62 read(STDIN_FILENO,&C,1);
63 if (C != '\n')
64 cout << endl;
65 }
66
67 string pkgCdromTextStatus::PromptLine(const char *Text)
68 {
69 cout << Text << ':' << endl;
70
71 string Res;
72 getline(cin,Res);
73 return Res;
74 }
75
76 bool pkgCdromTextStatus::AskCdromName(string &name)
77 {
78 cout << _("Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'") << flush;
79 name = PromptLine("");
80
81 return true;
82 }
83
84
85 void pkgCdromTextStatus::Update(string text, int current)
86 {
87 if(text.size() > 0)
88 cout << text << flush;
89 }
90
91 bool pkgCdromTextStatus::ChangeCdrom()
92 {
93 Prompt(_("Please insert a Disc in the drive and press enter"));
94 return true;
95 }
96
97 OpProgress* pkgCdromTextStatus::GetOpProgress()
98 {
99 return &Progress;
100 };
101
102 /*}}}*/
103
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 &)
111 {
112 bool res = false;
113 pkgCdromTextStatus log;
114 pkgCdrom cdrom;
115 res = cdrom.Add(&log);
116 if(res)
117 cout << _("Repeat this process for the rest of the CDs in your set.") << endl;
118 return res;
119 }
120 /*}}}*/
121 // DoIdent - Ident a CDROM /*{{{*/
122 // ---------------------------------------------------------------------
123 /* */
124 bool DoIdent(CommandLine &)
125 {
126 string ident;
127 pkgCdromTextStatus log;
128 pkgCdrom cdrom;
129 return cdrom.Ident(ident, &log);
130 }
131 /*}}}*/
132
133 // ShowHelp - Show the help screen /*{{{*/
134 // ---------------------------------------------------------------------
135 /* */
136 int ShowHelp()
137 {
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)
141 return 0;
142
143 cout <<
144 "Usage: apt-cdrom [options] command\n"
145 "\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"
148 "and /etc/fstab.\n"
149 "\n"
150 "Commands:\n"
151 " add - Add a CDROM\n"
152 " ident - Report the identity of a CDROM\n"
153 "\n"
154 "Options:\n"
155 " -h This help text\n"
156 " -d CD-ROM mount point\n"
157 " -r Rename a recognized CD-ROM\n"
158 " -m No mounting\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"
163 "See fstab(5)\n";
164 return 0;
165 }
166 /*}}}*/
167
168 int main_(int argc,const char *argv[]);
169 int main(int argc,const char *argv[]) {
170 _exit(main_(argc, argv));
171 }
172 int main_(int argc,const char *argv[])
173 {
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},
187 {0,0,0,0}};
188 CommandLine::Dispatch Cmds[] = {
189 {"add",&DoAdd},
190 {"ident",&DoIdent},
191 {0,0}};
192
193 // Set up gettext support
194 setlocale(LC_ALL,"");
195 //textdomain(PACKAGE);
196
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)
202 {
203 _error->DumpErrors();
204 return 100;
205 }
206
207 // See if the help should be shown
208 if (_config->FindB("help") == true || _config->FindB("version") == true ||
209 CmdL.FileSize() == 0)
210 return ShowHelp();
211
212 // Deal with stdout not being a tty
213 if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
214 _config->Set("quiet","1");
215
216 // Match the operation
217 CmdL.DispatchArg(Cmds);
218
219 // Print any errors or warnings found during parsing
220 if (_error->empty() == false)
221 {
222 bool Errors = _error->PendingError();
223 _error->DumpErrors();
224 return Errors == true?100:0;
225 }
226
227 return 0;
228 }