commit 459dd0f32ea9e9aa6e00b15472a0aa1a1aee9c5f Author: Johannes 'josch' Schauer Date: Sat Dec 24 08:57:31 2016 +0100 initial commit diff --git a/apt-satisfy b/apt-satisfy new file mode 100755 index 0000000..f9f307e --- /dev/null +++ b/apt-satisfy @@ -0,0 +1,64 @@ +#!/bin/sh + +set -eu + +depends=$@ + +edspfile=$(mktemp) +solution=$(mktemp) + +trap "rm -r \"$edspfile\" \"$solution\"" EXIT + +# simulate installation of a random package - we choose apt because that has to exist +# +# we expect the dump solver to fail with exit 100 +APT_EDSP_DUMP_FILENAME="$edspfile" apt-get --simulate install --solver dump apt >/dev/null 2>&1 && [ $? -eq 100 ] + +request=$(grep-dctrl -F Request '' -s Request -n "$edspfile") +architecture=$(grep-dctrl -F Request '' -s Architecture -n "$edspfile") +architectures=$(grep-dctrl -F Request '' -s Architectures -n "$edspfile") + +# generate the APT-ID of the dummy package from the largest id plus one +newid=$(grep-dctrl -F Package '' -s APT-ID -n "$edspfile" | sort -n | tail -1) +newid=$((newid+1)) + +# Replace the EDSP header and add a dummy package at the top +# +# We pass some custom options to /usr/lib/apt/solvers/apt because while it +# still needs access to the system's apt config, the presence of some settings +# will let it error out. +{ + cat << END +Request: $request +Architecture: $architecture +Architectures: $architectures +Install: apt-satisfy-dummy:$architecture + +Package: apt-satisfy-dummy +Architecture: $architecture +Version: 1 +APT-ID: $newid +Depends: $depends +APT-Pin: 990 + +END + grep-dctrl -F Package '' "$edspfile"; +} | /usr/lib/apt/solvers/apt -o APT::Default-Release="" > "$solution" + +# FIXME: instead of using grep and cat we want to use grep-dctrl but +# unfortunately the EDSP that /usr/lib/apt/solvers/apt outputs is not valid +# deb822 +if grep Error: "$solution"; then + cat "$solution" + exit +fi + +selector=$(grep-dctrl -F Install '' -n -s Install "$solution" | paste -s -d"|") + +install=$(grep-dctrl --eregex -F APT-ID "^($selector)$" -n -s Package,Architecture,Version "$edspfile" \ + | paste -sd ":= " ) +echo apt install $install + +auto=$(grep-dctrl --eregex -F APT-ID "^($selector)$" -n -s Package,Architecture "$edspfile" \ + | paste -sd ": " ) +echo apt-mark auto $auto