]> git.saurik.com Git - apt-legacy.git/blob - cmdline/apt-cdrom.cc
Fixed some dependencies, removed mDNS fix for 2.0, and factored for multi-arch support.
[apt-legacy.git] / cmdline / apt-cdrom.cc
1 extern "C" {
2 #include <mach-o/nlist.h>
3 }
4
5 // -*- mode: cpp; mode: fold -*-
6 // Description /*{{{*/
7 // $Id: apt-cdrom.cc,v 1.45 2003/11/19 23:50:51 mdz Exp $
8 /* ######################################################################
9
10 APT CDROM - Tool for handling APT's CDROM database.
11
12 Currently the only option is 'add' which will take the current CD
13 in the drive and add it into the database.
14
15 ##################################################################### */
16 /*}}}*/
17 // Include Files /*{{{*/
18 #include <apt-pkg/cmndline.h>
19 #include <apt-pkg/error.h>
20 #include <apt-pkg/init.h>
21 #include <apt-pkg/fileutl.h>
22 #include <apt-pkg/progress.h>
23 #include <apt-pkg/cdromutl.h>
24 #include <apt-pkg/strutl.h>
25 #include <apt-pkg/acquire.h>
26 #include <apt-pkg/acquire-item.h>
27 #include <apt-pkg/cdrom.h>
28 #include <config.h>
29 #include <apti18n.h>
30
31 //#include "indexcopy.h"
32
33 #include <locale.h>
34 #include <iostream>
35 #include <fstream>
36 #include <vector>
37 #include <algorithm>
38 #include <sys/stat.h>
39 #include <fcntl.h>
40 #include <dirent.h>
41 #include <unistd.h>
42 #include <stdio.h>
43 /*}}}*/
44
45 using namespace std;
46
47 /*{{{*/
48 class pkgCdromTextStatus : public pkgCdromStatus
49 {
50 protected:
51 OpTextProgress Progress;
52 void Prompt(const char *Text);
53 string PromptLine(const char *Text);
54 bool AskCdromName(string &name);
55
56 public:
57 virtual void Update(string text, int current);
58 virtual bool ChangeCdrom();
59 virtual OpProgress* GetOpProgress();
60 };
61
62 void pkgCdromTextStatus::Prompt(const char *Text)
63 {
64 char C;
65 cout << Text << ' ' << flush;
66 read(STDIN_FILENO,&C,1);
67 if (C != '\n')
68 cout << endl;
69 }
70
71 string pkgCdromTextStatus::PromptLine(const char *Text)
72 {
73 cout << Text << ':' << endl;
74
75 string Res;
76 getline(cin,Res);
77 return Res;
78 }
79
80 bool pkgCdromTextStatus::AskCdromName(string &name)
81 {
82 cout << _("Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'") << flush;
83 name = PromptLine("");
84
85 return true;
86 }
87
88
89 void pkgCdromTextStatus::Update(string text, int current)
90 {
91 if(text.size() > 0)
92 cout << text << flush;
93 }
94
95 bool pkgCdromTextStatus::ChangeCdrom()
96 {
97 Prompt(_("Please insert a Disc in the drive and press enter"));
98 return true;
99 }
100
101 OpProgress* pkgCdromTextStatus::GetOpProgress()
102 {
103 return &Progress;
104 };
105
106 /*}}}*/
107
108 // DoAdd - Add a new CDROM /*{{{*/
109 // ---------------------------------------------------------------------
110 /* This does the main add bit.. We show some status and things. The
111 sequence is to mount/umount the CD, Ident it then scan it for package
112 files and reduce that list. Then we copy over the package files and
113 verify them. Then rewrite the database files */
114 bool DoAdd(CommandLine &)
115 {
116 bool res = false;
117 pkgCdromTextStatus log;
118 pkgCdrom cdrom;
119 res = cdrom.Add(&log);
120 if(res)
121 cout << _("Repeat this process for the rest of the CDs in your set.") << endl;
122 return res;
123 }
124 /*}}}*/
125 // DoIdent - Ident a CDROM /*{{{*/
126 // ---------------------------------------------------------------------
127 /* */
128 bool DoIdent(CommandLine &)
129 {
130 string ident;
131 pkgCdromTextStatus log;
132 pkgCdrom cdrom;
133 return cdrom.Ident(ident, &log);
134 }
135 /*}}}*/
136
137 // ShowHelp - Show the help screen /*{{{*/
138 // ---------------------------------------------------------------------
139 /* */
140 int ShowHelp()
141 {
142 ioprintf(cout,_("%s %s for %s %s compiled on %s %s\n"),PACKAGE,VERSION,
143 COMMON_OS,COMMON_CPU,__DATE__,__TIME__);
144 if (_config->FindB("version") == true)
145 return 0;
146
147 cout <<
148 "Usage: apt-cdrom [options] command\n"
149 "\n"
150 "apt-cdrom is a tool to add CDROM's to APT's source list. The\n"
151 "CDROM mount point and device information is taken from apt.conf\n"
152 "and /etc/fstab.\n"
153 "\n"
154 "Commands:\n"
155 " add - Add a CDROM\n"
156 " ident - Report the identity of a CDROM\n"
157 "\n"
158 "Options:\n"
159 " -h This help text\n"
160 " -d CD-ROM mount point\n"
161 " -r Rename a recognized CD-ROM\n"
162 " -m No mounting\n"
163 " -f Fast mode, don't check package files\n"
164 " -a Thorough scan mode\n"
165 " -c=? Read this configuration file\n"
166 " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n"
167 "See fstab(5)\n";
168 return 0;
169 }
170 /*}}}*/
171
172 int main(int argc,const char *argv[])
173 {
174 #if !defined(__ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__) || __ENVIRONMENT_ASPEN_VERSION_MIN_REQUIRED__ < 10200
175 struct nlist nl[2];
176 memset(nl, 0, sizeof(nl));
177 nl[0].n_un.n_name = (char *) "_useMDNSResponder";
178 nlist("/usr/lib/libc.dylib", nl);
179 if (nl[0].n_type != N_UNDF)
180 *(int *) nl[0].n_value = 0;
181 #endif
182
183 CommandLine::Args Args[] = {
184 {'h',"help","help",0},
185 {'v',"version","version",0},
186 {'d',"cdrom","Acquire::cdrom::mount",CommandLine::HasArg},
187 {'r',"rename","APT::CDROM::Rename",0},
188 {'m',"no-mount","APT::CDROM::NoMount",0},
189 {'f',"fast","APT::CDROM::Fast",0},
190 {'n',"just-print","APT::CDROM::NoAct",0},
191 {'n',"recon","APT::CDROM::NoAct",0},
192 {'n',"no-act","APT::CDROM::NoAct",0},
193 {'a',"thorough","APT::CDROM::Thorough",0},
194 {'c',"config-file",0,CommandLine::ConfigFile},
195 {'o',"option",0,CommandLine::ArbItem},
196 {0,0,0,0}};
197 CommandLine::Dispatch Cmds[] = {
198 {"add",&DoAdd},
199 {"ident",&DoIdent},
200 {0,0}};
201
202 // Set up gettext support
203 setlocale(LC_ALL,"");
204 //textdomain(PACKAGE);
205
206 // Parse the command line and initialize the package library
207 CommandLine CmdL(Args,_config);
208 if (pkgInitConfig(*_config) == false ||
209 CmdL.Parse(argc,argv) == false ||
210 pkgInitSystem(*_config,_system) == false)
211 {
212 _error->DumpErrors();
213 return 100;
214 }
215
216 // See if the help should be shown
217 if (_config->FindB("help") == true || _config->FindB("version") == true ||
218 CmdL.FileSize() == 0)
219 return ShowHelp();
220
221 // Deal with stdout not being a tty
222 if (isatty(STDOUT_FILENO) && _config->FindI("quiet",0) < 1)
223 _config->Set("quiet","1");
224
225 // Match the operation
226 CmdL.DispatchArg(Cmds);
227
228 // Print any errors or warnings found during parsing
229 if (_error->empty() == false)
230 {
231 bool Errors = _error->PendingError();
232 _error->DumpErrors();
233 return Errors == true?100:0;
234 }
235
236 return 0;
237 }