patch for apt-get to support execution of programs just before and after update and install
Hello,
I've written a small patch for apt-get to allow execution of programs just
before and after 'update' and 'install', ie: just before and after it needs to
connect to the internet. This allows the user eg to automatically call pon and
poff; therefore he needs to add the following lines to apt.conf:
APT::Get
{
Pre-Update "/usr/bin/pon";
Post-Update "/usr/bin/poff";
Pre-Download "/usr/bin/pon";
Post-Download "/usr/bin/poff";
}
(Though, I use it not to connect to the internet, but to get a sources.list file
from a server, just before apt downloads packagelists.)
There is a little bug however: if apt doesn't need to download, since all
packages are in it's cache, the Pre-Download and Post-Download commands are
still executed.
This feature was inspired by the DPkg::Pre-Install-Pkgs feature.
I've created the diff with:
$ diff -u apt-get.cc apt-get.cc.with_pre_post_update_pre_post_download_patch >pre_post_update_pre_post_download-diff
You can apply it with:
$ patch <pre_post_update_pre_post_download-diff
If you have any questions or remarks about this, please send me a message (you
have to CC to me, since I'm not on this list).
cheers,
Admar Schoonen
--- apt-get.cc Mon Sep 24 00:08:09 2001
+++ apt-get.cc.with_pre_post_update_pre_post_download_patch Sun Sep 23 23:51:29 2001
@@ -795,6 +795,11 @@
if (_config->FindB("APT::Get::Download-Only",false) == true)
_system->UnLock();
+ // Execute pre-download
+ string PreDownloadCmnd;
+ PreDownloadCmnd=_config->Find("APT::Get::Pre-Download");
+ if (PreDownloadCmnd.c_str()!=NULL)
+ system(PreDownloadCmnd.c_str());
// Run it
while (1)
{
@@ -823,6 +828,12 @@
if (Fetcher.Run() == pkgAcquire::Failed)
return false;
+ // Execute post-download
+ string PostDownloadCmnd;
+ PostDownloadCmnd=_config->Find("APT::Get::Post-Download");
+ if (PostDownloadCmnd.c_str()!=NULL)
+ system(PostDownloadCmnd.c_str());
+
// Print out errors
bool Failed = false;
for (pkgAcquire::ItemIterator I = Fetcher.ItemsBegin(); I != Fetcher.ItemsEnd(); I++)
@@ -1154,6 +1165,12 @@
/* */
bool DoUpdate(CommandLine &CmdL)
{
+ // Execute pre-update
+ string PreUpdateCmnd;
+ PreUpdateCmnd=_config->Find("APT::Get::Pre-Update");
+ if (PreUpdateCmnd.c_str()!=NULL)
+ system(PreUpdateCmnd.c_str());
+
if (CmdL.FileSize() != 1)
return _error->Error(_("The update command takes no arguments"));
@@ -1212,6 +1229,11 @@
if (Failed == true)
return _error->Error(_("Some index files failed to download, they have been ignored, or old ones used instead."));
+ // Execute post-update
+ string PostUpdateCmnd;
+ PostUpdateCmnd=_config->Find("APT::Get::Post-Update");
+ if (PostUpdateCmnd.c_str()!=NULL)
+ system(PostUpdateCmnd.c_str());
return true;
}
/*}}}*/
Reply to: