use schroot "type=directory" which means no need to do fstab modification
[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 # Install apt dependencies in the chroot
15 chroot /opt/chroot/coriolis /bin/bash << EOF
16 echo Installing necessary apt dependencies in the chroot
17 apt-get update -y
18 apt-get upgrade -y
19 apt-get install -y automake binutils-dev bison build-essential \
20 sysvinit-utils sysvinit-core \
21 ccache clang cmake doxygen dvipng flex gcc git graphviz \
22 imagemagick libboost-all-dev libboost-python-dev libbz2-dev \
23 libmpfr-dev libgmp-dev libmotif-dev libreadline-dev \
24 libqwt-dev libtool libx11-dev libxaw7-dev libxml2-dev \
25 python2.7 python2.7-dev \
26 libxpm-dev libxt-dev python3.7 python3-jinja2 python3-pip \
27 python3-setuptools python-dev python-qt4 python-sphinx \
28 qt4-dev-tools rapidjson-dev tcl tcl-dev tcl-tclreadline \
29 texlive texlive-fonts-extra texlive-lang-french \
30 texlive-latex-extra texlive-pictures xfig yosys zlib1g-dev
31
32 # yeah don't add systemd in a chroot. not funny joke
33 apt-get remove -y systemd
34
35 # Create user with same UID in the chroot
36 useradd -m -p `python3 -c 'import crypt; print (crypt.crypt("1234","Fx"))'` \
37 -s /bin/bash $SUDO_USER -k /etc/skel
38 echo -e "
39 Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
40
41 echo -e "
42 \e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
43 "
44
45 # Add convenience variable to chroot user .bash_profile
46 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
47 chown $SUDO_USER /home/$SUDO_USER/.bash_profile
48 chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
49
50 echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"
51 EOF
52
53 # Add coriolis config to schroot.conf
54 cat <<EOF >>/etc/schroot/schroot.conf
55 [coriolis]
56 description=Debian Buster for Coriolis
57 directory=/opt/chroot/coriolis
58 groups=sbuild-security,$SUDO_USER,users
59 type=directory
60 EOF
61
62 echo "Adding the following coriolis section to /etc/schroot/schroot.conf:
63
64 [coriolis]
65 description=Debian Buster for Coriolis
66 directory=/opt/chroot/coriolis
67 groups=sbuild-security,$SUDO_USER,users
68 type=directory
69
70 This enables you to chroot into coriolis as an unprivileged user by running
71 'schroot -c coriolis /bin/bash'
72 "
73
74 # Build and install yosys from source
75 # note that a specific version of yosys is needed for ls180 at the moment
76 chroot /opt/chroot/coriolis /bin/bash << EOF
77 apt-get update -y
78 apt-get build-dep yosys -y
79 apt-get remove yosys -y
80 EOF
81 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
82 cd /home/$SUDO_USER
83 git clone https://github.com/cliffordwolf/yosys.git
84 cd yosys
85 git checkout 049e3abf9baf795e69b9ecb9c4f19de6131f8418
86 make config-clang
87 make -j$(nproc)
88 EOF'
89
90 chroot /opt/chroot/coriolis /bin/bash << EOF
91 cd /home/$SUDO_USER/yosys
92 make install
93 EOF
94
95 # Install coriolis2 from source
96 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
97 cd /home/$SUDO_USER
98 source .bash_profile
99 mkdir -p /home/$SUDO_USER/coriolis-2.x/src
100 cd /home/$SUDO_USER/coriolis-2.x/src
101 git clone https://gitlab.lip6.fr/vlsi-eda/coriolis.git
102 cd coriolis
103 git checkout devel
104 ./bootstrap/ccb.py --project=coriolis --make="-j$(nproc) install"
105
106 # Setup and test coriolisenv
107 /home/$SUDO_USER/coriolis-2.x/src/coriolis/bootstrap/coriolisEnv.py > /home/$SUDO_USER/coriolisenv
108 source /home/$SUDO_USER/.bash_profile
109 source /home/$SUDO_USER/coriolisenv
110 EOF'
111
112 # Install alliance from source
113 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
114 cd /home/$SUDO_USER
115 source coriolisenv
116 git clone https://gitlab.lip6.fr/vlsi-eda/alliance.git
117 mkdir -p /home/$SUDO_USER/alliance/build /home/$SUDO_USER/alliance/install
118 mv alliance/alliance/src alliance
119 rm -rf alliance/alliance
120 cd alliance/src
121 ./autostuff
122 cd /home/$SUDO_USER/alliance/build
123 ../src/configure --prefix=/home/$SUDO_USER/alliance/install --enable-alc-shared
124 EOF'
125
126 chroot /opt/chroot/coriolis /bin/bash << EOF
127 cd /home/$SUDO_USER/alliance/build
128 source /home/$SUDO_USER/coriolisenv
129 make -j1 install
130 EOF
131
132 # Install and configure alliance-check-toolkit
133 runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
134 cd /home/$SUDO_USER
135 git clone https://gitlab.lip6.fr/vlsi-eda/alliance-check-toolkit.git
136 source coriolisenv
137 touch alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
138 cat <<EOG >>alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
139 export CORIOLIS_TOP=/home/$SUDO_USER/coriolis-2.x/Linux.x86_64/Release.Shared/install
140 export ALLIANCE_TOP=/home/$SUDO_USER/alliance/install
141 export CHECK_TOOLKIT=/home/$SUDO_USER/alliance-check-toolkit
142 export YOSYS_TOP=/home/$SUDO_USER/yosys
143 EOG
144 source /home/$SUDO_USER/.bash_profile
145 cd alliance-check-toolkit/benchs/ARM/cmos
146 make lvx
147 echo -e "
148 \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
149 "
150 make cgt
151 EOF'
152