From: Luke Kenneth Casson Leighton Date: Mon, 8 Mar 2021 11:25:30 +0000 (+0000) Subject: add mk-deb-chroot based on coriolis2-chroot X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=00b106aaf5bcd9dcfcdcc300411763c3ced95f0a;p=dev-env-setup.git add mk-deb-chroot based on coriolis2-chroot --- diff --git a/mk-deb-chroot b/mk-deb-chroot new file mode 100755 index 0000000..9853493 --- /dev/null +++ b/mk-deb-chroot @@ -0,0 +1,80 @@ +#!/bin/bash +if [ "$EUID" -ne 0 ] + then echo "Please run as root" + exit +fi +if [ -z "$1" ] + then echo "need arg $1 for chroot to make" + exit +fi +chrootdir="$1" +echo "creating chroot '$chrootdir'" +# Setup fstab mount points +cat <> /etc/fstab +/dev /opt/chroot/$chrootdir/dev none bind 0 0 +/dev/pts /opt/chroot/$chrootdir/dev/pts none bind 0 0 +/proc /opt/chroot/$chrootdir/proc none bind 0 0 +/sys /opt/chroot/$chrootdir/sys none bind 0 0 +/tmp /opt/chroot/$chrootdir/tmp none bind 0 0 +EOF + +# Create coriolis chroot dir in /opt +mkdir -p /opt/chroot/$chrootdir +# Install debootstrap and schroot via apt +apt install -y debootstrap schroot +# Install debian/buster chroot using debootstrap +/usr/sbin/debootstrap buster /opt/chroot/$chrootdir http://ftp.debian.org/debian +# Mount all chroot mount points from fstab +mount /opt/chroot/$chrootdir/dev +mount /opt/chroot/$chrootdir/dev/pts +mount /opt/chroot/$chrootdir/proc +mount /opt/chroot/$chrootdir/sys +mount /opt/chroot/$chrootdir/tmp +echo "$chrootdir" > /opt/chroot/$chrootdir/etc/debian_chroot +# Install apt dependencies in the chroot +chroot /opt/chroot/$chrootdir /bin/bash << 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 \ +python3 python3-pip \ +python3-setuptools python-dev + +# Create user with same UID in the chroot +useradd -m -p `python -c 'import crypt; print crypt.crypt("1234","Fx")'` -s /bin/bash $SUDO_USER -k /etc/skel +echo -e " +Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m" + +echo -e " +\e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m +" + +# Add convenience variable to chroot user .bash_profile +echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\n' > /home/$SUDO_USER/.bash_profile +chown $SUDO_USER /home/$SUDO_USER/.bash_profile +chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile + +echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds" +EOF + +# Add chroot config to schroot.conf +cat <>/etc/schroot/schroot.conf +[$chrootdir] +description=Debian Buster for $chrootdir +directory=/opt/chroot/$chrootdir +groups=sbuild-security,$SUDO_USER,users +EOF + +echo "Adding the following $chrootdir section to /etc/schroot/schroot.conf: + +[$chrootdir] +description=Debian Buster for $chrootdir +directory=/opt/chroot/$chrootdir +groups=sbuild-security,$SUDO_USER,users + +This enables you to chroot into $chrootdir as an unprivileged user by running +'schroot -c $chrootdir /bin/bash' +" +