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 # argh apt with broken proxies and unreliable ISPs, getting fed up with it
24 cat <<EOF >/tmp/brokenproxy
25 APT::Acquire::Retries "20";
26 APT::Get::Fix-Broken "true";
27 Acquire::http::Pipeline-Depth "0";
28 Acquire::http::No-Cache=True;
29 Acquire::BrokenProxy=true;
32 cp /tmp
/brokenproxy
/etc
/apt
/apt.conf.d
/80-retries
33 cp /tmp
/brokenproxy
/opt
/chroot
/coriolis
/etc
/apt
/apt.conf.d
/80-retries
35 # Install debootstrap and schroot
36 if [ -e /etc
/debian_version
]; then
37 # Debian detected: use apt
38 apt
install -y debootstrap schroot
39 elif [ -e /etc
/arch-release
]; then
40 # Arch Linux detected: use pacman
41 pacman
-S --needed debootstrap schroot
44 # Install debian/buster chroot using debootstrap
45 /usr
/sbin
/debootstrap buster
/opt
/chroot
/$chrootdir \
46 http
://ftp.uk.debian.org
/debian
47 echo "$chrootdir" > /opt
/chroot
/$chrootdir/etc
/debian_chroot
50 mkdir
-p /etc
/schroot
/$chrootdir
51 cp /etc
/schroot
/default
/copyfiles
/etc
/schroot
/$chrootdir
52 touch /etc
/schroot
/$chrootdir/nssdatabases
54 # create special fstab not bind-mounting /home
55 cat <<EOF >/etc/schroot/$chrootdir/fstab
56 # <file system> <mount point> <type> <options> <dump> <pass>
57 /proc /proc none rw,bind 0 0
58 /sys /sys none rw,bind 0 0
59 /dev /dev none rw,bind 0 0
60 /dev/pts /dev/pts none rw,bind 0 0
61 /tmp /tmp none rw,bind 0 0
64 if grep -x "\[$chrootdir\]" /etc
/schroot
/schroot.conf
; then
65 echo "Found [$chrootdir] section in /etc/schroot/schroot.conf"
67 # Add chroot config to schroot.conf
68 cat <<EOF >>/etc/schroot/schroot.conf
70 description=Debian Buster for $chrootdir
71 directory=/opt/chroot/$chrootdir
72 groups=sbuild-security,$SUDO_USER,users
77 echo "Adding the following $chrootdir section to /etc/schroot/schroot.conf:
80 description=Debian Buster for $chrootdir
81 directory=/opt/chroot/$chrootdir
82 groups=sbuild-security,$SUDO_USER,users
85 This enables you to chroot into $chrootdir as an unprivileged user by running
86 'schroot -c $chrootdir /bin/bash'
90 # Install apt dependencies in the chroot
92 schroot
-c $chrootdir /bin
/bash
<< EOF
93 echo Installing necessary apt dependencies in the chroot
96 apt-get install -y automake binutils-dev build-essential \
97 ccache cmake gcc git \
103 python3 python3-pip \
104 python3-setuptools python3-dev
106 # yeah systemd in a chroot? not very funny joke.
107 apt-get remove -y systemd
109 # add sudo no password
110 echo '$SUDO_USER ALL=NOPASSWD: ALL' >> /etc/sudoers.d/$chrootdir
112 # Create user with same UID in the chroot
113 useradd -m -p `python3 -c 'import crypt; print (crypt.crypt("1234","Fx"))'` \
114 -s /bin/bash $SUDO_USER -k /etc/skel
116 Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
118 # add deb-src to sources
119 echo deb-src http://ftp.debian.org/debian buster main > \
120 /etc/apt/sources.list.d/bustersrc.list
123 \e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
126 # Add convenience variable to chroot user .bash_profile
127 echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\n' > /home/$SUDO_USER/.bash_profile
128 chown $SUDO_USER /home/$SUDO_USER/.bash_profile
129 chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
131 echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"