Fix correct commit hash for release 0.7.0 of openXC7
[dev-env-setup.git] / mk-deb-chroot
index 526c26c42f455df805033d385dd56ec4426f61c5..81b4a3cb79431214d73af47d8beda07fce447b6a 100755 (executable)
@@ -18,7 +18,7 @@ fi
 echo "Creating chroot dir '$chrootdir'"
 
 # Create coriolis chroot dir in /opt
-mkdir /opt/chroot/$chrootdir
+mkdir -p /opt/chroot/$chrootdir
 
 # argh apt with broken proxies and unreliable ISPs, getting fed up with it
 if [ -e /tmp/brokenproxy ]; then
@@ -39,22 +39,36 @@ else
     cp /tmp/brokenproxy /etc/apt/apt.conf.d/80-retries
 fi
 
-# No need to check if exists, this script always runs with new chroot
-cp /tmp/brokenproxy /opt/chroot/$chrootdir/etc/apt/apt.conf.d/80-retries
-
-
 # Install debootstrap and schroot
 if [ -e /etc/debian_version ]; then
     # Debian detected: use apt
-    apt install -y debootstrap schroot
+    REQUIRED_PKG="debootstrap"
+    PKG_OK=$(dpkg-query -W --showformat='${Status}\n'\
+    $REQUIRED_PKG|grep "install ok installed")
+    echo Checking for $REQUIRED_PKG: $PKG_OK
+    if [ "" = "$PKG_OK" ]; then
+        apt install -y debootstrap
+    fi
+
+    REQUIRED_PKG="schroot"
+    PKG_OK=$(dpkg-query -W --showformat='${Status}\n'\
+    $REQUIRED_PKG|grep "install ok installed")
+    echo Checking for $REQUIRED_PKG: $PKG_OK
+    if [ "" = "$PKG_OK" ]; then
+        apt install -y schroot
+    fi
 elif [ -e /etc/arch-release ]; then
     # Arch Linux detected: use pacman
     pacman -S --needed debootstrap schroot
 fi
 
-# Install debian/buster chroot using debootstrap
-/usr/sbin/debootstrap buster /opt/chroot/$chrootdir \
-                      http://ftp.uk.debian.org/debian
+# Debian mirror from where to download packages for the chroot
+CHROOT_DEBIAN_MIRROR=${CHROOT_DEBIAN_MIRROR:-http://ftp.uk.debian.org/debian}
+
+# Install debian/buster chroot using debootstrap,
+# any /etc/ config must be done after this point!
+/usr/sbin/debootstrap buster /opt/chroot/$chrootdir $CHROOT_DEBIAN_MIRROR
+
 echo "$chrootdir" > /opt/chroot/$chrootdir/etc/debian_chroot
 
 # make chroot profile
@@ -62,6 +76,9 @@ mkdir -p /etc/schroot/$chrootdir
 cp /etc/schroot/default/copyfiles /etc/schroot/$chrootdir
 touch /etc/schroot/$chrootdir/nssdatabases
 
+# Copy over brokenproxy apt script to the new chroot environment
+cp /tmp/brokenproxy /opt/chroot/$chrootdir/etc/apt/apt.conf.d/80-retries
+
 # create special fstab not bind-mounting /home
 schroot_fstab="
 # <file system> <mount point>   <type>  <options>       <dump>  <pass>
@@ -109,21 +126,40 @@ This enables you to chroot into $chrootdir as an unprivileged user by running
 "
 fi
 
+#!!! buster backports is needed for a lot of things
+cat << EOF > /opt/chroot/$chrootdir/etc/apt/sources.list.d/buster_backports.list
+deb http://deb.debian.org/debian buster-backports main
+deb-src http://deb.debian.org/debian buster-backports main
+EOF
+
+# oooo annoying, pin preferences for buster-backports
+# make it low pririty for reproduceability
+cat << EOF > /opt/chroot/$chrootdir/etc/apt/preferences.d/99buster-backports
+Package: *
+Pin: release a=buster-backports
+Pin-Priority: 100
+
+Package: libcurl3-gnutls
+Pin: version 7.64*
+Pin-Priority: 1001
+EOF
+
 # Install apt dependencies in the chroot
 cd /tmp
-schroot -c $chrootdir /bin/bash << EOF
+schroot -c $chrootdir /bin/bash --directory=/tmp << EOF
 echo Installing necessary apt dependencies in the chroot
 apt-get update -y
 apt-get upgrade -y
 apt-get install -y automake binutils-dev build-essential \
-ccache cmake gcc git \
-libtool \
-sysvinit-core \
-sysvinit-utils \
-sudo \
-python2.7 \
-python3 python3-pip \
-python3-setuptools python3-dev
+        ccache cmake gcc git \
+        libtool \
+        sysvinit-core \
+        sysvinit-utils \
+        sudo \
+        python2.7 \
+        python3 python3-pip \
+        python3-setuptools python3-dev \
+        python3-setuptools-scm
 
 # yeah systemd in a chroot? not very funny joke.
 apt-get remove -y systemd