[HOW-TO] Debian: Reinstall Packages Dependent By Meta

Post fully complete "how to" guides and tutorials here. This is a great place to get feedback on stuff you might put in the wiki.

Moderators: MattKingUSA, khz

Post Reply
User avatar
GraysonPeddie
Established Member
Posts: 659
Joined: Sun Feb 12, 2012 11:12 pm
Location: Altha, FL
Been thanked: 6 times
Contact:

[HOW-TO] Debian: Reinstall Packages Dependent By Meta

Post by GraysonPeddie »

Applies To
  • Debian
  • Debian-based Linux Distributions, such as:
    • Ubuntu
    • Mint
    • Netrunner
Scenario

You wish to reinstall all packages that are dependent by a meta package.

Problem

If you execute the command:

Code: Select all

sudo apt-get install --reinstall kxstudio-meta-non-free
This will only install a meta package and nothing else.

Expected Result

Apt-Get should install all the dependencies that are part of the meta package.

Solution

Follow the instructions to create and give apt-reinstall-meta an executable permission.
  1. Depending in your desktop environment:
    1. For GNOME/Unity, open gnome-terminal.
    2. For KDE, open up Konsole.
    3. For XFCE including the others, run xterm.
  2. As root, execute the following command into the terminal:

    Code: Select all

    sudo nano /usr/local/bin/apt-reinstall-meta
    Enter your user password when prompted.
  3. Copy the code into nano. In nano, hold Control + Shift and press V.

    Code: Select all

    #!/bin/bash
    
    # Check if the user is in root mode
    if [ "$(id -u)" != "0" ]
    then
        echo "You must be rooted to install packages that are related to a meta package." 2>&1
        exit 1
    fi
    
    # Check to see if the meta package is not given by the user.
    if [ -z "$1" ]
    then
        echo "Example meta package: kubuntu-desktop"
        exit 1
    fi
    
    # Search for packages that is depended by the meta-package
    # and ask the user if s/he wants to reinstall all the packages.
    apt-cache depends $1 | awk -F ":" '{print $2}' | \
    sed '/^$/d' | xargs sudo apt-get \
    install --reinstall --install-recommends
    
    exit 0
    Do Ctrl+O and Ctrl+X to save and exit.
  4. Execute the command to give apt-reinstall-meta an executable permission.

    Code: Select all

    sudo chmod a+x /usr/local/bin/apt-reinstall-meta
  5. You're done. Now execute whatever meta package you want to reinstall. This will reinstall all of the dependent packages. One example is kxstudio-meta-non-free.

    Code: Select all

    sudo apt-reinstall-meta kxstudio-meta-non-free
Remarks

This will check to see if you are running as root, check to be sure that the string is not empty, search for packages that is part of the meta package, and asks if you want to install them.

Credits
--Grayson Peddie

Music Interest: New Age w/ a mix of modern smooth jazz, light techno/trance & downtempo -- something Epcot Future World/Tomorrowland-flavored.
Post Reply