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