969930fd8b906f784902f9ea938b688386e492f3
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 if grep -x "\[$chrootdir\]" /etc
/schroot
/schroot.conf
; then
52 echo "Found [$chrootdir] section in /etc/schroot/schroot.conf"
54 # Add chroot config to schroot.conf
55 cat <<EOF >>/etc/schroot/schroot.conf
57 description=Debian Buster for $chrootdir
58 directory=/opt/chroot/$chrootdir
59 groups=sbuild-security,$SUDO_USER,users
64 echo "Adding the following $chrootdir section to /etc/schroot/schroot.conf:
67 description=Debian Buster for $chrootdir
68 directory=/opt/chroot/$chrootdir
69 groups=sbuild-security,$SUDO_USER,users
72 This enables you to chroot into $chrootdir as an unprivileged user by running
73 'schroot -c $chrootdir /bin/bash'
77 # Install apt dependencies in the chroot
79 schroot
-c $chrootdir /bin
/bash
<< EOF
80 echo Installing necessary apt dependencies in the chroot
83 apt-get install -y automake binutils-dev build-essential \
84 ccache cmake gcc git \
91 python3-setuptools python3-dev
93 # yeah systemd in a chroot? not very funny joke.
94 apt-get remove -y systemd
96 # add sudo no password
97 echo '$SUDO_USER ALL=NOPASSWD: ALL' >> /etc/sudoers.d/$chrootdir
99 # Create user with same UID in the chroot
100 useradd -m -p `python3 -c 'import crypt; print (crypt.crypt("1234","Fx"))'` \
101 -s /bin/bash $SUDO_USER -k /etc/skel
103 Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
105 # add deb-src to sources
106 echo deb-src http://ftp.debian.org/debian buster main > \
107 /etc/apt/sources.list.d/bustersrc.list
110 \e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
113 # Add convenience variable to chroot user .bash_profile
114 echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\n' > /home/$SUDO_USER/.bash_profile
115 chown $SUDO_USER /home/$SUDO_USER/.bash_profile
116 chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
118 echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"