Ok I figured it out. You can close this ticket unless you think others might encounter the same issue.
I must have followed instructions like at https://wiki.aleen42.com/qa/dpkg.html to rename /var/lib/dpkg/info to /var/lib/dpkg/info.bak, and it was choking on the directory because head can't operate on a directory. I moved /var/lib/dpkg/info.bak somewhere else and it fixed the problem.
The post install script /var/lib/dpkg/info/dpkg.postinst contains the following code that will choke if there is a directory in /var/lib/dpkg/info/:
for file in *; do
# Check whether this is a known file we do not want to act on.
case "$file" in
alternatives|\
arch|\
available|available-old|\
cmethopt|methlock|methods|\
diversions|diversions-old|\
info|parts|triggers|updates|\
lock|lock-frontend|\
statoverride|statoverride-old|\
status|status-old)
# Ignore known files just to make sure.
continue
;;
*)
esac
# Check whether the file looks like an alternative state file.
mode="$(head -1 "$file")"
case "$mode" in
auto|manual)
# Looks like a state file, we will handle this one.
echo "Moving misplaced alternative state file $admindir/$file..."
mv "$file" "alternatives/$file"
;;
*)
echo "warning: unknown dpkg database file $admindir/$file is not a misplaced alternative state... leaving as is" 1>&2
continue
;;
esac
done
)
Ok I figured it out. You can close this ticket unless you think others might encounter the same issue.
I must have followed instructions like at https:/ /wiki.aleen42. com/qa/ dpkg.html to rename /var/lib/dpkg/info to /var/lib/ dpkg/info. bak, and it was choking on the directory because head can't operate on a directory. I moved /var/lib/ dpkg/info. bak somewhere else and it fixed the problem.
The post install script /var/lib/ dpkg/info/ dpkg.postinst contains the following code that will choke if there is a directory in /var/lib/ dpkg/info/ :
fixup_misplaced _alternatives( ) ${DPKG_ ADMINDIR: -/var/lib/ dpkg}
(
admindir=
cd "$admindir"
for file in *; do available- old|\ methlock| methods| \ diversions- old|\ parts|triggers| updates| \ lock-frontend| \ e|statoverride- old|\ status- old)
# Check whether this is a known file we do not want to act on.
case "$file" in
alternatives|\
arch|\
available|
cmethopt|
diversions|
info|
lock|
statoverrid
status|
# Ignore known files just to make sure.
continue
;;
*)
esac
# Check whether the file looks like an alternative state file. $file"
mode="$(head -1 "$file")"
case "$mode" in
auto|manual)
# Looks like a state file, we will handle this one.
echo "Moving misplaced alternative state file $admindir/$file..."
mv "$file" "alternatives/
;;
*)
echo "warning: unknown dpkg database file $admindir/$file is not a misplaced alternative state... leaving as is" 1>&2
continue
;;
esac
done
)