23c08421c38958d1524d117367a67cc553493fe3
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"
18 echo "Creating chroot dir '$chrootdir'"
20 # Create coriolis chroot dir in /opt
21 mkdir
/opt
/chroot
/$chrootdir
23 echo "adding retries for debootstrap to not fail"
24 echo 'APT::Acquire::Retries "10";' > /etc
/apt
/apt.conf.d
/80-retries
25 echo 'APT::Acquire::Retries "10";' > /opt
/chroot
/$chrootdir/etc
/apt
/apt.conf.d
/80-retries
27 # Install debootstrap and schroot
28 if [ -e /etc
/debian_version
]; then
29 # Debian detected: use apt
30 apt
install -y debootstrap schroot
31 elif [ -e /etc
/arch-release
]; then
32 # Arch Linux detected: use pacman
33 pacman
-S --needed debootstrap schroot
36 # Install debian/buster chroot using debootstrap
37 /usr
/sbin
/debootstrap buster
/opt
/chroot
/$chrootdir \
38 http
://ftp.uk.debian.org
/debian
39 echo "$chrootdir" > /opt
/chroot
/$chrootdir/etc
/debian_chroot
42 mkdir
-p /etc
/schroot
/$chrootdir
43 cp /etc
/schroot
/default
/copyfiles
/etc
/schroot
/$chrootdir
44 touch /etc
/schroot
/$chrootdir/nssdatabases
46 # create special fstab not bind-mounting /home
47 cat <<EOF >/etc/schroot/$chrootdir/fstab
48 # <file system> <mount point> <type> <options> <dump> <pass>
49 /proc /proc none rw,bind 0 0
50 /sys /sys none rw,bind 0 0
51 /dev /dev none rw,bind 0 0
52 /dev/pts /dev/pts none rw,bind 0 0
53 /tmp /tmp none rw,bind 0 0
56 if grep -x "\[$chrootdir\]" /etc
/schroot
/schroot.conf
; then
57 echo "Found [$chrootdir] section in /etc/schroot/schroot.conf"
59 # Add chroot config to schroot.conf
60 cat <<EOF >>/etc/schroot/schroot.conf
62 description=Debian Buster for $chrootdir
63 directory=/opt/chroot/$chrootdir
64 groups=sbuild-security,$SUDO_USER,users
69 echo "Adding the following $chrootdir section to /etc/schroot/schroot.conf:
72 description=Debian Buster for $chrootdir
73 directory=/opt/chroot/$chrootdir
74 groups=sbuild-security,$SUDO_USER,users
77 This enables you to chroot into $chrootdir as an unprivileged user by running
78 'schroot -c $chrootdir /bin/bash'
82 # Install apt dependencies in the chroot
84 schroot
-c $chrootdir /bin
/bash
<< EOF
85 echo Installing necessary apt dependencies in the chroot
88 apt-get install -y automake binutils-dev build-essential \
89 ccache cmake gcc git \
96 python3-setuptools python3-dev
98 # yeah systemd in a chroot? not very funny joke.
99 apt-get remove -y systemd
101 # add sudo no password
102 echo '$SUDO_USER ALL=NOPASSWD: ALL' >> /etc/sudoers.d/$chrootdir
104 # Create user with same UID in the chroot
105 useradd -m -p `python3 -c 'import crypt; print (crypt.crypt("1234","Fx"))'` \
106 -s /bin/bash $SUDO_USER -k /etc/skel
108 Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
110 # add deb-src to sources
111 echo deb-src http://ftp.debian.org/debian buster main > \
112 /etc/apt/sources.list.d/bustersrc.list
115 \e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
118 # Add convenience variable to chroot user .bash_profile
119 echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\n' > /home/$SUDO_USER/.bash_profile
120 chown $SUDO_USER /home/$SUDO_USER/.bash_profile
121 chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
123 echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"