Handle suite mismatch, don't download packages if update failed

Signed-off-by: Tanya Degurechaff <34323200+TanyaEleventhGoddess@users.noreply.github.com>
This commit is contained in:
Tanya Degurechaff 2020-07-13 16:11:51 +02:00
parent 92d4e109f1
commit 862a6098f0
2 changed files with 57 additions and 9 deletions

View File

@ -67,6 +67,16 @@ find_interpreter()
return 1
}
release_info() {
if wget "${1}/dists/${release}/Release" -O /dev/null --quiet 2> /dev/null; then
local release_file=$(wget "${1}/dists/${release}/Release" -O - --quiet 2> /dev/null)
distro_suite=${release_file#*Suite: }
distro_suite=${distro_suite%%$'\n'*}
return 0
fi
return 1
}
configure_debian()
{
rootfs=$1
@ -237,14 +247,26 @@ EOF
fi
}
apt_update_packages(){
local apt_update_args="update"
local lpath="${rootfs}/var/lib/apt/lists/$(echo "$MIRROR" | sed 's#.*://##;s#/#_#g')_dists_${release}_Release"
if [ -f "$lpath" ] && [ ! -z "$distro_suite" ]; then
local lsuite=$(cat "$lpath" | grep 'Suite:')
[ "${lsuite#Suite: }" != "$distro_suite" ] && apt_update_args="--allow-releaseinfo-change $apt_update_args"
fi
chroot "${rootfs}" apt-get $apt_update_args
return $?
}
install_packages()
{
local rootfs="$1"; shift
local packages="$*"
chroot "${rootfs}" apt-get update
if [ -n "${packages}" ]; then
if [ -n "${packages}" ] && apt_update_packages; then
chroot "${rootfs}" apt-get install --force-yes -y --no-install-recommends ${packages}
elif [ -n "${packages}" ]; then
echo "Apt update failed, not downloading packages"
fi
}
@ -811,10 +833,12 @@ fi
release=${release:-stable}
permanent_releases=('stable' 'testing' 'sid' 'unstable')
if [[ ! "${permanent_releases[*]}" =~ (^|[^[:alpha:]])$release([^[:alpha:]]|$) ]]; then
if ! wget "${MIRROR}/dists/${release}/Release" -O /dev/null 2> /dev/null; then
if ! release_info "${MIRROR}"; then
echo "Invalid release ${release} (not found in mirror)"
exit 1
fi
else
release_info "${MIRROR}"
fi
# detect rootfs

View File

@ -67,6 +67,16 @@ find_interpreter()
return 1
}
release_info() {
if wget "${1}/dists/${release}/Release" -O /dev/null --quiet 2> /dev/null; then
local release_file=$(wget "${1}/dists/${release}/Release" -O - --quiet 2> /dev/null)
distro_suite=${release_file#*Suite: }
distro_suite=${distro_suite%%$'\n'*}
return 0
fi
return 1
}
configure_devuan()
{
rootfs=$1
@ -240,14 +250,26 @@ EOF
fi
}
apt_update_packages(){
local apt_update_args="update"
local lpath="${rootfs}/var/lib/apt/lists/$(echo "$MIRROR" | sed 's#.*://##;s#/#_#g')_dists_${release}_Release"
if [ -f "$lpath" ] && [ ! -z "$distro_suite" ]; then
local lsuite=$(cat "$lpath" | grep 'Suite:')
[ "${lsuite#Suite: }" != "$distro_suite" ] && apt_update_args="--allow-releaseinfo-change $apt_update_args"
fi
chroot "${rootfs}" apt-get $apt_update_args
return $?
}
install_packages()
{
local rootfs="$1"; shift
local packages="$*"
chroot "${rootfs}" apt-get update
if [ -n "${packages}" ]; then
if [ -n "${packages}" ] && apt_update_packages; then
chroot "${rootfs}" apt-get install --force-yes -y --no-install-recommends ${packages}
elif [ -n "${packages}" ]; then
echo "Apt update failed, not downloading packages"
fi
}
@ -755,12 +777,14 @@ if [ -n "$authkey" ]; then
fi
release=${release:-stable}
permanent_releases=('stable' 'testing' 'ceres' 'unstable')
permanent_releases=('stable' 'testing' 'sid' 'unstable')
if [[ ! "${permanent_releases[*]}" =~ (^|[^[:alpha:]])$release([^[:alpha:]]|$) ]]; then
if ! wget "${MIRROR}/dists/${release}/Release" -O /dev/null 2> /dev/null; then
if ! release_info "${MIRROR}"; then
echo "Invalid release ${release} (not found in mirror)"
exit 1
fi
else
release_info "${MIRROR}"
fi
# detect rootfs