2018-09-18 09:20:24 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2018-12-28 06:44:54 +00:00
|
|
|
# This script fills either cache.A or cache.B with new content and then
|
|
|
|
# atomically switches the cache symlink from one to the other at the end.
|
|
|
|
# This way, at no point will the cache be in an non-working state, even
|
|
|
|
# when this script got canceled at any point.
|
|
|
|
# Working with two directories also automatically prunes old packages in
|
|
|
|
# the local repository.
|
|
|
|
|
2020-01-05 16:33:37 +00:00
|
|
|
deletecache() {
|
|
|
|
dir="$1"
|
|
|
|
echo "running deletecache $dir">&2
|
|
|
|
if [ ! -e "$dir" ]; then
|
|
|
|
return
|
2019-09-04 13:44:34 +00:00
|
|
|
fi
|
2020-01-05 16:33:37 +00:00
|
|
|
if [ ! -e "$dir/mmdebstrapcache" ]; then
|
|
|
|
echo "$dir cannot be the mmdebstrap cache" >&2
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
# be very careful with removing the old directory
|
2021-08-16 11:11:42 +00:00
|
|
|
for dist in oldstable stable testing unstable; do
|
2020-01-05 16:33:37 +00:00
|
|
|
for variant in minbase buildd -; do
|
|
|
|
if [ -e "$dir/debian-$dist-$variant.tar" ]; then
|
|
|
|
rm "$dir/debian-$dist-$variant.tar"
|
|
|
|
else
|
|
|
|
echo "does not exist: $dir/debian-$dist-$variant.tar" >&2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ -e "$dir/debian/dists/$dist" ]; then
|
|
|
|
rm --one-file-system --recursive "$dir/debian/dists/$dist"
|
|
|
|
else
|
|
|
|
echo "does not exist: $dir/debian/dists/$dist" >&2
|
|
|
|
fi
|
2021-08-16 11:11:42 +00:00
|
|
|
case "$dist" in oldstable|stable)
|
|
|
|
if [ -e "$dir/debian/dists/$dist-updates" ]; then
|
|
|
|
rm --one-file-system --recursive "$dir/debian/dists/$dist-updates"
|
2020-01-05 16:33:37 +00:00
|
|
|
else
|
2021-08-16 11:11:42 +00:00
|
|
|
echo "does not exist: $dir/debian/dists/$dist-updates" >&2
|
2020-01-05 16:33:37 +00:00
|
|
|
fi
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "$dist" in
|
|
|
|
oldstable)
|
|
|
|
if [ -e "$dir/debian-security/dists/$dist/updates" ]; then
|
|
|
|
rm --one-file-system --recursive "$dir/debian-security/dists/$dist/updates"
|
|
|
|
else
|
|
|
|
echo "does not exist: $dir/debian-security/dists/$dist/updates" >&2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
stable)
|
|
|
|
if [ -e "$dir/debian-security/dists/$dist-security" ]; then
|
|
|
|
rm --one-file-system --recursive "$dir/debian-security/dists/$dist-security"
|
|
|
|
else
|
|
|
|
echo "does not exist: $dir/debian-security/dists/$dist-security" >&2
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2020-01-05 16:33:37 +00:00
|
|
|
done
|
2022-11-16 12:59:38 +00:00
|
|
|
for f in "$dir/debian-"*.qcow; do
|
2023-01-16 06:44:13 +00:00
|
|
|
if [ -e "$f" ]; then
|
|
|
|
rm --one-file-system "$f"
|
|
|
|
fi
|
2022-11-16 12:59:38 +00:00
|
|
|
done
|
2020-01-05 16:33:37 +00:00
|
|
|
if [ -e "$dir/debian/pool/main" ]; then
|
|
|
|
rm --one-file-system --recursive "$dir/debian/pool/main"
|
|
|
|
else
|
|
|
|
echo "does not exist: $dir/debian/pool/main" >&2
|
|
|
|
fi
|
|
|
|
if [ -e "$dir/debian-security/pool/updates/main" ]; then
|
|
|
|
rm --one-file-system --recursive "$dir/debian-security/pool/updates/main"
|
|
|
|
else
|
|
|
|
echo "does not exist: $dir/debian-security/pool/updates/main" >&2
|
|
|
|
fi
|
2020-01-22 22:30:28 +00:00
|
|
|
for i in $(seq 1 6); do
|
|
|
|
if [ ! -e "$dir/debian$i" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
rm "$dir/debian$i"
|
|
|
|
done
|
2020-01-05 16:33:37 +00:00
|
|
|
rm "$dir/mmdebstrapcache"
|
2022-01-07 11:46:35 +00:00
|
|
|
# remove all symlinks
|
|
|
|
find "$dir" -type l -delete
|
|
|
|
|
2020-01-05 16:33:37 +00:00
|
|
|
# now the rest should only be empty directories
|
|
|
|
if [ -e "$dir" ]; then
|
|
|
|
find "$dir" -depth -print0 | xargs -0 --no-run-if-empty rmdir
|
|
|
|
else
|
|
|
|
echo "does not exist: $dir" >&2
|
|
|
|
fi
|
|
|
|
}
|
2018-12-05 09:33:03 +00:00
|
|
|
|
2020-01-05 16:33:37 +00:00
|
|
|
cleanup_newcachedir() {
|
|
|
|
echo "running cleanup_newcachedir"
|
|
|
|
deletecache "$newcachedir"
|
|
|
|
}
|
2018-09-18 09:20:24 +00:00
|
|
|
|
2019-01-24 11:40:09 +00:00
|
|
|
get_oldaptnames() {
|
|
|
|
if [ ! -e "$1/$2" ]; then
|
|
|
|
return
|
|
|
|
fi
|
2021-09-21 19:11:46 +00:00
|
|
|
xz -dc "$1/$2" \
|
2019-01-24 11:40:09 +00:00
|
|
|
| grep-dctrl --no-field-names --show-field=Package,Version,Architecture,Filename '' \
|
|
|
|
| paste -sd " \n" \
|
2022-11-16 12:59:38 +00:00
|
|
|
| while read -r name ver arch fname; do
|
2019-01-24 11:40:09 +00:00
|
|
|
if [ ! -e "$1/$fname" ]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# apt stores deb files with the colon encoded as %3a while
|
|
|
|
# mirrors do not contain the epoch at all #645895
|
|
|
|
case "$ver" in *:*) ver="${ver%%:*}%3a${ver#*:}";; esac
|
|
|
|
aptname="$rootdir/var/cache/apt/archives/${name}_${ver}_${arch}.deb"
|
|
|
|
# we have to cp and not mv because other
|
|
|
|
# distributions might still need this file
|
|
|
|
# we have to cp and not symlink because apt
|
|
|
|
# doesn't recognize symlinks
|
|
|
|
cp --link "$1/$fname" "$aptname"
|
|
|
|
echo "$aptname"
|
|
|
|
done
|
|
|
|
}
|
2018-09-18 09:20:24 +00:00
|
|
|
|
2019-01-24 11:40:09 +00:00
|
|
|
get_newaptnames() {
|
|
|
|
if [ ! -e "$1/$2" ]; then
|
|
|
|
return
|
|
|
|
fi
|
2019-07-24 19:30:49 +00:00
|
|
|
# skip empty files by trying to uncompress the first byte of the payload
|
2021-09-21 19:11:46 +00:00
|
|
|
if [ "$(xz -dc "$1/$2" | head -c1 | wc -c)" -eq 0 ]; then
|
2019-07-24 19:30:49 +00:00
|
|
|
return
|
|
|
|
fi
|
2021-09-21 19:11:46 +00:00
|
|
|
xz -dc "$1/$2" \
|
2019-07-24 19:30:49 +00:00
|
|
|
| grep-dctrl --no-field-names --show-field=Package,Version,Architecture,Filename,SHA256 '' \
|
2019-01-24 11:40:09 +00:00
|
|
|
| paste -sd " \n" \
|
2022-11-16 12:59:38 +00:00
|
|
|
| while read -r name ver arch fname hash; do
|
2019-07-24 19:30:49 +00:00
|
|
|
# sanity check for the hash because sometimes the
|
|
|
|
# archive switches the hash algorithm
|
|
|
|
if [ "${#hash}" -ne 64 ]; then
|
|
|
|
echo "expected hash length of 64 but got ${#hash} for: $hash" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-01-24 11:40:09 +00:00
|
|
|
dir="${fname%/*}"
|
|
|
|
# apt stores deb files with the colon encoded as %3a while
|
|
|
|
# mirrors do not contain the epoch at all #645895
|
|
|
|
case "$ver" in *:*) ver="${ver%%:*}%3a${ver#*:}";; esac
|
|
|
|
aptname="$rootdir/var/cache/apt/archives/${name}_${ver}_${arch}.deb"
|
|
|
|
if [ -e "$aptname" ]; then
|
|
|
|
# make sure that we found the right file by checking its hash
|
2019-07-24 19:30:49 +00:00
|
|
|
echo "$hash $aptname" | sha256sum --check >&2
|
2019-01-24 11:40:09 +00:00
|
|
|
mkdir -p "$1/$dir"
|
|
|
|
# since we move hardlinks around, the same hardlink might've been
|
|
|
|
# moved already into the same place by another distribution.
|
|
|
|
# mv(1) refuses to copy A to B if both are hardlinks of each other.
|
2022-11-16 12:59:38 +00:00
|
|
|
if [ -e "$aptname" ] && [ -e "$1/$fname" ] && [ "$(stat -c "%d %i" "$aptname")" = "$(stat -c "%d %i" "$1/$fname")" ]; then
|
2019-01-24 11:40:09 +00:00
|
|
|
# both files are already the same so we just need to
|
|
|
|
# delete the source
|
|
|
|
rm "$aptname"
|
|
|
|
else
|
|
|
|
mv "$aptname" "$1/$fname"
|
|
|
|
fi
|
|
|
|
echo "$aptname"
|
|
|
|
fi
|
2018-10-21 16:02:08 +00:00
|
|
|
done
|
2019-01-24 11:40:09 +00:00
|
|
|
}
|
|
|
|
|
2020-01-05 16:33:37 +00:00
|
|
|
cleanupapt() {
|
|
|
|
echo "running cleanupapt" >&2
|
|
|
|
if [ ! -e "$rootdir" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
for f in \
|
|
|
|
"$rootdir/var/cache/apt/archives/"*.deb \
|
|
|
|
"$rootdir/var/cache/apt/archives/partial/"*.deb \
|
|
|
|
"$rootdir/var/cache/apt/"*.bin \
|
|
|
|
"$rootdir/var/lib/apt/lists/"* \
|
|
|
|
"$rootdir/var/lib/dpkg/status" \
|
|
|
|
"$rootdir/var/lib/dpkg/lock-frontend" \
|
|
|
|
"$rootdir/var/lib/dpkg/lock" \
|
|
|
|
"$rootdir/etc/apt/apt.conf" \
|
2023-02-18 22:16:48 +00:00
|
|
|
"$rootdir/etc/apt/sources.list.d/"* \
|
|
|
|
"$rootdir/etc/apt/preferences.d/"* \
|
2020-01-05 16:33:37 +00:00
|
|
|
"$rootdir/etc/apt/sources.list" \
|
|
|
|
"$rootdir/oldaptnames" \
|
|
|
|
"$rootdir/newaptnames" \
|
|
|
|
"$rootdir/var/cache/apt/archives/lock"; do
|
|
|
|
if [ ! -e "$f" ]; then
|
|
|
|
echo "does not exist: $f" >&2
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [ -d "$f" ]; then
|
|
|
|
rmdir "$f"
|
|
|
|
else
|
|
|
|
rm "$f"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
find "$rootdir" -depth -print0 | xargs -0 --no-run-if-empty rmdir
|
|
|
|
}
|
|
|
|
|
|
|
|
# note: this function uses brackets instead of curly braces, so that it's run
|
|
|
|
# in its own process and we can handle traps independent from the outside
|
|
|
|
update_cache() (
|
2019-01-24 11:40:09 +00:00
|
|
|
dist="$1"
|
|
|
|
nativearch="$2"
|
|
|
|
|
|
|
|
# use a subdirectory of $newcachedir so that we can use
|
|
|
|
# hardlinks
|
|
|
|
rootdir="$newcachedir/apt"
|
|
|
|
mkdir -p "$rootdir"
|
2018-09-18 09:20:24 +00:00
|
|
|
|
2020-01-05 16:33:37 +00:00
|
|
|
# we only set this trap here and overwrite the previous trap, because
|
|
|
|
# the update_cache function is run as part of a pipe and thus in its
|
|
|
|
# own process which will EXIT after it finished
|
|
|
|
trap "cleanupapt" EXIT INT TERM
|
|
|
|
|
2019-01-24 11:40:09 +00:00
|
|
|
for p in /etc/apt/apt.conf.d /etc/apt/sources.list.d /etc/apt/preferences.d /var/cache/apt/archives /var/lib/apt/lists/partial /var/lib/dpkg; do
|
|
|
|
mkdir -p "$rootdir/$p"
|
|
|
|
done
|
|
|
|
|
|
|
|
# read sources.list content from stdin
|
|
|
|
cat > "$rootdir/etc/apt/sources.list"
|
|
|
|
|
|
|
|
cat << END > "$rootdir/etc/apt/apt.conf"
|
2018-09-18 09:20:24 +00:00
|
|
|
Apt::Architecture "$nativearch";
|
2018-10-21 16:02:08 +00:00
|
|
|
Apt::Architectures "$nativearch";
|
2018-09-18 09:20:24 +00:00
|
|
|
Dir::Etc "$rootdir/etc/apt";
|
|
|
|
Dir::State "$rootdir/var/lib/apt";
|
|
|
|
Dir::Cache "$rootdir/var/cache/apt";
|
|
|
|
Apt::Install-Recommends false;
|
|
|
|
Apt::Get::Download-Only true;
|
2018-11-02 16:23:53 +00:00
|
|
|
Acquire::Languages "none";
|
2018-09-18 09:20:24 +00:00
|
|
|
Dir::Etc::Trusted "/etc/apt/trusted.gpg";
|
|
|
|
Dir::Etc::TrustedParts "/etc/apt/trusted.gpg.d";
|
2021-11-09 06:29:42 +00:00
|
|
|
Acquire::http::Dl-Limit "1000";
|
|
|
|
Acquire::https::Dl-Limit "1000";
|
|
|
|
Acquire::Retries "5";
|
2018-09-18 09:20:24 +00:00
|
|
|
END
|
|
|
|
|
2022-11-16 12:59:38 +00:00
|
|
|
: > "$rootdir/var/lib/dpkg/status"
|
2018-09-18 09:20:24 +00:00
|
|
|
|
2023-02-18 22:16:48 +00:00
|
|
|
if [ "$dist" = "$DEFAULT_DIST" ] && [ "$nativearch" = "$HOSTARCH" ] && [ "$USE_HOST_APT_CONFIG" = "yes" ]; then
|
|
|
|
# we append sources and settings instead of overwriting after
|
|
|
|
# an empty line
|
|
|
|
for f in /etc/apt/sources.list /etc/apt/sources.list.d/*; do
|
|
|
|
[ -e "$f" ] || continue
|
|
|
|
[ -e "$rootdir/$f" ] && echo >> "$rootdir/$f"
|
|
|
|
# we do not add entries from deb.debian.org or
|
|
|
|
# otherwise tests will fail if mirror pushes happen
|
|
|
|
# while the script is running
|
|
|
|
grep -v deb.debian.org/debian "$f" >> "$rootdir/$f" || :
|
|
|
|
done
|
|
|
|
for f in /etc/apt/preferences.d/*; do
|
|
|
|
[ -e "$f" ] || continue
|
|
|
|
[ -e "$rootdir/$f" ] && echo >> "$rootdir/$f"
|
|
|
|
cat "$f" >> "$rootdir/$f"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2019-01-24 11:40:09 +00:00
|
|
|
APT_CONFIG="$rootdir/etc/apt/apt.conf" apt-get update
|
2018-09-18 09:20:24 +00:00
|
|
|
|
2019-01-24 11:40:09 +00:00
|
|
|
# before downloading packages and before replacing the old Packages
|
|
|
|
# file, copy all old *.deb packages from the mirror to
|
|
|
|
# /var/cache/apt/archives so that apt will not re-download *.deb
|
|
|
|
# packages that we already have
|
|
|
|
{
|
2021-09-21 19:11:46 +00:00
|
|
|
get_oldaptnames "$oldmirrordir" "dists/$dist/main/binary-$nativearch/Packages.xz"
|
2021-08-16 11:11:42 +00:00
|
|
|
case "$dist" in oldstable|stable)
|
2021-09-21 19:11:46 +00:00
|
|
|
get_oldaptnames "$oldmirrordir" "dists/$dist-updates/main/binary-$nativearch/Packages.xz"
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "$dist" in
|
|
|
|
oldstable)
|
2021-09-21 19:11:46 +00:00
|
|
|
get_oldaptnames "$oldcachedir/debian-security" "dists/$dist/updates/main/binary-$nativearch/Packages.xz"
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
stable)
|
2021-09-21 19:11:46 +00:00
|
|
|
get_oldaptnames "$oldcachedir/debian-security" "dists/$dist-security/main/binary-$nativearch/Packages.xz"
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
2019-01-24 11:40:09 +00:00
|
|
|
} | sort -u > "$rootdir/oldaptnames"
|
2018-10-21 16:02:08 +00:00
|
|
|
|
2019-01-24 11:40:09 +00:00
|
|
|
pkgs=$(APT_CONFIG="$rootdir/etc/apt/apt.conf" apt-get indextargets \
|
|
|
|
--format '$(FILENAME)' 'Created-By: Packages' "Architecture: $nativearch" \
|
|
|
|
| xargs --delimiter='\n' /usr/lib/apt/apt-helper cat-file \
|
|
|
|
| grep-dctrl --no-field-names --show-field=Package --exact-match \
|
|
|
|
\( --field=Essential yes --or --field=Priority required \
|
|
|
|
--or --field=Priority important --or --field=Priority standard \
|
2021-01-06 10:33:37 +00:00
|
|
|
\))
|
2019-01-24 11:40:09 +00:00
|
|
|
|
2023-01-23 15:35:35 +00:00
|
|
|
pkgs="$pkgs build-essential busybox gpg eatmydata fakechroot fakeroot"
|
2019-01-24 11:40:09 +00:00
|
|
|
|
2022-07-26 16:30:52 +00:00
|
|
|
# we need usr-is-merged to simulate debootstrap behaviour for all dists
|
|
|
|
# starting from Debian 12 (Bullseye)
|
|
|
|
case "$dist" in
|
|
|
|
oldstable|stable) : ;;
|
2022-10-18 08:32:03 +00:00
|
|
|
*) pkgs="$pkgs usr-is-merged usrmerge" ;;
|
2022-07-26 16:30:52 +00:00
|
|
|
esac
|
|
|
|
|
2022-11-16 12:59:38 +00:00
|
|
|
# shellcheck disable=SC2086
|
2019-01-24 11:40:09 +00:00
|
|
|
APT_CONFIG="$rootdir/etc/apt/apt.conf" apt-get --yes install $pkgs
|
|
|
|
|
|
|
|
# to be able to also test gpg verification, we need to create a mirror
|
|
|
|
mkdir -p "$newmirrordir/dists/$dist/main/binary-$nativearch/"
|
|
|
|
curl --location "$mirror/dists/$dist/Release" > "$newmirrordir/dists/$dist/Release"
|
|
|
|
curl --location "$mirror/dists/$dist/Release.gpg" > "$newmirrordir/dists/$dist/Release.gpg"
|
2021-09-21 19:11:46 +00:00
|
|
|
curl --location "$mirror/dists/$dist/main/binary-$nativearch/Packages.xz" > "$newmirrordir/dists/$dist/main/binary-$nativearch/Packages.xz"
|
2022-01-07 11:46:35 +00:00
|
|
|
codename=$(awk '/^Codename: / { print $2; }' < "$newmirrordir/dists/$dist/Release")
|
|
|
|
[ -L "$newmirrordir/dists/$codename" ] || ln -s "$dist" "$newmirrordir/dists/$codename"
|
2021-08-16 11:11:42 +00:00
|
|
|
case "$dist" in oldstable|stable)
|
|
|
|
mkdir -p "$newmirrordir/dists/$dist-updates/main/binary-$nativearch/"
|
|
|
|
curl --location "$mirror/dists/$dist-updates/Release" > "$newmirrordir/dists/$dist-updates/Release"
|
|
|
|
curl --location "$mirror/dists/$dist-updates/Release.gpg" > "$newmirrordir/dists/$dist-updates/Release.gpg"
|
2021-09-21 19:11:46 +00:00
|
|
|
curl --location "$mirror/dists/$dist-updates/main/binary-$nativearch/Packages.xz" > "$newmirrordir/dists/$dist-updates/main/binary-$nativearch/Packages.xz"
|
2022-01-07 11:46:35 +00:00
|
|
|
[ -L "$newmirrordir/dists/$codename-updates" ] || ln -s "$dist-updates" "$newmirrordir/dists/$codename-updates"
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "$dist" in
|
|
|
|
oldstable)
|
|
|
|
mkdir -p "$newcachedir/debian-security/dists/$dist/updates/main/binary-$nativearch/"
|
|
|
|
curl --location "$security_mirror/dists/$dist/updates/Release" > "$newcachedir/debian-security/dists/$dist/updates/Release"
|
|
|
|
curl --location "$security_mirror/dists/$dist/updates/Release.gpg" > "$newcachedir/debian-security/dists/$dist/updates/Release.gpg"
|
2021-09-21 19:11:46 +00:00
|
|
|
curl --location "$security_mirror/dists/$dist/updates/main/binary-$nativearch/Packages.xz" > "$newcachedir/debian-security/dists/$dist/updates/main/binary-$nativearch/Packages.xz"
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
stable)
|
|
|
|
mkdir -p "$newcachedir/debian-security/dists/$dist-security/main/binary-$nativearch/"
|
|
|
|
curl --location "$security_mirror/dists/$dist-security/Release" > "$newcachedir/debian-security/dists/$dist-security/Release"
|
|
|
|
curl --location "$security_mirror/dists/$dist-security/Release.gpg" > "$newcachedir/debian-security/dists/$dist-security/Release.gpg"
|
2021-09-21 19:11:46 +00:00
|
|
|
curl --location "$security_mirror/dists/$dist-security/main/binary-$nativearch/Packages.xz" > "$newcachedir/debian-security/dists/$dist-security/main/binary-$nativearch/Packages.xz"
|
2022-01-07 11:46:35 +00:00
|
|
|
[ -L "$newcachedir/debian-security/dists/$codename-security" ] || ln -s "$dist-security" "$newcachedir/debian-security/dists/$codename-security"
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
2019-01-24 11:40:09 +00:00
|
|
|
|
|
|
|
# the deb files downloaded by apt must be moved to their right locations in the
|
|
|
|
# pool directory
|
|
|
|
#
|
|
|
|
# Instead of parsing the Packages file, we could also attempt to move the deb
|
|
|
|
# files ourselves to the appropriate pool directories. But that approach
|
|
|
|
# requires re-creating the heuristic by which the directory is chosen, requires
|
|
|
|
# stripping the epoch from the filename and will break once mirrors change.
|
|
|
|
# This way, it doesn't matter where the mirror ends up storing the package.
|
|
|
|
{
|
2021-09-21 19:11:46 +00:00
|
|
|
get_newaptnames "$newmirrordir" "dists/$dist/main/binary-$nativearch/Packages.xz";
|
2021-08-16 11:11:42 +00:00
|
|
|
case "$dist" in oldstable|stable)
|
2021-09-21 19:11:46 +00:00
|
|
|
get_newaptnames "$newmirrordir" "dists/$dist-updates/main/binary-$nativearch/Packages.xz"
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "$dist" in
|
|
|
|
oldstable)
|
2021-09-21 19:11:46 +00:00
|
|
|
get_newaptnames "$newcachedir/debian-security" "dists/$dist/updates/main/binary-$nativearch/Packages.xz"
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
stable)
|
2021-09-21 19:11:46 +00:00
|
|
|
get_newaptnames "$newcachedir/debian-security" "dists/$dist-security/main/binary-$nativearch/Packages.xz"
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
2019-01-24 11:40:09 +00:00
|
|
|
} | sort -u > "$rootdir/newaptnames"
|
|
|
|
|
|
|
|
rm "$rootdir/var/cache/apt/archives/lock"
|
|
|
|
rmdir "$rootdir/var/cache/apt/archives/partial"
|
|
|
|
# remove all packages that were in the old Packages file but not in the
|
|
|
|
# new one anymore
|
|
|
|
comm -23 "$rootdir/oldaptnames" "$rootdir/newaptnames" | xargs --delimiter="\n" --no-run-if-empty rm
|
|
|
|
# now the apt cache should be empty
|
2022-11-16 12:59:38 +00:00
|
|
|
if [ -n "$(ls -1qA "$rootdir/var/cache/apt/archives/")" ]; then
|
2019-03-25 13:49:03 +00:00
|
|
|
echo "$rootdir/var/cache/apt/archives not empty:"
|
|
|
|
ls -la "$rootdir/var/cache/apt/archives/"
|
2019-01-24 11:40:09 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
APT_CONFIG="$rootdir/etc/apt/apt.conf" apt-get --option Dir::Etc::SourceList=/dev/null update
|
|
|
|
APT_CONFIG="$rootdir/etc/apt/apt.conf" apt-get clean
|
2020-01-05 16:33:37 +00:00
|
|
|
|
|
|
|
cleanupapt
|
|
|
|
|
|
|
|
# this function is run in its own process, so we unset all traps before
|
|
|
|
# returning
|
|
|
|
trap "-" EXIT INT TERM
|
|
|
|
)
|
|
|
|
|
|
|
|
if [ -e "./shared/cache.A" ] && [ -e "./shared/cache.B" ]; then
|
|
|
|
echo "both ./shared/cache.A and ./shared/cache.B exist" >&2
|
|
|
|
echo "was a former run of the script aborted?" >&2
|
|
|
|
if [ -e ./shared/cache ]; then
|
|
|
|
echo "cache symlink points to $(readlink ./shared/cache)" >&2
|
|
|
|
case "$(readlink ./shared/cache)" in
|
|
|
|
cache.A)
|
2023-01-16 06:36:51 +00:00
|
|
|
echo "removing ./shared/cache.B" >&2
|
|
|
|
rm -r ./shared/cache.B
|
2020-01-05 16:33:37 +00:00
|
|
|
;;
|
|
|
|
cache.B)
|
2023-01-16 06:36:51 +00:00
|
|
|
echo "removing ./shared/cache.A" >&2
|
|
|
|
rm -r ./shared/cache.A
|
2020-01-05 16:33:37 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "unexpected" >&2
|
2023-01-16 06:36:51 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
2020-01-05 16:33:37 +00:00
|
|
|
esac
|
2023-01-16 06:36:51 +00:00
|
|
|
else
|
|
|
|
echo "./shared/cache doesn't exist" >&2
|
|
|
|
exit 1
|
2020-01-05 16:33:37 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -e "./shared/cache.A" ]; then
|
|
|
|
oldcache=cache.A
|
|
|
|
newcache=cache.B
|
|
|
|
else
|
|
|
|
oldcache=cache.B
|
|
|
|
newcache=cache.A
|
|
|
|
fi
|
|
|
|
|
|
|
|
oldcachedir="./shared/$oldcache"
|
|
|
|
newcachedir="./shared/$newcache"
|
|
|
|
|
|
|
|
oldmirrordir="$oldcachedir/debian"
|
|
|
|
newmirrordir="$newcachedir/debian"
|
|
|
|
|
|
|
|
mirror="http://deb.debian.org/debian"
|
|
|
|
security_mirror="http://security.debian.org/debian-security"
|
|
|
|
components=main
|
|
|
|
|
|
|
|
: "${DEFAULT_DIST:=unstable}"
|
|
|
|
: "${HAVE_QEMU:=yes}"
|
2020-01-06 10:10:31 +00:00
|
|
|
: "${RUN_MA_SAME_TESTS:=yes}"
|
2020-11-26 23:51:45 +00:00
|
|
|
# by default, use the mmdebstrap executable in the current directory
|
|
|
|
: "${CMD:=./mmdebstrap}"
|
2023-02-18 22:16:48 +00:00
|
|
|
: "${USE_HOST_APT_CONFIG:=no}"
|
2020-01-05 16:33:37 +00:00
|
|
|
|
|
|
|
if [ -e "$oldmirrordir/dists/$DEFAULT_DIST/Release" ]; then
|
|
|
|
http_code=$(curl --output /dev/null --silent --location --head --time-cond "$oldmirrordir/dists/$DEFAULT_DIST/Release" --write-out '%{http_code}' "$mirror/dists/$DEFAULT_DIST/Release")
|
|
|
|
case "$http_code" in
|
|
|
|
200) ;; # need update
|
|
|
|
304) echo up-to-date; exit 0;;
|
|
|
|
*) echo "unexpected status: $http_code"; exit 1;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
trap "cleanup_newcachedir" EXIT INT TERM
|
|
|
|
|
|
|
|
mkdir -p "$newcachedir"
|
|
|
|
touch "$newcachedir/mmdebstrapcache"
|
2018-10-21 16:02:08 +00:00
|
|
|
|
2020-01-06 10:10:31 +00:00
|
|
|
HOSTARCH=$(dpkg --print-architecture)
|
2023-01-16 06:44:38 +00:00
|
|
|
arches="$HOSTARCH"
|
2020-01-06 10:10:31 +00:00
|
|
|
if [ "$HOSTARCH" = amd64 ]; then
|
2023-01-16 06:44:38 +00:00
|
|
|
arches="$arches arm64 i386"
|
|
|
|
elif [ "$HOSTARCH" = arm64 ]; then
|
|
|
|
arches="$arches amd64 armhf"
|
2020-01-06 10:10:31 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
for nativearch in $arches; do
|
2021-08-16 11:11:42 +00:00
|
|
|
for dist in oldstable stable testing unstable; do
|
2020-01-06 10:10:31 +00:00
|
|
|
# non-host architectures are only downloaded for $DEFAULT_DIST
|
2022-11-16 12:59:38 +00:00
|
|
|
if [ "$nativearch" != "$HOSTARCH" ] && [ "$DEFAULT_DIST" != "$dist" ]; then
|
2019-09-26 21:32:52 +00:00
|
|
|
continue
|
|
|
|
fi
|
2021-08-16 11:11:42 +00:00
|
|
|
# we need a first pass without updates and security patches
|
|
|
|
# because otherwise, old package versions needed by
|
|
|
|
# debootstrap will not get included
|
|
|
|
echo "deb [arch=$nativearch] $mirror $dist $components" | update_cache "$dist" "$nativearch"
|
|
|
|
# we need to include the base mirror again or otherwise
|
|
|
|
# packages like build-essential will be missing
|
|
|
|
case "$dist" in
|
|
|
|
oldstable)
|
|
|
|
cat << END | update_cache "$dist" "$nativearch"
|
2019-01-24 11:40:09 +00:00
|
|
|
deb [arch=$nativearch] $mirror $dist $components
|
2021-08-16 11:11:42 +00:00
|
|
|
deb [arch=$nativearch] $mirror $dist-updates main
|
|
|
|
deb [arch=$nativearch] $security_mirror $dist/updates main
|
2019-01-24 11:40:09 +00:00
|
|
|
END
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
stable)
|
|
|
|
cat << END | update_cache "$dist" "$nativearch"
|
2019-01-24 11:40:09 +00:00
|
|
|
deb [arch=$nativearch] $mirror $dist $components
|
2021-08-16 11:11:42 +00:00
|
|
|
deb [arch=$nativearch] $mirror $dist-updates main
|
|
|
|
deb [arch=$nativearch] $security_mirror $dist-security main
|
2019-01-24 11:40:09 +00:00
|
|
|
END
|
2021-08-16 11:11:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
2018-10-21 16:02:08 +00:00
|
|
|
done
|
2018-09-18 09:20:24 +00:00
|
|
|
done
|
2018-11-04 19:34:40 +00:00
|
|
|
|
2020-01-22 22:30:28 +00:00
|
|
|
# Create some symlinks so that we can trick apt into accepting multiple apt
|
|
|
|
# lines that point to the same repository but look different. This is to
|
|
|
|
# avoid the warning:
|
|
|
|
# W: Target Packages (main/binary-all/Packages) is configured multiple times...
|
|
|
|
for i in $(seq 1 6); do
|
|
|
|
ln -s debian "$newcachedir/debian$i"
|
|
|
|
done
|
|
|
|
|
2020-01-05 16:33:37 +00:00
|
|
|
tmpdir=""
|
|
|
|
|
|
|
|
cleanuptmpdir() {
|
|
|
|
if [ -z "$tmpdir" ]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [ ! -e "$tmpdir" ]; then
|
|
|
|
return
|
|
|
|
fi
|
2022-11-05 13:59:57 +00:00
|
|
|
for f in "$tmpdir/worker.sh" \
|
2020-01-05 16:33:37 +00:00
|
|
|
"$tmpdir/mini-httpd" "$tmpdir/hosts" \
|
|
|
|
"$tmpdir/debian-chroot.tar" \
|
2022-11-05 13:59:57 +00:00
|
|
|
"$tmpdir/mmdebstrap.service"; do
|
2020-01-05 16:33:37 +00:00
|
|
|
if [ ! -e "$f" ]; then
|
|
|
|
echo "does not exist: $f" >&2
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
rm "$f"
|
|
|
|
done
|
|
|
|
rmdir "$tmpdir"
|
|
|
|
}
|
|
|
|
|
2022-11-16 12:59:38 +00:00
|
|
|
SOURCE_DATE_EPOCH="$(date --date="$(grep-dctrl -s Date -n '' "$newmirrordir/dists/$DEFAULT_DIST/Release")" +%s)"
|
|
|
|
export SOURCE_DATE_EPOCH
|
2020-03-07 22:36:56 +00:00
|
|
|
|
2018-12-05 09:33:03 +00:00
|
|
|
if [ "$HAVE_QEMU" = "yes" ]; then
|
2021-11-09 06:30:20 +00:00
|
|
|
case "$HOSTARCH" in
|
2022-11-05 13:59:57 +00:00
|
|
|
amd64|i386|arm64)
|
2021-11-09 06:30:20 +00:00
|
|
|
# okay
|
|
|
|
;;
|
|
|
|
*)
|
2022-11-05 13:59:57 +00:00
|
|
|
echo "qemu support is only available on amd64, i386 and arm64" >&2
|
|
|
|
echo "because grub is only available on those arches" >&2
|
2021-11-09 06:30:20 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2018-12-05 09:33:03 +00:00
|
|
|
# We must not use any --dpkgopt here because any dpkg options still
|
|
|
|
# leak into the chroot with chrootless mode.
|
|
|
|
# We do not use our own package cache here because
|
|
|
|
# - it doesn't (and shouldn't) contain the extra packages
|
|
|
|
# - it doesn't matter if the base system is from a different mirror timestamp
|
2018-12-05 09:36:21 +00:00
|
|
|
# procps is needed for /sbin/sysctl
|
2018-12-05 09:33:03 +00:00
|
|
|
tmpdir="$(mktemp -d)"
|
2020-01-05 16:33:37 +00:00
|
|
|
trap "cleanuptmpdir; cleanup_newcachedir" EXIT INT TERM
|
|
|
|
|
2022-11-05 13:59:57 +00:00
|
|
|
pkgs=perl-doc,systemd-sysv,perl,arch-test,fakechroot,fakeroot,mount,uidmap,qemu-user-static,binfmt-support,qemu-user,dpkg-dev,mini-httpd,libdevel-cover-perl,libtemplate-perl,debootstrap,procps,apt-cudf,aspcud,python3,libcap2-bin,gpg,debootstrap,distro-info-data,iproute2,ubuntu-keyring,apt-utils,grub-efi
|
2021-08-16 11:11:42 +00:00
|
|
|
if [ "$DEFAULT_DIST" != "oldstable" ]; then
|
2021-01-11 12:28:18 +00:00
|
|
|
pkgs="$pkgs,squashfs-tools-ng,genext2fs"
|
|
|
|
fi
|
2020-11-26 23:54:23 +00:00
|
|
|
if [ ! -e ./mmdebstrap ]; then
|
|
|
|
pkgs="$pkgs,mmdebstrap"
|
|
|
|
fi
|
2020-01-16 12:42:08 +00:00
|
|
|
case "$HOSTARCH" in
|
2020-11-29 20:39:08 +00:00
|
|
|
amd64|arm64)
|
2020-01-16 12:42:08 +00:00
|
|
|
pkgs="$pkgs,linux-image-$HOSTARCH"
|
|
|
|
;;
|
2020-11-29 20:39:08 +00:00
|
|
|
i386)
|
|
|
|
pkgs="$pkgs,linux-image-686"
|
|
|
|
;;
|
2020-01-16 12:42:08 +00:00
|
|
|
ppc64el)
|
|
|
|
pkgs="$pkgs,linux-image-powerpc64le"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "no kernel image for $HOSTARCH" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2020-01-06 10:10:31 +00:00
|
|
|
if [ "$HOSTARCH" = amd64 ] && [ "$RUN_MA_SAME_TESTS" = "yes" ]; then
|
2020-11-26 22:16:36 +00:00
|
|
|
arches=amd64,arm64
|
|
|
|
pkgs="$pkgs,libfakechroot:arm64,libfakeroot:arm64"
|
2023-01-16 06:44:38 +00:00
|
|
|
elif [ "$HOSTARCH" = arm64 ] && [ "$RUN_MA_SAME_TESTS" = "yes" ]; then
|
|
|
|
arches=arm64,amd64
|
|
|
|
pkgs="$pkgs,libfakechroot:amd64,libfakeroot:amd64"
|
2020-01-06 10:10:31 +00:00
|
|
|
else
|
|
|
|
arches=$HOSTARCH
|
|
|
|
fi
|
2022-11-16 12:59:38 +00:00
|
|
|
$CMD --variant=apt --architectures="$arches" --include="$pkgs" \
|
2021-11-09 06:29:42 +00:00
|
|
|
--aptopt='Acquire::http::Dl-Limit "1000"' \
|
|
|
|
--aptopt='Acquire::https::Dl-Limit "1000"' \
|
|
|
|
--aptopt='Acquire::Retries "5"' \
|
2022-12-23 10:55:42 +00:00
|
|
|
"$DEFAULT_DIST" - "$mirror" > "$tmpdir/debian-chroot.tar"
|
2018-11-04 19:34:40 +00:00
|
|
|
|
2018-12-05 09:33:03 +00:00
|
|
|
cat << END > "$tmpdir/mmdebstrap.service"
|
2018-11-04 19:34:40 +00:00
|
|
|
[Unit]
|
|
|
|
Description=mmdebstrap worker script
|
|
|
|
|
|
|
|
[Service]
|
|
|
|
Type=oneshot
|
|
|
|
ExecStart=/worker.sh
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
|
|
|
END
|
2018-12-05 09:33:03 +00:00
|
|
|
# here is something crazy:
|
|
|
|
# as we run mmdebstrap, the process ends up being run by different users with
|
|
|
|
# different privileges (real or fake). But for being able to collect
|
|
|
|
# Devel::Cover data, they must all share a single directory. The only way that
|
|
|
|
# I found to make this work is to mount the database directory with a
|
|
|
|
# filesystem that doesn't support ownership information at all and a umask that
|
|
|
|
# gives read/write access to everybody.
|
|
|
|
# https://github.com/pjcj/Devel--Cover/issues/223
|
|
|
|
cat << 'END' > "$tmpdir/worker.sh"
|
2018-11-04 19:34:40 +00:00
|
|
|
#!/bin/sh
|
2018-12-30 16:19:47 +00:00
|
|
|
echo 'root:root' | chpasswd
|
2021-11-09 06:30:40 +00:00
|
|
|
mount -t 9p -o trans=virtio,access=any,msize=128k mmdebstrap /mnt
|
2018-12-28 06:44:54 +00:00
|
|
|
# need to restart mini-httpd because we mounted different content into www-root
|
|
|
|
systemctl restart mini-httpd
|
2019-02-28 23:33:26 +00:00
|
|
|
|
|
|
|
handler () {
|
|
|
|
while IFS= read -r line || [ -n "$line" ]; do
|
2019-03-01 11:44:31 +00:00
|
|
|
printf "%s %s: %s\n" "$(date -u -d "0 $(date +%s.%3N) seconds - $2 seconds" +"%T.%3N")" "$1" "$line"
|
2019-02-28 23:33:26 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2018-11-04 19:34:40 +00:00
|
|
|
(
|
|
|
|
cd /mnt;
|
2018-11-23 16:35:24 +00:00
|
|
|
if [ -e cover_db.img ]; then
|
|
|
|
mkdir -p cover_db
|
|
|
|
mount -o loop,umask=000 cover_db.img cover_db
|
|
|
|
fi
|
2019-02-28 23:33:26 +00:00
|
|
|
|
2019-03-01 11:44:31 +00:00
|
|
|
now=$(date +%s.%3N)
|
2019-02-28 23:33:26 +00:00
|
|
|
ret=0
|
|
|
|
{ { { { {
|
|
|
|
sh -x ./test.sh 2>&1 1>&4 3>&- 4>&-; echo $? >&2;
|
2019-03-01 11:44:31 +00:00
|
|
|
} | handler E "$now" >&3;
|
|
|
|
} 4>&1 | handler O "$now" >&3;
|
2019-02-28 23:33:26 +00:00
|
|
|
} 2>&1;
|
|
|
|
} | { read xs; exit $xs; };
|
|
|
|
} 3>&1 || ret=$?
|
2023-01-16 06:54:03 +00:00
|
|
|
echo $ret > /mnt/exitstatus.txt
|
2018-11-23 16:35:24 +00:00
|
|
|
if [ -e cover_db.img ]; then
|
|
|
|
df -h cover_db
|
|
|
|
umount cover_db
|
|
|
|
fi
|
2023-01-16 06:54:03 +00:00
|
|
|
) > /mnt/output.txt 2>&1
|
2018-11-04 19:34:40 +00:00
|
|
|
umount /mnt
|
|
|
|
systemctl poweroff
|
|
|
|
END
|
2018-12-05 09:33:03 +00:00
|
|
|
chmod +x "$tmpdir/worker.sh"
|
2018-12-28 06:44:54 +00:00
|
|
|
# initially we serve from the new cache so that debootstrap can grab
|
|
|
|
# the new package repository and not the old
|
|
|
|
cat << END > "$tmpdir/mini-httpd"
|
2018-11-04 19:34:40 +00:00
|
|
|
START=1
|
2018-12-28 06:44:54 +00:00
|
|
|
DAEMON_OPTS="-h 127.0.0.1 -p 80 -u nobody -dd /mnt/$newcache -i /var/run/mini-httpd.pid -T UTF-8"
|
2018-11-04 19:34:40 +00:00
|
|
|
END
|
2018-12-05 09:33:03 +00:00
|
|
|
cat << 'END' > "$tmpdir/hosts"
|
2018-11-04 19:34:40 +00:00
|
|
|
127.0.0.1 localhost
|
|
|
|
END
|
2018-12-05 09:33:03 +00:00
|
|
|
#libguestfs-test-tool
|
|
|
|
#export LIBGUESTFS_DEBUG=1 LIBGUESTFS_TRACE=1
|
2020-03-07 22:37:17 +00:00
|
|
|
#
|
|
|
|
# In case the rootfs was prepared in fakechroot mode, ldconfig has to
|
|
|
|
# run to populate /etc/ld.so.cache or otherwise fakechroot tests will
|
|
|
|
# fail to run.
|
2020-11-27 07:18:27 +00:00
|
|
|
#
|
|
|
|
# The disk size is sufficient in most cases. Sometimes, gcc will do
|
|
|
|
# an upload with unstripped executables to make tracking down ICEs much
|
|
|
|
# easier (see #872672, #894014). During times with unstripped gcc, the
|
|
|
|
# buildd variant will not be 400MB but 1.3GB large and needs a 10G
|
|
|
|
# disk.
|
|
|
|
if [ -z ${DISK_SIZE+x} ]; then
|
2022-07-26 16:34:24 +00:00
|
|
|
DISK_SIZE=10G
|
2020-11-27 07:18:27 +00:00
|
|
|
fi
|
2022-11-05 13:59:57 +00:00
|
|
|
case "$HOSTARCH" in
|
|
|
|
amd64) GRUB_TARGET=x86_64-efi;;
|
|
|
|
i386) GRUB_TARGET=i386-efi;;
|
|
|
|
arm64) GRUB_TARGET=arm64-efi;;
|
|
|
|
esac
|
|
|
|
case "$HOSTARCH" in
|
|
|
|
arm64) SERIAL="loglevel=3 console=tty0 console=ttyAMA0,115200n8" ;;
|
|
|
|
*) SERIAL="loglevel=3 console=tty0 console=ttyS0,115200n8" ;;
|
|
|
|
esac
|
|
|
|
guestfish -- \
|
|
|
|
disk-create "$newcachedir/debian-$DEFAULT_DIST.qcow" qcow2 "$DISK_SIZE" : \
|
|
|
|
add-drive "$newcachedir/debian-$DEFAULT_DIST.qcow" format:qcow2 : \
|
|
|
|
launch : \
|
|
|
|
part-init /dev/sda gpt : \
|
|
|
|
part-add /dev/sda primary 8192 262144 : \
|
|
|
|
part-add /dev/sda primary 262145 -34 : \
|
|
|
|
part-set-gpt-type /dev/sda 1 C12A7328-F81F-11D2-BA4B-00A0C93EC93B : \
|
|
|
|
mkfs ext2 /dev/sda2 : \
|
|
|
|
mount /dev/sda2 / : \
|
|
|
|
tar-in "$tmpdir/debian-chroot.tar" / xattrs:true : \
|
|
|
|
mkdir-p /boot/efi : \
|
|
|
|
mkfs vfat /dev/sda1 : \
|
|
|
|
mount /dev/sda1 /boot/efi : \
|
2020-03-07 22:37:17 +00:00
|
|
|
command /sbin/ldconfig : \
|
2018-12-05 09:33:03 +00:00
|
|
|
mkdir-p /etc/systemd/system/multi-user.target.wants : \
|
|
|
|
ln-s ../mmdebstrap.service /etc/systemd/system/multi-user.target.wants/mmdebstrap.service : \
|
|
|
|
copy-in "$tmpdir/mmdebstrap.service" /etc/systemd/system/ : \
|
|
|
|
copy-in "$tmpdir/worker.sh" / : \
|
|
|
|
copy-in "$tmpdir/mini-httpd" /etc/default : \
|
2020-01-04 00:24:17 +00:00
|
|
|
copy-in "$tmpdir/hosts" /etc/ : \
|
2020-02-06 07:14:19 +00:00
|
|
|
touch /mmdebstrap-testenv : \
|
2022-11-05 13:59:57 +00:00
|
|
|
command "sh -c 'echo UUID=\$(blkid -c /dev/null -o value -s UUID /dev/sda2) / ext4 errors=remount-ro 0 1 > /etc/fstab'" : \
|
|
|
|
command "sh -c 'echo UUID=\$(blkid -c /dev/null -o value -s UUID /dev/sda1) /boot/efi vfat errors=remount-ro 0 2 >> /etc/fstab'" : \
|
|
|
|
command "sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT=/GRUB_CMDLINE_LINUX_DEFAULT=\"biosdevname=0 net.ifnames=0 consoleblank=0 rw $SERIAL\"/' /etc/default/grub" : \
|
|
|
|
command "update-initramfs -u" : \
|
|
|
|
command "grub-mkconfig -o /boot/grub/grub.cfg" : \
|
|
|
|
command "grub-install /dev/sda --target=$GRUB_TARGET --no-nvram --force-extra-removable --no-floppy --modules=part_gpt --grub-mkdevicemap=/boot/grub/device.map" : \
|
2020-02-06 07:14:19 +00:00
|
|
|
sync : \
|
2022-11-05 13:59:57 +00:00
|
|
|
umount /boot/efi : \
|
2020-02-06 07:14:19 +00:00
|
|
|
umount / : \
|
|
|
|
shutdown
|
2020-01-05 16:33:37 +00:00
|
|
|
cleanuptmpdir
|
|
|
|
trap "cleanup_newcachedir" EXIT INT TERM
|
2018-12-05 09:33:03 +00:00
|
|
|
fi
|
2018-11-04 19:34:40 +00:00
|
|
|
|
2019-02-24 09:49:01 +00:00
|
|
|
if [ "$HAVE_QEMU" = "yes" ]; then
|
|
|
|
# now replace the minihttpd config with one that serves the new repository
|
2020-01-04 08:19:19 +00:00
|
|
|
guestfish -a "$newcachedir/debian-$DEFAULT_DIST.qcow" -i <<EOF
|
|
|
|
upload -<<END /etc/default/mini-httpd
|
2018-12-28 06:44:54 +00:00
|
|
|
START=1
|
|
|
|
DAEMON_OPTS="-h 127.0.0.1 -p 80 -u nobody -dd /mnt/cache -i /var/run/mini-httpd.pid -T UTF-8"
|
|
|
|
END
|
2020-01-04 08:19:19 +00:00
|
|
|
EOF
|
2019-02-24 09:49:01 +00:00
|
|
|
fi
|
2018-12-28 06:44:54 +00:00
|
|
|
|
|
|
|
# delete possibly leftover symlink
|
|
|
|
if [ -e ./shared/cache.tmp ]; then
|
|
|
|
rm ./shared/cache.tmp
|
|
|
|
fi
|
|
|
|
# now atomically switch the symlink to point to the other directory
|
|
|
|
ln -s $newcache ./shared/cache.tmp
|
|
|
|
mv --no-target-directory ./shared/cache.tmp ./shared/cache
|
2020-01-05 16:33:37 +00:00
|
|
|
|
|
|
|
deletecache "$oldcachedir"
|
|
|
|
|
|
|
|
trap - EXIT INT TERM
|