summaryrefslogtreecommitdiff
path: root/cmdline
diff options
context:
space:
mode:
Diffstat (limited to 'cmdline')
-rw-r--r--cmdline/apt-get.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc
index 089b64701..cd43e17c7 100644
--- a/cmdline/apt-get.cc
+++ b/cmdline/apt-get.cc
@@ -1496,6 +1496,61 @@ bool DoUpgrade(CommandLine &CmdL)
return InstallPackages(Cache,true);
}
/*}}}*/
+// DoInstallTask - Install task from the command line /*{{{*/
+// ---------------------------------------------------------------------
+/* Install named task */
+bool DoInstallTask(CommandLine &CmdL)
+{
+ const char *start, *end;
+ pkgCache::PkgIterator Pkg;
+
+ CacheFile Cache;
+ if (Cache.OpenForInstall() == false ||
+ Cache.CheckDeps(CmdL.FileSize() != 1) == false)
+ return false;
+
+ // create the records parser
+ pkgRecords Recs(Cache);
+
+ unsigned int ExpectedInst = 0;
+ unsigned int Packages = 0;
+ pkgProblemResolver Fix(Cache);
+ char buf[64*1024];
+
+ for (const char **I = CmdL.FileList + 1; *I != 0; I++)
+ {
+ regex_t Pattern;
+ int Res;
+
+ // build regexp for the task
+ char S[300];
+ snprintf(S, sizeof(S), "^Task:.*%s.*\n", *I);
+ regcomp(&Pattern,S, REG_EXTENDED | REG_NOSUB | REG_NEWLINE);
+
+ for (Pkg = Cache->PkgBegin(); Pkg.end() == false; Pkg++)
+ {
+ pkgCache::VerIterator ver = (*Cache)[Pkg].CandidateVerIter(*Cache);
+ if(ver.end())
+ continue;
+ pkgRecords::Parser &parser = Recs.Lookup(ver.FileList());
+ parser.GetRec(start,end);
+ strncpy(buf, start, end-start);
+ buf[end-start] = 0x0;
+ if (regexec(&Pattern,buf,0,0,0) != 0)
+ continue;
+ TryToInstall(Pkg,Cache,Fix,false,false,ExpectedInst);
+ }
+ }
+
+ // Call the scored problem resolver
+ Fix.InstallProtect();
+ if (Fix.Resolve(true) == false)
+ _error->Discard();
+
+ // prompt for install
+ return InstallPackages(Cache,false,true);
+}
+
// DoInstall - Install packages from the command line /*{{{*/
// ---------------------------------------------------------------------
/* Install named packages */
@@ -2653,6 +2708,7 @@ int main(int argc,const char *argv[])
CommandLine::Dispatch Cmds[] = {{"update",&DoUpdate},
{"upgrade",&DoUpgrade},
{"install",&DoInstall},
+ {"installtask",&DoInstallTask},
{"remove",&DoInstall},
{"autoremove",&DoInstall},
{"dist-upgrade",&DoDistUpgrade},