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