Last active
July 12, 2019 22:08
-
-
Save hilbix/c08c0bce5f4e6e61765fc7f53aa8619b to your computer and use it in GitHub Desktop.
Helper to fix broken "apt-get install -f", which might happen when upgrading from i386 to amd64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Public Domain | |
# | |
# If you follow https://wiki.debian.org/CrossGrading you might get stuck | |
# at the "apt-get install -f" step. Either you are doomed, or use this script here. | |
# | |
# Just run it to find out the troublesome :i386 packages. | |
# Then paste those packagenames to the script here to install the amd64 counterpart. | |
# Or press just return to run "apt-get install -f", | |
# which might suddenly kick in and do it's job. | |
# | |
# For this to work "apt-get" must have the right architecture, already. | |
STDOUT() { local e=$?; printf %q "$1"; [ 1 -lt $# ] && printf ' %q' "${@:2}"; printf '\n'; return $e; } | |
STDERR() { STDOUT "$@" >&2; } | |
OOPS() { STDERR OOPS: "$@"; exit 23; } | |
x() { "$@"; } | |
o() { x "$@" || OOPS "err$?:" "$@"; } | |
v() { local -n v="$1"; v="$(o ${@:2})" || OOPS var "$1" failed; } | |
fixer() | |
{ | |
case "$1" in | |
('') STDERR empty package name; return;; | |
(-*|*[^a-z0-9.-]*) STDERR wrong package name "$1"; return;; | |
esac | |
[ -d "$1" ] && STDERR double listed "$1" && return; | |
o mkdir "$1" | |
o cd "$1" | |
o apt-get download "$1" | |
x dpkg -i "$1"*.deb | |
} | |
fix() | |
{ | |
case "$1" in | |
(*..*) OOPS wrong TMP dir "$1";; | |
(/tmp/*) ;; | |
(*) OOPS wrong TMP dir "$1";; | |
esac | |
o cd "$1" | |
for b in "${@:2}" | |
do | |
o cd "$1" | |
fixer "${b%.}" | |
done | |
o rm -rf "$1" | |
} | |
show=: | |
while o cd / | |
$show && x apt-get install -f | |
show=false | |
read -p 'PACKAGE(s): ' -ra pack | |
do | |
[ 0 = "${#pack[@]}" ] && { show=:; continue; } | |
v DIR mktemp -d | |
fix "$DIR" "${pack[@]}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment