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