From f7ca17135e3a6c6e3a969de7278e300986d49594 Mon Sep 17 00:00:00 2001 From: Andy Fingerhut Date: Sat, 22 Oct 2022 05:21:08 -0400 Subject: [PATCH 1/3] Add a script to automate installation on base OS --- tools/setup/install.sh | 135 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100755 tools/setup/install.sh diff --git a/tools/setup/install.sh b/tools/setup/install.sh new file mode 100755 index 0000000..d96aaa7 --- /dev/null +++ b/tools/setup/install.sh @@ -0,0 +1,135 @@ +#! /bin/bash + +# Remember the current directory when the script was started: +SCRIPT_START_DIR="${PWD}" + +THIS_SCRIPT_FILE_MAYBE_RELATIVE="$0" +THIS_SCRIPT_DIR_MAYBE_RELATIVE="${THIS_SCRIPT_FILE_MAYBE_RELATIVE%/*}" +THIS_SCRIPT_DIR_ABSOLUTE=`readlink -f "${THIS_SCRIPT_DIR_MAYBE_RELATIVE}"` + +os_version_warning() { + 1>&2 echo "This software has only been tested on these systems:" + 1>&2 echo " Fedora 34" + 1>&2 echo " Ubuntu 22.04" + 1>&2 echo "" + 1>&2 echo "Proceed installing manually at your own risk of" + 1>&2 echo "significant time spent figuring out how to make it all" + 1>&2 echo "work, or consider getting VirtualBox and creating an" + 1>&2 echo "appropriate virtual machine with one of the tested versions." +} + +if [ ! -e /etc/os-release ] +then + 1>&2 echo "No file /etc/os-release found. Aborting because we have" + 1>&2 echo "no way to tell which Linux distribution and version you" + 1>&2 echo "are running." + exit 1 +fi + +supported_os=0 +source /etc/os-release +if [ "${NAME}" = "Ubuntu" -a \( "${VERSION_ID}" = "22.04" \) ] +then + echo "Found distribution '${NAME}' version '${VERSION_ID}'. Continuing with installation." + supported_os=1 +fi +if [ "${NAME}" = "Fedora" -a \( "${VERSION_ID}" = "34" \) ] +then + echo "Found distribution '${NAME}' version '${VERSION_ID}'. Continuing with installation." + supported_os=1 +fi + +if [ $supported_os == 0 ] +then + os_version_warning + 1>&2 echo "" + 1>&2 echo "Here are the contents of /etc/os-release:" + cat /etc/os-release + exit 1 +fi + +# Minimum required system memory is 6 GBytes, minus a few MBytes +# because from experiments I have run on several different Ubuntu +# Linux VMs, when you configure them with 2 Gbytes of RAM, the first +# line of /proc/meminfo shows a little less than that available, I +# believe because some memory occupied by the kernel is not shown. + +min_mem_MBytes=`expr 6 \* \( 1024 - 64 \)` +memtotal_KBytes=`head -n 1 /proc/meminfo | awk '{print $2;}'` +memtotal_MBytes=`expr ${memtotal_KBytes} / 1024` + +if [ "${memtotal_MBytes}" -lt "${min_mem_MBytes}" ] +then + memtotal_comment="too low" + abort_script=1 +else + memtotal_comment="enough" +fi + +echo "Minimum recommended memory to run this script: ${min_mem_MBytes} MBytes" +echo "Memory on this system from /proc/meminfo: ${memtotal_MBytes} MBytes -> $memtotal_comment" + +min_free_disk_MBytes=`expr 8 \* 1024` +free_disk_MBytes=`df --output=avail --block-size=1M . | tail -n 1` + +if [ "${free_disk_MBytes}" -lt "${min_free_disk_MBytes}" ] +then + free_disk_comment="too low" + abort_script=1 +else + free_disk_comment="enough" +fi + +echo "Minimum free disk space to run this script: ${min_free_disk_MBytes} MBytes" +echo "Free disk space on this system from df output: ${free_disk_MBytes} MBytes -> $free_disk_comment" + +if [ "${abort_script}" == 1 ] +then + echo "" + echo "Aborting script because system has too little RAM or free disk space" + exit 1 +fi + +cd "${THIS_SCRIPT_DIR_ABSOLUTE}" +source p4sde_env_setup.sh $HOME/sde + +if [ "${NAME}" = "Ubuntu" ] +then + sudo apt update + + # Install Wireshark and tshark on Ubuntu system without having to + # answer _any_ questions interactively, except perhaps providing + # your password when prompted by 'sudo'. + # https://askubuntu.com/questions/1275842/install-wireshark-without-confirm + echo "wireshark-common wireshark-common/install-setuid boolean true" | sudo debconf-set-selections + sudo DEBIAN_FRONTEND=noninteractive apt-get -y install wireshark tshark + + sudo apt-get -y install python3-pip +fi + +pip3 install distro + +mkdir -p $SDE_INSTALL +cd $SDE +git clone --depth=1 https://github.com/p4lang/target-utils --recursive utils +git clone --depth=1 https://github.com/p4lang/target-syslibs --recursive syslibs +git clone --depth=1 https://github.com/p4lang/p4-dpdk-target --recursive p4-dpdk-target + +# NOTE: The version of meson installed by running the install_dep.py +# program below on some OS versions is: + +# Ubuntu 20.04 'sudo apt-get install meson' -> meson 0.53.2 ninja 1.10.0 'meson compile'? no +# Ubuntu 22.04 'sudo apt-get install meson' -> meson 0.61.2 ninja 1.10.1 'meson compile'? yes +# Fedora 34 'yum install meson' -> meson 0.62.1 ninja 1.10.2 'meson compile'? yes + +# Without a version of meson that implements the 'compile' +# sub-command, the p4-dpdk-target install script will not work. meson +# 0.61.1 and 0.61.2 appear to be new enough, but 0.53.2 is not. + +sudo -E python3 p4-dpdk-target/tools/setup/install_dep.py +cd $SDE/p4-dpdk-target +git submodule update --init --recursive --force +./autogen.sh +./configure --prefix=$SDE_INSTALL +make -j4 +make install From 2585057c285e14c117029e535b17adf0e5a0e921 Mon Sep 17 00:00:00 2001 From: Andy Fingerhut Date: Sat, 22 Oct 2022 05:51:33 -0400 Subject: [PATCH 2/3] Reduce RAM and disk space required to run the install script --- tools/setup/install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/setup/install.sh b/tools/setup/install.sh index d96aaa7..a1a54dc 100755 --- a/tools/setup/install.sh +++ b/tools/setup/install.sh @@ -48,13 +48,13 @@ then exit 1 fi -# Minimum required system memory is 6 GBytes, minus a few MBytes +# Minimum required system memory is 4 GBytes, minus a few MBytes # because from experiments I have run on several different Ubuntu # Linux VMs, when you configure them with 2 Gbytes of RAM, the first # line of /proc/meminfo shows a little less than that available, I # believe because some memory occupied by the kernel is not shown. -min_mem_MBytes=`expr 6 \* \( 1024 - 64 \)` +min_mem_MBytes=`expr 4 \* \( 1024 - 64 \)` memtotal_KBytes=`head -n 1 /proc/meminfo | awk '{print $2;}'` memtotal_MBytes=`expr ${memtotal_KBytes} / 1024` @@ -69,7 +69,7 @@ fi echo "Minimum recommended memory to run this script: ${min_mem_MBytes} MBytes" echo "Memory on this system from /proc/meminfo: ${memtotal_MBytes} MBytes -> $memtotal_comment" -min_free_disk_MBytes=`expr 8 \* 1024` +min_free_disk_MBytes=`expr 6 \* 1024` free_disk_MBytes=`df --output=avail --block-size=1M . | tail -n 1` if [ "${free_disk_MBytes}" -lt "${min_free_disk_MBytes}" ] From 620a6ddd78b2faee3a7197365bf7756acfffd9d4 Mon Sep 17 00:00:00 2001 From: Andy Fingerhut Date: Mon, 24 Oct 2022 00:42:15 -0400 Subject: [PATCH 3/3] Changes towards enabling this script to work on Fedora versions other than 34 --- tools/setup/install.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/setup/install.sh b/tools/setup/install.sh index a1a54dc..3c3f2ef 100755 --- a/tools/setup/install.sh +++ b/tools/setup/install.sh @@ -28,14 +28,14 @@ fi supported_os=0 source /etc/os-release -if [ "${NAME}" = "Ubuntu" -a \( "${VERSION_ID}" = "22.04" \) ] +if [ "${ID}" = "ubuntu" -a \( "${VERSION_ID}" = "22.04" \) ] then - echo "Found distribution '${NAME}' version '${VERSION_ID}'. Continuing with installation." + echo "Found distribution '${ID}' version '${VERSION_ID}'. Continuing with installation." supported_os=1 fi -if [ "${NAME}" = "Fedora" -a \( "${VERSION_ID}" = "34" \) ] +if [ "${ID}" = "fedora" -a \( "${VERSION_ID}" = "34" -o "${VERSION_ID}" = "36" \) ] then - echo "Found distribution '${NAME}' version '${VERSION_ID}'. Continuing with installation." + echo "Found distribution '${ID}' version '${VERSION_ID}'. Continuing with installation." supported_os=1 fi @@ -93,7 +93,7 @@ fi cd "${THIS_SCRIPT_DIR_ABSOLUTE}" source p4sde_env_setup.sh $HOME/sde -if [ "${NAME}" = "Ubuntu" ] +if [ "${ID}" = "ubuntu" ] then sudo apt update @@ -106,6 +106,10 @@ then sudo apt-get -y install python3-pip fi +if [ "${ID}" = "fedora" ] +then + sudo yum install -y python3-pip +fi pip3 install distro