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 "Creating chroot dir '$chrootdir'"
19 # Create coriolis chroot dir in /opt
20 mkdir
/opt
/chroot
/$chrootdir
22 # Install debootstrap and schroot
23 if [ -e /etc
/debian_version
]; then
24 # Debian detected: use apt
25 apt
install -y debootstrap schroot
26 elif [ -e /etc
/arch-release
]; then
27 # Arch Linux detected: use pacman
28 pacman
-S --needed debootstrap schroot
31 # Install debian/buster chroot using debootstrap
32 /usr
/sbin
/debootstrap buster
/opt
/chroot
/$chrootdir \
33 http
://ftp.uk.debian.org
/debian
34 echo "$chrootdir" > /opt
/chroot
/$chrootdir/etc
/debian_chroot
37 mkdir
-p /etc
/schroot
/$chrootdir
38 cp /etc
/schroot
/default
/copyfiles
/etc
/schroot
/$chrootdir
39 touch /etc
/schroot
/$chrootdir/nssdatabases
41 # create special fstab not bind-mounting /home
42 cat <<EOF >/etc/schroot/$chrootdir/fstab
43 # <file system> <mount point> <type> <options> <dump> <pass>
44 /proc /proc none rw,bind 0 0
45 /sys /sys none rw,bind 0 0
46 /dev /dev none rw,bind 0 0
47 /dev/pts /dev/pts none rw,bind 0 0
48 /tmp /tmp none rw,bind 0 0
51 # Add chroot config to schroot.conf
52 cat <<EOF >>/etc/schroot/schroot.conf
54 description=Debian Buster for $chrootdir
55 directory=/opt/chroot/$chrootdir
56 groups=sbuild-security,$SUDO_USER,users
61 echo "Adding the following $chrootdir section to /etc/schroot/schroot.conf:
64 description=Debian Buster for $chrootdir
65 directory=/opt/chroot/$chrootdir
66 groups=sbuild-security,$SUDO_USER,users
69 This enables you to chroot into $chrootdir as an unprivileged user by running
70 'schroot -c $chrootdir /bin/bash'
73 # Install apt dependencies in the chroot
75 schroot
-c $chrootdir /bin
/bash
<< EOF
76 echo Installing necessary apt dependencies in the chroot
79 apt-get install -y automake binutils-dev build-essential \
80 ccache cmake gcc git \
87 python3-setuptools python3-dev
89 # yeah systemd in a chroot? not very funny joke.
90 apt-get remove -y systemd
92 # add sudo no password
93 echo '$SUDO_USER ALL=NOPASSWD: ALL' >> /etc/sudoers.d/$chrootdir
95 # Create user with same UID in the chroot
96 useradd -m -p `python3 -c 'import crypt; print (crypt.crypt("1234","Fx"))'` \
97 -s /bin/bash $SUDO_USER -k /etc/skel
99 Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
101 # add deb-src to sources
102 echo deb-src http://ftp.debian.org/debian buster main > \
103 /etc/apt/sources.list.d/bustersrc.list
106 \e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
109 # Add convenience variable to chroot user .bash_profile
110 echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\n' > /home/$SUDO_USER/.bash_profile
111 chown $SUDO_USER /home/$SUDO_USER/.bash_profile
112 chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
114 echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"