3 then echo "Please run as root"
7 then echo "need arg $1 for chroot to make"
11 echo "creating chroot '$chrootdir'"
13 # Create coriolis chroot dir in /opt
14 mkdir
-p /opt
/chroot
/$chrootdir
16 # Install debootstrap and schroot
17 if [ -e /etc
/debian_version
]; then
18 # Debian detected: use apt
19 apt
install -y debootstrap schroot
20 elif [ -e /etc
/arch-release
]; then
21 # Arch Linux detected: use pacman
22 pacman
-S --needed debootstrap schroot
25 # Install debian/buster chroot using debootstrap
26 /usr
/sbin
/debootstrap buster
/opt
/chroot
/$chrootdir \
27 http
://ftp.uk.debian.org
/debian
28 echo "$chrootdir" > /opt
/chroot
/$chrootdir/etc
/debian_chroot
31 mkdir
-p /etc
/schroot
/$chrootdir
32 cp /etc
/schroot
/default
/copyfiles
/etc
/schroot
/$chrootdir
33 touch /etc
/schroot
/$chrootdir/nssdatabases
35 # create special fstab not bind-mounting /home
36 cat <<EOF >/etc/schroot/$chrootdir/fstab
37 # <file system> <mount point> <type> <options> <dump> <pass>
38 /proc /proc none rw,bind 0 0
39 /sys /sys none rw,bind 0 0
40 /dev /dev none rw,bind 0 0
41 /dev/pts /dev/pts none rw,bind 0 0
42 /tmp /tmp none rw,bind 0 0
45 # Add chroot config to schroot.conf
46 cat <<EOF >>/etc/schroot/schroot.conf
48 description=Debian Buster for $chrootdir
49 directory=/opt/chroot/$chrootdir
50 groups=sbuild-security,$SUDO_USER,users
55 echo "Adding the following $chrootdir section to /etc/schroot/schroot.conf:
58 description=Debian Buster for $chrootdir
59 directory=/opt/chroot/$chrootdir
60 groups=sbuild-security,$SUDO_USER,users
63 This enables you to chroot into $chrootdir as an unprivileged user by running
64 'schroot -c $chrootdir /bin/bash'
67 # Install apt dependencies in the chroot
69 schroot
-c $chrootdir /bin
/bash
<< EOF
70 echo Installing necessary apt dependencies in the chroot
73 apt-get install -y automake binutils-dev build-essential \
74 ccache cmake gcc git \
81 python3-setuptools python3-dev
83 # yeah systemd in a chroot? not very funny joke.
84 apt-get remove -y systemd
86 # add sudo no password
87 echo '$SUDO_USER ALL=NOPASSWD: ALL' >> /etc/sudoers.d/$chrootdir
89 # Create user with same UID in the chroot
90 useradd -m -p `python3 -c 'import crypt; print (crypt.crypt("1234","Fx"))'` \
91 -s /bin/bash $SUDO_USER -k /etc/skel
93 Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
95 # add deb-src to sources
96 echo deb-src http://ftp.debian.org/debian buster main > \
97 /etc/apt/sources.list.d/bustersrc.list
100 \e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
103 # Add convenience variable to chroot user .bash_profile
104 echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\n' > /home/$SUDO_USER/.bash_profile
105 chown $SUDO_USER /home/$SUDO_USER/.bash_profile
106 chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
108 echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"