2020-12-21 01:31:10 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
CONFIGURED_ARCH=$1
|
|
|
|
IMAGE_DISTRO=$2
|
|
|
|
FILESYSTEM_ROOT=$3
|
|
|
|
http_proxy=$4
|
|
|
|
|
|
|
|
TARGET=$TARGET_PATH
|
|
|
|
[ -z "$TARGET" ] && TARGET=target
|
|
|
|
|
|
|
|
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh
|
|
|
|
|
|
|
|
TARGET_BASEIMAGE_PATH=$TARGET/versions/host-base-image
|
|
|
|
mkdir -p $TARGET_BASEIMAGE_PATH
|
|
|
|
|
2022-01-07 07:36:26 -06:00
|
|
|
alias urlencode='python3 -c "import sys, urllib.parse as ul; print (ul.quote_plus(sys.argv[1]))"'
|
|
|
|
shopt -s expand_aliases
|
|
|
|
|
2020-12-21 01:31:10 -06:00
|
|
|
generate_version_file()
|
|
|
|
{
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT /bin/bash -c "dpkg-query -W -f '\${Package}==\${Version}\n'" > $TARGET_BASEIMAGE_PATH/versions-deb-${IMAGE_DISTRO}-${CONFIGURED_ARCH}
|
|
|
|
}
|
|
|
|
|
2022-06-08 17:49:49 -05:00
|
|
|
if [ "$ENABLE_VERSION_CONTROL_DEB" != "y" ] || [ ! -d files/build/versions/host-base-image ]; then
|
2020-12-21 01:31:10 -06:00
|
|
|
if [[ $CONFIGURED_ARCH == armhf || $CONFIGURED_ARCH == arm64 ]]; then
|
2021-10-25 17:36:55 -05:00
|
|
|
if [ $MULTIARCH_QEMU_ENVIRON == "y" ]; then
|
2021-04-18 10:17:57 -05:00
|
|
|
# qemu arm bin executable for cross-building
|
|
|
|
sudo mkdir -p $FILESYSTEM_ROOT/usr/bin
|
|
|
|
sudo cp /usr/bin/qemu*static $FILESYSTEM_ROOT/usr/bin || true
|
|
|
|
fi
|
2021-10-25 17:36:55 -05:00
|
|
|
sudo http_proxy=$HTTP_PROXY SKIP_BUILD_HOOK=y debootstrap --foreign --variant=minbase --arch $CONFIGURED_ARCH $IMAGE_DISTRO $FILESYSTEM_ROOT http://deb.debian.org/debian
|
|
|
|
sudo rm $FILESYSTEM_ROOT/proc -rf
|
|
|
|
sudo mkdir $FILESYSTEM_ROOT/proc
|
|
|
|
sudo mount -t proc proc $FILESYSTEM_ROOT/proc
|
|
|
|
sudo LANG=C chroot $FILESYSTEM_ROOT /debootstrap/debootstrap --second-stage
|
2020-12-21 01:31:10 -06:00
|
|
|
else
|
|
|
|
sudo http_proxy=$HTTP_PROXY SKIP_BUILD_HOOK=y debootstrap --variant=minbase --arch $CONFIGURED_ARCH $IMAGE_DISTRO $FILESYSTEM_ROOT http://debian-archive.trafficmanager.net/debian
|
|
|
|
fi
|
|
|
|
RET=$?
|
|
|
|
if [ $RET -ne 0 ]; then
|
|
|
|
exit $RET
|
|
|
|
fi
|
|
|
|
|
|
|
|
generate_version_file
|
|
|
|
exit $RET
|
|
|
|
fi
|
|
|
|
|
|
|
|
ARCH=$(dpkg --print-architecture)
|
|
|
|
DISTRO=$(grep CODENAME /etc/os-release | cut -d= -f2)
|
|
|
|
if [ "$ARCH" != "$CONFIGURED_ARCH" ] || [ "$DISTRO" != "$IMAGE_DISTRO" ]; then
|
2022-06-06 06:35:53 -05:00
|
|
|
"Not support to build different ARCH/DISTRO ${CONFIGURED_ARCH}:${IMAGE_DISTRO} in ${ARCH}:${DISTRO}."
|
2020-12-21 01:31:10 -06:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-06-06 06:35:53 -05:00
|
|
|
# Generate the version files for the host base image
|
|
|
|
TEMP_DIR=$(mktemp -d)
|
|
|
|
./scripts/versions_manager.py generate -t $TEMP_DIR -n host-base-image -d $IMAGE_DISTRO -a $CONFIGURED_ARCH
|
2022-06-08 17:49:49 -05:00
|
|
|
PACKAGES=$(sed -E 's/=(=[^=]*)$/\1/' $TEMP_DIR/versions-deb)
|
2022-06-06 06:35:53 -05:00
|
|
|
if [ -z "$PACKAGES" ]; then
|
|
|
|
echo "Not found host-base-image packages, please check the version files in files/build/versions/host-base-image" 2>&1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
rm -rf $TEMP_DIR
|
|
|
|
|
2020-12-21 01:31:10 -06:00
|
|
|
BASEIMAGE_TARBALLPATH=$TARGET/baseimage
|
|
|
|
BASEIMAGE_TARBALL=$(realpath -e $TARGET)/baseimage.tgz
|
|
|
|
|
|
|
|
rm -rf $BASEIMAGE_TARBALLPATH $BASEIMAGE_TARBALL
|
|
|
|
|
|
|
|
ARCHIEVES=$BASEIMAGE_TARBALLPATH/var/cache/apt/archives
|
|
|
|
APTLIST=$BASEIMAGE_TARBALLPATH/var/lib/apt/lists
|
|
|
|
TARGET_DEBOOTSTRAP=$BASEIMAGE_TARBALLPATH/debootstrap
|
2022-01-07 07:36:26 -06:00
|
|
|
APTDEBIAN="$APTLIST/deb.debian.org_debian_dists_${DISTRO}_main_binary-${CONFIGURED_ARCH}_Packages"
|
2020-12-21 01:31:10 -06:00
|
|
|
DEBPATHS=$TARGET_DEBOOTSTRAP/debpaths
|
|
|
|
DEBOOTSTRAP_BASE=$TARGET_DEBOOTSTRAP/base
|
|
|
|
DEBOOTSTRAP_REQUIRED=$TARGET_DEBOOTSTRAP/required
|
|
|
|
[ -d $BASEIMAGE_TARBALLPATH ] && rm -rf $BASEIMAGE_TARBALLPATH
|
|
|
|
mkdir -p $ARCHIEVES
|
|
|
|
mkdir -p $APTLIST
|
|
|
|
mkdir -p $TARGET_DEBOOTSTRAP
|
2021-06-30 02:42:57 -05:00
|
|
|
URL_ARR=$(apt-get download --print-uris $PACKAGES | cut -d" " -f1 | tr -d "'")
|
2020-12-21 01:31:10 -06:00
|
|
|
PACKAGE_ARR=($PACKAGES)
|
|
|
|
LENGTH=${#PACKAGE_ARR[@]}
|
|
|
|
for ((i=0;i<LENGTH;i++))
|
|
|
|
do
|
|
|
|
package=${PACKAGE_ARR[$i]}
|
|
|
|
packagename=$(echo $package | sed -E 's/=[^=]*$//')
|
2022-01-07 07:36:26 -06:00
|
|
|
encoded_packagename=$(urlencode $packagename)
|
|
|
|
url=$(echo "$URL_ARR" | grep -i "/${packagename}_\|/${encoded_packagename}_")
|
2021-06-30 02:42:57 -05:00
|
|
|
if [ -z "$url" ] || [[ $(echo "$url" | wc -l) -gt 1 ]]; then
|
2022-06-06 06:35:53 -05:00
|
|
|
echo "No found package or found multiple package for package $packagename, url: $url" 1>&2
|
2021-06-30 02:42:57 -05:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-12-21 01:31:10 -06:00
|
|
|
filename=$(basename "$url")
|
2022-01-07 07:36:26 -06:00
|
|
|
SKIP_BUILD_HOOK=y wget $url -O $ARCHIEVES/$filename
|
2020-12-21 01:31:10 -06:00
|
|
|
echo $packagename >> $DEBOOTSTRAP_REQUIRED
|
|
|
|
echo "$packagename /var/cache/apt/archives/$filename" >> $DEBPATHS
|
|
|
|
done
|
|
|
|
touch $APTDEBIAN
|
|
|
|
touch $DEBOOTSTRAP_BASE
|
2021-05-11 05:04:01 -05:00
|
|
|
(cd $BASEIMAGE_TARBALLPATH && fakeroot tar -zcf $BASEIMAGE_TARBALL .)
|
2020-12-21 01:31:10 -06:00
|
|
|
|
|
|
|
sudo debootstrap --verbose --variant=minbase --arch $CONFIGURED_ARCH --unpack-tarball=$BASEIMAGE_TARBALL $IMAGE_DISTRO $FILESYSTEM_ROOT
|
|
|
|
RET=$?
|
|
|
|
if [ $RET -ne 0 ]; then
|
|
|
|
exit $RET
|
|
|
|
fi
|
|
|
|
|
|
|
|
generate_version_file
|