Monday, January 10, 2011

How to fix a dpkg broken by the Brother MFC-7340 deb driver

I'm getting an apt-get error that says

E: The package brmfc7340lpr needs to be reinstalled, but I can't find an archive for it.

(the brmfc7340lpr is a printer driver) its a local deb file, doing an dpkg or apt-get purge doesn't work, neither does apt-get install -f

How do I reinstall a package from a local deb file?

P.S.

box-name% sudo apt-get upgrade
[sudo] password for username: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: The package brmfc7340lpr needs to be reinstalled, but I can't find an archive for it.
box-name% sudo apt-get purge brmfc7340lpr
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: The package brmfc7340lpr needs to be reinstalled, but I can't find an archive for it.
box-name% sudo dpkg --purge brmfc7340lpr 
dpkg: error processing brmfc7340lpr (--purge):
 Package is in a very bad inconsistent state - you should
 reinstall it before attempting a removal.
Errors were encountered while processing:
 brmfc7340lpr
box-name% sudo dpkg --install brmfc7340lpr-2.0.2-1.i386.deb
Selecting previously deselected package brmfc7340lpr.
(Reading database ... 725204 files and directories currently installed.)
Preparing to replace brmfc7340lpr 2.0.2-1 (using .../brmfc7340lpr-2.0.2-1.i386.deb) ...
Unpacking replacement brmfc7340lpr ...
start: Unknown job: lpd
dpkg: warning: subprocess old post-removal script returned error exit status 1
dpkg - trying script from the new package instead ...
start: Unknown job: lpd
dpkg: error processing brmfc7340lpr-2.0.2-1.i386.deb (--install):
 subprocess new post-removal script returned error exit status 1
start: Unknown job: lpd
dpkg: error while cleaning up:
 subprocess new post-removal script returned error exit status 1
Errors were encountered while processing:
brmfc7340lpr-2.0.2-1.i386.deb
box-name% sudo apt-get install -f                                     
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: The package brmfc7340lpr needs to be reinstalled, but I can't find an archive for it.
box-name% 
  • You can always (re)install a package using dpkg:

    dpkg --install local-file.deb
    

    In order to make a "clean room" installation, you can first purge the package and then install it again:

    dpkg --purge brmfc7340lpr
    dpkg --install brmfc7340lpr*.deb
    

    You might need to add option --force-depends during purge, if some other package depends on brmfc7340lpr.

    Update: Based on the transcript you posted, it seems that the brmfc7340lpr package cannot be (re)installed because its post-removal script is erroring out.

    Those files are stored in directory /var/lib/dpkg/info; for each package X, there can be any one of these scripts:

    • X.postinst run after the package has been installed, e.g., to start services provided by the package.

    • X.prerm run before removing/purging the package, e.g., to ensure that daemons provided by the package are stopped.

    • X.postrm run after the package has been removed, e.g., to signal any service optionally using the package that it is no longer available. (For instance, a printer driver package might want to signal cpus/lpr to remove printers depending on that specific driver.)

    Now, this brmfc7340lpr package seems to try to (re)start the lpd printer daemon upon removal, which won't work as Ubuntu uses CUPS instead: you should definitely look for a CUPS-compatible printer driver -- see the link in Jorge Castro's answer. (I think this is a bug in the package, as it should not restart the lpd service unconditionally, but just reload it if it's already running.)

    The best option to go forward comes from this launchpad answer:

    ln -s /etc/init.d/cpus /etc/init.d/lpd
    

    This will effectively (re)start CUPS when the lpd service is instead searched for.

    Otherwise, I only see two options, both rather unpleasant:

    1. Either edit the /var/lib/dpkg/info/brmfc7340lpr.postrm script, and comment out the line that is invoking /etc/init.d/lpd start (or restart or stop), (e.g., just replace it with /bin/true). Another option is to just place exit 0 as the first non-comment line in the script. This would be my favorite, but requires a bit of confidence with editing shell scripts.

    2. Install lpr, purge the brmfc6340lpr package, purge lpr: this requires a bit of attention as lpr conflicts with the default Ubuntu printer spooling system CUPS:

      a. sudo aptitude install lpr (this will remove cups-bsd and ubuntu-desktop as a side effect)

      b. sudo aptitude purge brmfc7340lpr lpr (should work now)

      c. sudo aptitude install cups-bsd ubuntu-desktop (restore system to its original state)

    Roman A. Taycher : dpkg --install doesn't work
    Riccardo Murri : @Roman What error message do you get? Does `--purge` first and then `--install` work?
    Riccardo Murri : @Roman updated with some specific instructions that might help. I agree with andrewsomething's comment that this no longer looks a generic question and should be renamed.
    Roman A. Taycher : I ended up renaming lpd to nlpdn temporarily to install it.
  • Riccardo's solution should work, I am guessing the problem lies here:

    start: Unknown job: lpd

    Guess 1: It looks like the deb is trying to restart a service which isn't running and erroring out. Try installing the lpr package from the repositories and then installing the deb and see if that works.

    Guess 2: It sounds like you're trying to install a deb from a website for a brother 7340 printer: This page might be a good starting point if you want to split it off into another question.

    Roman A. Taycher : /etc/init.d/lpd start start: Unknown job: lpd
  • The problem here appears to be that the package has managed to get itself half-installed, but now its maintainer scripts are all faililng (due to being unable to start the lpd service).

    You should be able to resolve this by editing the /var/lib/dpkg/info/brmfc7340lpr.postrm file and commenting out (by adding # to the start of the line) the line which is trying to start lpd (or just comment out everything). You should then be able to run dpkg --configure -a to get the package properly installed before you can remove it.

    You might need to edit more of the packages maintainer scripts in order to remove the package - they'll all be in /var/lib/dpkg/info/, and they'll be named something like brmfc7340lpr.X where X can be one of preinst, postinst, prerm, postrm.

    This is an example of the sort of havoc a poorly written package can wreak.

    From RAOF

0 comments:

Post a Comment