Fix correct commit hash for release 0.7.0 of openXC7
[dev-env-setup.git] / coriolis2-chroot
index a19ef53f29965383026dd843247038f9ef5fd2c7..1ba4e35ee7fdb9802d1a5a8feda234a711dc8ee3 100755 (executable)
@@ -3,167 +3,48 @@ if [ "$EUID" -ne 0 ]
   then echo "Please run as root"
   exit
 fi
-# Create coriolis chroot dir in /opt
-mkdir -p /opt/chroot/coriolis
-# Install debootstrap and schroot via apt
-apt install -y debootstrap schroot
-# Install debian/buster chroot using debootstrap
-/usr/sbin/debootstrap buster /opt/chroot/coriolis \
-                      http://ftp.uk.debian.org/debian
-echo "coriolis2" > /opt/chroot/coriolis/etc/debian_chroot
-# make coriolis2 profile
-mkdir -p /etc/schroot/coriolis2
-cp /etc/schroot/default/* /etc/schroot/coriolis2
-
-# create special fstab not bind-mounting /home
-cat <<EOF >/etc/schroot/coriolis2/fstab
-# <file system> <mount point>   <type>  <options>       <dump>  <pass>
-/proc           /proc           none    rw,bind         0       0
-/sys            /sys            none    rw,bind         0       0
-/dev            /dev            none    rw,bind         0       0
-/dev/pts        /dev/pts        none    rw,bind         0       0
-/tmp            /tmp            none    rw,bind         0       0
-EOF
-
-# Add coriolis config to schroot.conf
-cat <<EOF >>/etc/schroot/schroot.conf
-[coriolis]
-description=Debian Buster for Coriolis
-directory=/opt/chroot/coriolis
-groups=sbuild-security,$SUDO_USER,users
-type=directory
-profile=coriolis2
-EOF
-
-echo "Adding the following coriolis section to /etc/schroot/schroot.conf:
-
-[coriolis]
-description=Debian Buster for Coriolis
-directory=/opt/chroot/coriolis
-groups=sbuild-security,$SUDO_USER,users
-type=directory
-profile=coriolis2
+# Terminal echo colours
+RED='\033[1;91m'
+NC='\033[0m'
+
+# Default name for the new chroot
+chroot_name="coriolis"
+
+# Check if default chroot name should be used or not
+if [ -z $1 ]; then
+    echo "Not provided a chroot name, using default chroot \"$chroot_name\""
+else
+       chroot_name="$1"
+       echo "Using specified chroot name \"$chroot_name\""
+fi
 
-This enables you to chroot into coriolis as an unprivileged user by running
-'schroot -c coriolis /bin/bash'
+if [ -e /opt/chroot/$chroot_name ]; then
+    echo -e "
+${RED}Chroot \"$chroot_name\" exists! Delete with \"rm-deb-chroot\" or
+run parts of this script separately${NC}
 "
-
-# Install apt dependencies in the chroot
-cd /tmp
-schroot -c coriolis /bin/bash << EOF
-echo Installing necessary apt dependencies in the chroot
-apt-get update -y
-apt-get upgrade -y
-apt-get install -y automake binutils-dev bison build-essential \
-sysvinit-utils sysvinit-core \
-ccache clang cmake doxygen dvipng flex gcc git graphviz \
-imagemagick libboost-all-dev libboost-python-dev libbz2-dev \
-libmpfr-dev libgmp-dev libmotif-dev libreadline-dev \
-libqwt-dev libtool libx11-dev libxaw7-dev libxml2-dev \
-python2.7 python2.7-dev \
-libxpm-dev libxt-dev python3.7 python3-jinja2 python3-pip \
-python3-setuptools python-dev python-qt4 python-sphinx \
-qt4-dev-tools rapidjson-dev tcl tcl-dev tcl-tclreadline \
-texlive texlive-fonts-extra texlive-lang-french \
-texlive-latex-extra texlive-pictures xfig yosys zlib1g-dev
-
-# yeah don't add systemd in a chroot.  not funny joke
-apt-get remove -y systemd
-
-# Create user with same UID in the chroot
-useradd -m -p `python3 -c 'import crypt; print (crypt.crypt("1234","Fx"))'` \
-                -s /bin/bash $SUDO_USER -k /etc/skel
-echo -e "
-Added user ${SUDO_USER} with \e[1;91mpassword: 1234\e[0m"
-
-echo -e "
-\e[1;91mPlease use command 'passwd ${SUDO_USER}' to change this immediately after this script is run for security purposes.\e[0m
+    echo "See https://libre-soc.org/HDL_workflow/coriolis2/ for more info.
 "
+    exit
+fi
 
-# Add convenience variable to chroot user .bash_profile
-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
-chown $SUDO_USER /home/$SUDO_USER/.bash_profile
-chgrp $SUDO_USER /home/$SUDO_USER/.bash_profile
-
-echo -e "Added 'export PATH=/usr/lib/ccache:\"\044PATH\"\nexport DISPLAY=:0.0' to /home/$SUDO_USER/.bash_profile to speed up rebuilds"
-EOF
-
-# Build and install yosys from source
-# note that a specific version of yosys is needed for ls180 at the moment
-chroot /opt/chroot/coriolis /bin/bash << EOF
-apt-get update -y 
-apt-get build-dep yosys -y
-apt-get remove yosys -y
-EOF
-runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
-cd /home/$SUDO_USER
-git clone https://github.com/cliffordwolf/yosys.git
-cd yosys
-git checkout 049e3abf9baf795e69b9ecb9c4f19de6131f8418
-make config-clang
-make -j$(nproc)
-EOF'
-
-chroot /opt/chroot/coriolis /bin/bash << EOF
-cd /home/$SUDO_USER/yosys
-make install
-EOF
-
-# Install coriolis2 from source
-runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
-cd /home/$SUDO_USER
-source .bash_profile
-mkdir -p /home/$SUDO_USER/coriolis-2.x/src
-cd /home/$SUDO_USER/coriolis-2.x/src
-git clone https://gitlab.lip6.fr/vlsi-eda/coriolis.git
-cd coriolis
-git checkout devel
-./bootstrap/ccb.py --project=coriolis --make="-j$(nproc) install"
-
-# Setup and test coriolisenv
-/home/$SUDO_USER/coriolis-2.x/src/coriolis/bootstrap/coriolisEnv.py > /home/$SUDO_USER/coriolisenv
-source /home/$SUDO_USER/.bash_profile
-source /home/$SUDO_USER/coriolisenv
-EOF'
+echo "Creating a new chroot \"$chroot_name\" using \"mk-deb-chroot\""
+./mk-deb-chroot $chroot_name
+echo "Copying scripts to chroot \"$chroot_name\" using \"cp-scripts-to-chroot\""
+./cp-scripts-to-chroot $chroot_name
 
-# Install alliance from source
-runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash <<    EOF
-cd /home/$SUDO_USER
-source coriolisenv
-git clone https://gitlab.lip6.fr/vlsi-eda/alliance.git
-mkdir -p /home/$SUDO_USER/alliance/build /home/$SUDO_USER/alliance/install
-mv alliance/alliance/src alliance
-rm -rf alliance/alliance
-cd alliance/src
-./autostuff
-cd /home/$SUDO_USER/alliance/build
-../src/configure --prefix=/home/$SUDO_USER/alliance/install --enable-alc-shared
-EOF'
+# Run coriolis installation script as a normal user
+echo "Entering \"$chroot_name\" and setting Coriolis and its dependencies!"
+runuser $SUDO_USER -c "schroot -c $chroot_name --directory=/tmp /bin/bash << EOF
+cd /home/$SUDO_USER/dev-env-setup
+./coriolis-install
+EOF"
 
-chroot /opt/chroot/coriolis /bin/bash << EOF
-cd /home/$SUDO_USER/alliance/build
-source /home/$SUDO_USER/coriolisenv
-make -j1 install
-EOF
 
-# Install and configure alliance-check-toolkit
-runuser $SUDO_USER --preserve-environment -c 'schroot -c coriolis /bin/bash << EOF
-cd /home/$SUDO_USER
-git clone https://gitlab.lip6.fr/vlsi-eda/alliance-check-toolkit.git
-source coriolisenv
-touch alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
-cat <<EOG >>alliance-check-toolkit/etc/mk/users.d/user-$SUDO_USER.mk
-export CORIOLIS_TOP=/home/$SUDO_USER/coriolis-2.x/Linux.x86_64/Release.Shared/install
-export ALLIANCE_TOP=/home/$SUDO_USER/alliance/install
-export CHECK_TOOLKIT=/home/$SUDO_USER/alliance-check-toolkit
-export YOSYS_TOP=/home/$SUDO_USER/yosys
-EOG
-source /home/$SUDO_USER/.bash_profile
-cd alliance-check-toolkit/benchs/ARM/cmos
-make lvx
+echo "Your new Coriolis chroot should now be setup and ready to go!"
+echo -e "
+${RED}To get inside the new chroot, execute the following (as normal user):${NC}"
 echo -e "
-\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
+${RED}schroot -c $chroot_name --directory=/home/$SUDO_USER${NC}
 "
-make cgt
-EOF'