Skip to content

Instantly share code, notes, and snippets.

@hasanbayatme
Last active January 10, 2021 20:14
Show Gist options
  • Save hasanbayatme/8eb920165777399cfd684d8d4227a6e2 to your computer and use it in GitHub Desktop.
Save hasanbayatme/8eb920165777399cfd684d8d4227a6e2 to your computer and use it in GitHub Desktop.
Fixes Ubuntu broken packages. Accepts an argument to what action to apply to broken packages. you can use upgrade and install commands, default action is remove.

Fix Broken

This script allows you to fix the broken ubuntu packages.

Most of the time the broken packages will be fixed by removing them.

Getting Started Documentation License

Getting Started

First off, download the script:

wget --no-cache https://gist.github.com/EmpireWorld/8eb920165777399cfd684d8d4227a6e2/raw/fix-broken.sh

And then try one of the following methods: (The default method is remove)

  • Fix by Removing: (Recommended) (Default)
./fix-broken.sh remove
  • Fix by Installing:
./fix-broken.sh install
  • Fix by Updating:
./fix-broken.sh update

Or trying to use the typical script:

./fix-broken.sh

Documentation

Here is small documentation about the usage of fix-broken script:

./fix-broken.sh [install|remove|update] [apt|apt-get]

License

MIT @ Hasan Bayat

Made with ❤️ by Hasan Bayat

#!/bin/bash
########################
# Written by Hasan Bayat
# Fixes the broken packages by taking the required action.
# License MIT @ Hasan Bayat
########################
apt='apt'
action='remove'
if [[ -n "$1" ]]; then
action=$1
fi
if ! type "apt" > /dev/null; then
apt='apt-get'
fi
baseCmd="sudo $apt $action -y"
while read line; do
cmd="$baseCmd $line"
eval $cmd
done < <(grep -oP 'Broken \K.*?(?=:)' /var/log/dist-upgrade/apt.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment