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