]>
git.saurik.com Git - apt.git/blob - cmdline/apt-helper.cc
1 // -*- mode: cpp; mode: fold -*-
3 /* #####################################################################
4 apt-helper - cmdline helpers
5 ##################################################################### */
7 // Include Files /*{{{*/
10 #include <apt-pkg/cmndline.h>
11 #include <apt-pkg/error.h>
12 #include <apt-pkg/init.h>
13 #include <apt-pkg/strutl.h>
14 #include <apt-pkg/pkgsystem.h>
15 #include <apt-pkg/fileutl.h>
16 #include <apt-pkg/acquire.h>
17 #include <apt-pkg/acquire-item.h>
19 #include <apt-private/acqprogress.h>
20 #include <apt-private/private-output.h>
21 #include <apt-private/private-cmndline.h>
25 #include <sys/types.h>
36 bool DoDownloadFile(CommandLine
&CmdL
)
38 if (CmdL
.FileSize() <= 2)
39 return _error
->Error(_("Must specify at least one pair url/filename"));
43 AcqTextStatus
Stat(ScreenWidth
, _config
->FindI("quiet",0));
45 std::string download_uri
= CmdL
.FileList
[1];
46 std::string targetfile
= CmdL
.FileList
[2];
48 if (CmdL
.FileSize() > 3)
49 hash
= HashString(CmdL
.FileList
[3]);
50 new pkgAcqFile(&Fetcher
, download_uri
, "", 0, "desc", "short-desc",
51 "dest-dir-ignored", targetfile
);
53 if (!FileExists(targetfile
))
55 _error
->Error(_("Download Failed"));
58 if(hash
.empty() == false)
60 if(hash
.VerifyFile(targetfile
) == false)
62 _error
->Error(_("HashSum Failed"));
63 Rename(targetfile
, targetfile
+".failed");
70 bool ShowHelp(CommandLine
&CmdL
)
72 ioprintf(cout
,_("%s %s for %s compiled on %s %s\n"),PACKAGE
,PACKAGE_VERSION
,
73 COMMON_ARCH
,__DATE__
,__TIME__
);
75 if (_config
->FindB("version") == true)
79 _("Usage: apt-helper [options] command\n"
80 " apt-helper [options] download-file uri target-path\n"
82 "apt-helper is a internal helper for apt\n"
85 " download-file - download the given uri to the target-path\n"
87 " This APT helper has Super Meep Powers.\n");
92 int main(int argc
,const char *argv
[]) /*{{{*/
94 CommandLine::Dispatch Cmds
[] = {{"help",&ShowHelp
},
95 {"download-file", &DoDownloadFile
},
98 std::vector
<CommandLine::Args
> Args
= getCommandArgs(
99 "apt-download", CommandLine::GetCommand(Cmds
, argc
, argv
));
101 // Set up gettext support
102 setlocale(LC_ALL
,"");
105 // Parse the command line and initialize the package library
106 CommandLine
CmdL(Args
.data(),_config
);
107 if (pkgInitConfig(*_config
) == false ||
108 CmdL
.Parse(argc
,argv
) == false ||
109 pkgInitSystem(*_config
,_system
) == false)
111 if (_config
->FindB("version") == true)
113 _error
->DumpErrors();
117 // See if the help should be shown
118 if (_config
->FindB("help") == true ||
119 _config
->FindB("version") == true ||
120 CmdL
.FileSize() == 0)
128 // Match the operation
129 CmdL
.DispatchArg(Cmds
);
131 // Print any errors or warnings found during parsing
132 bool const Errors
= _error
->PendingError();
133 if (_config
->FindI("quiet",0) > 0)
134 _error
->DumpErrors();
136 _error
->DumpErrors(GlobalError::DEBUG
);
137 return Errors
== true ? 100 : 0;