sort out coriolis-chroot
[dev-env-setup.git] / coriolis2-chroot
1 #!/bin/bash
2 if [ "$EUID" -ne 0 ]
3 then echo "Please run as root"
4 exit
5 fi
6 # Create coriolis chroot dir in /opt
7 mkdir -p /opt/chroot/coriolis
8 # Install debootstrap and schroot via apt
9 apt install -y debootstrap schroot
10 # Install debian/buster chroot using debootstrap
11 /usr/sbin/debootstrap buster /opt/chroot/coriolis \
12 http://ftp.uk.debian.org/debian
13 echo "coriolis2" > /opt/chroot/coriolis/etc/debian_chroot
14 # make coriolis2 profile
15 mkdir -p /etc/schroot/coriolis2
16 cp /etc/schroot/default/copyfiles /etc/schroot/coriolis2
17
18 # just... don't ask. yes, really, schroot fails if this is missing
19 mkdir -p /run/systemd/userdb
20
21 # create special nssthingy not copying passwd or shadow
22 cat <<EOF >/etc/schroot/coriolis2/nssdatabases
23 # System databases to copy into the chroot from the host system.
24 #
25 # <database name>
26 gshadow
27 services
28 protocols
29 networks
30 hosts
31 EOF
32
33 # create special fstab not bind-mounting /home
34 cat <<EOF >/etc/schroot/coriolis2/fstab
35 # <file system> <mount point> <type> <options> <dump> <pass>
36 /proc /proc none rw,bind 0 0
37 /sys /sys none rw,bind 0 0
38 /dev /dev none rw,bind 0 0
39 /dev/pts /dev/pts none rw,bind 0 0
40 /tmp /tmp none rw,bind 0 0
41 EOF
42
43 # Add coriolis config to schroot.conf
44 cat <<EOF >>/etc/schroot/schroot.conf
45 [coriolis]
46 description=Debian Buster for Coriolis
47 directory=/opt/chroot/coriolis
48 groups=sbuild-security,$SUDO_USER,users
49 type=directory
50 profile=coriolis2
51 EOF
52
53 echo "Adding the following coriolis section to /etc/schroot/schroot.conf:
54
55 [coriolis]
56 description=Debian Buster for Coriolis
57 directory=/opt/chroot/coriolis
58 groups=sbuild-security,$SUDO_USER,users
59 type=directory
60 profile=coriolis2
61
62 This enables you to chroot into coriolis as an unprivileged user by running
63 'schroot -c coriolis /bin/bash'
64 "
65
66 # Install apt dependencies in the chroot
67 cd /tmp
68 schroot -c coriolis --directory=/tmp /bin/bash << EOF
69 echo Installing necessary apt dependencies in the chroot
70 apt-get update -y
71 apt-get upgrade -y
72 apt-get install -y automake binutils-dev bison build-essential \
73 sysvinit-utils sysvinit-core \
74 ccache clang cmake doxygen dvipng flex gcc git graphviz \
75 imagemagick libboost-all-dev libboost-python-dev libbz2-dev \
76 libmpfr-dev libgmp-dev libmotif-dev libreadline-dev \
77 libqwt-dev libtool libx11-dev libxaw7-dev libxml2-dev \
78 python2.7 python2.7-dev \
79 libxpm-dev libxt-dev python3.7 python3-jinja2 python3-pip \
80 python3-setuptools python-dev python-qt4 python-sphinx \
81 qt4-dev-tools rapidjson-dev tcl tcl-dev tcl-tclreadline \
82 texlive texlive-fonts-extra texlive-lang-french \
83 texlive-latex-extra texlive-pictures xfig zlib1g-dev
84
85 # yeah don't add systemd in a chroot. not funny joke
86 apt-get remove -y systemd
87
88 # Create user with same UID in the chroot
89 useradd -m -p `python3 -c 'import crypt; print (crypt.crypt("1234","Fx"))'` \
90 -s /bin/bash $SUDO_USER -k /etc/skel
91 echo -e "
92 Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
93
94 echo -e "
95 \e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
96 "
97
98 # Add convenience variable to chroot user .bash_profile
99 echo -e 'export PATH=/usr/lib/ccache:"\044PATH"\nexport DISPLAY=:0.0\nexport ALLIANCE_TOP=/home/$SUDO_USER/alliance/install\nexport YOSYS_TOP=/home/$SUDO_USER/yosys\nexport LD_LIBRARY_PATH=\044{ALLIANCE_TOP}/lib:\044{LD_LIBRARY_PATH}\nexport LD_LIBRARY_PATH=\044{ALLIANCE_TOP}/lib64:\044{LD_LIBRARY_PATH}' > /home/$SUDO_USER/.bash_profile
100 chown $SUDO_USER /home/$SUDO_USER/.bash_profile
101 chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
102
103 echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"
104 EOF
105
106 # Build and install yosys from source
107 # note that a specific version of yosys is needed for ls180 at the moment
108 schroot -c coriolis --directory=/tmp /bin/bash << EOF
109 echo "deb-src http://ftp.debian.org/debian buster main" > /etc/apt/sources.list.d/bustersrc.list
110 apt-get update -y
111 apt-get build-dep yosys -y
112 EOF
113
114 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis --directory=/tmp /bin/bash << EOF
115 cd /home/$SUDO_USER
116 git clone https://github.com/cliffordwolf/yosys.git
117 cd yosys
118 git checkout 049e3abf9baf795e69b9ecb9c4f19de6131f8418
119 make config-clang
120 make -j$(nproc)
121 EOF'
122
123 schroot -c coriolis --directory=/tmp /bin/bash << EOF
124 cd /home/$SUDO_USER/yosys
125 make install
126 EOF
127
128 # Install coriolis2 from source
129 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis --directory=/tmp /bin/bash << EOF
130 cd /home/$SUDO_USER
131 source .bash_profile
132 mkdir -p /home/$SUDO_USER/coriolis-2.x/src
133 cd /home/$SUDO_USER/coriolis-2.x/src
134 git clone https://gitlab.lip6.fr/vlsi-eda/coriolis.git
135 cd coriolis
136 git checkout devel
137 ./bootstrap/ccb.py --project=coriolis --make="-j$(nproc) install"
138
139 # Setup and test coriolisenv
140 /home/$SUDO_USER/coriolis-2.x/src/coriolis/bootstrap/coriolisEnv.py > /home/$SUDO_USER/coriolisenv
141 source /home/$SUDO_USER/.bash_profile
142 source /home/$SUDO_USER/coriolisenv
143 EOF'
144
145 # Install alliance from source
146 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis --directory=/tmp /bin/bash << EOF
147 cd /home/$SUDO_USER
148 source coriolisenv
149 git clone https://gitlab.lip6.fr/vlsi-eda/alliance.git
150 mkdir -p /home/$SUDO_USER/alliance/build /home/$SUDO_USER/alliance/install
151 mv alliance/alliance/src alliance
152 rm -rf alliance/alliance
153 cd alliance/src
154 ./autostuff
155 cd /home/$SUDO_USER/alliance/build
156 ../src/configure --prefix=/home/$SUDO_USER/alliance/install --enable-alc-shared
157 EOF'
158
159 schroot -c coriolis --directory=/tmp /bin/bash << EOF
160 cd /home/$SUDO_USER/alliance/build
161 source /home/$SUDO_USER/coriolisenv
162 make -j1 install
163 EOF
164
165 # Install and configure alliance-check-toolkit
166 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis --directory=/tmp /bin/bash << EOF
167 cd /home/$SUDO_USER
168 git clone https://gitlab.lip6.fr/vlsi-eda/alliance-check-toolkit.git
169 source coriolisenv
170 touch alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
171 cat <<EOG >>alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
172 export CORIOLIS_TOP=/home/$SUDO_USER/coriolis-2.x/Linux.x86_64/Release.Shared/install
173 export ALLIANCE_TOP=/home/$SUDO_USER/alliance/install
174 export CHECK_TOOLKIT=/home/$SUDO_USER/alliance-check-toolkit
175 export YOSYS_TOP=/home/$SUDO_USER/yosys
176 EOG
177 source /home/$SUDO_USER/.bash_profile
178 cd alliance-check-toolkit/benchs/ARM/cmos
179 make lvx
180 echo -e "
181 \e[1;91mSelect File -> Open Cell or press CTRL + o then enter as the cell name 'arm_chip_cts_r' without the single quotation marks.\e[0m
182 "
183 make cgt
184 EOF'
185