3 then echo "Please run as root"
7 then echo "Need arg $1 for chroot to make"
12 if [ -e /opt
/chroot
/$chrootdir ]; then
13 echo "/opt/chroot/$chrootdir already exists"
17 echo "adding retries for debootstrap to not fail"
18 echo 'APT::Acquire::Retries "10";' > /etc
/apt
/apt.conf.d
/80-retries
20 echo "Creating chroot dir '$chrootdir'"
22 # Create coriolis chroot dir in /opt
23 mkdir
/opt
/chroot
/$chrootdir
25 # Install debootstrap and schroot
26 if [ -e /etc
/debian_version
]; then
27 # Debian detected: use apt
28 apt
install -y debootstrap schroot
29 elif [ -e /etc
/arch-release
]; then
30 # Arch Linux detected: use pacman
31 pacman
-S --needed debootstrap schroot
34 # Install debian/buster chroot using debootstrap
35 /usr
/sbin
/debootstrap buster
/opt
/chroot
/$chrootdir \
36 http
://ftp.uk.debian.org
/debian
37 echo "$chrootdir" > /opt
/chroot
/$chrootdir/etc
/debian_chroot
40 mkdir
-p /etc
/schroot
/$chrootdir
41 cp /etc
/schroot
/default
/copyfiles
/etc
/schroot
/$chrootdir
42 touch /etc
/schroot
/$chrootdir/nssdatabases
44 # create special fstab not bind-mounting /home
45 cat <<EOF >/etc/schroot/$chrootdir/fstab
46 # <file system> <mount point> <type> <options> <dump> <pass>
47 /proc /proc none rw,bind 0 0
48 /sys /sys none rw,bind 0 0
49 /dev /dev none rw,bind 0 0
50 /dev/pts /dev/pts none rw,bind 0 0
51 /tmp /tmp none rw,bind 0 0
54 if grep -x "\[$chrootdir\]" /etc
/schroot
/schroot.conf
; then
55 echo "Found [$chrootdir] section in /etc/schroot/schroot.conf"
57 # Add chroot config to schroot.conf
58 cat <<EOF >>/etc/schroot/schroot.conf
60 description=Debian Buster for $chrootdir
61 directory=/opt/chroot/$chrootdir
62 groups=sbuild-security,$SUDO_USER,users
67 echo "Adding the following $chrootdir section to /etc/schroot/schroot.conf:
70 description=Debian Buster for $chrootdir
71 directory=/opt/chroot/$chrootdir
72 groups=sbuild-security,$SUDO_USER,users
75 This enables you to chroot into $chrootdir as an unprivileged user by running
76 'schroot -c $chrootdir /bin/bash'
80 # Install apt dependencies in the chroot
82 schroot
-c $chrootdir /bin
/bash
<< EOF
83 echo Installing necessary apt dependencies in the chroot
86 apt-get install -y automake binutils-dev build-essential \
87 ccache cmake gcc git \
94 python3-setuptools python3-dev
96 # yeah systemd in a chroot? not very funny joke.
97 apt-get remove -y systemd
99 # add sudo no password
100 echo '$SUDO_USER ALL=NOPASSWD: ALL' >> /etc/sudoers.d/$chrootdir
102 # Create user with same UID in the chroot
103 useradd -m -p `python3 -c 'import crypt; print (crypt.crypt("1234","Fx"))'` \
104 -s /bin/bash $SUDO_USER -k /etc/skel
106 Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
108 # add deb-src to sources
109 echo deb-src http://ftp.debian.org/debian buster main > \
110 /etc/apt/sources.list.d/bustersrc.list
113 \e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
116 # Add convenience variable to chroot user .bash_profile
117 echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\n' > /home/$SUDO_USER/.bash_profile
118 chown $SUDO_USER /home/$SUDO_USER/.bash_profile
119 chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
121 echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"