Use arithmetic comparisons where possible

This commit is contained in:
Jordan Carlin 2024-07-20 00:45:10 -07:00
parent c3614aa189
commit f68cb47a55
No known key found for this signature in database
3 changed files with 30 additions and 30 deletions

View File

@ -49,27 +49,27 @@ test -e /etc/os-release && os_release="/etc/os-release" || os_release="/usr/lib/
source "$os_release"
# Check for compatible distro
if [[ "$ID" = rhel || "$ID_LIKE" = *rhel* ]]; then
FAMILY=rhel
if [[ "$ID" == rhel || "$ID_LIKE" == *rhel* ]]; then
export FAMILY=rhel
if [ "$ID" != rhel ] && [ "$ID" != rocky ] && [ "$ID" != almalinux ]; then
printf "${WARNING_COLOR}%s\n${ENDC}" "For Red Hat family distros, the Wally install script has only been tested on RHEL, Rocky Linux," \
" and AlmaLinux. Your distro is $PRETTY_NAME. The regular Red Hat install will be attempted, but there will likely be issues."
fi
if [ "${VERSION_ID:0:1}" = 8 ]; then
RHEL_VERSION=8
elif [ "${VERSION_ID:0:1}" = 9 ]; then
RHEL_VERSION=9
if (( "${VERSION_ID:0:1}" == 8 )); then
export RHEL_VERSION=8
elif (( "${VERSION_ID:0:1}" = 9 )); then
export RHEL_VERSION=9
else
echo "${FAIL_COLOR}The Wally install script is only compatible with versions 8 and 9 of RHEL, Rocky Linux, and AlmaLinux. You have version $VERSION.${ENDC}"
exit 1
fi
elif [[ "$ID" = ubuntu || "$ID_LIKE" = *ubuntu* ]]; then
FAMILY=ubuntu
elif [[ "$ID" == ubuntu || "$ID_LIKE" == *ubuntu* ]]; then
export FAMILY=ubuntu
if [ "$ID" != ubuntu ]; then
printf "${WARNING_COLOR}%s\n${ENDC}" "For Ubuntu family distros, the Wally install script has only been tested on standard Ubuntu. Your distro " \
"is $PRETTY_NAME. The regular Ubuntu install will be attempted, but there may be issues."
else
UBUNTU_VERSION="${VERSION_ID:0:2}"
export UBUNTU_VERSION="${VERSION_ID:0:2}"
if (( UBUNTU_VERSION < 20 )); then
echo "${FAIL_COLOR}The Wally install script is only compatible with versions 20.04, 22.04, and 24.04 of Ubuntu. You have version $VERSION.${ENDC}"
exit 1

View File

@ -45,7 +45,7 @@ fi
# Generate list of packages to install and package manager commands based on distro
# Packages are grouped by which tool requires them. If multiple tools need a package, it is included in the first tool only
if [ "$FAMILY" = rhel ]; then
if [ "$FAMILY" == rhel ]; then
PACKAGE_MANAGER="dnf"
UPDATE_COMMAND="sudo dnf update -y"
GENERAL_PACKAGES="which rsync git make cmake python3.12 python3-pip curl wget ftp tar pkgconf-pkg-config dialog mutt ssmtp"
@ -55,13 +55,13 @@ if [ "$FAMILY" = rhel ]; then
VERILATOR_PACKAGES="help2man perl clang ccache gperftools numactl mold"
BUILDROOT_PACKAGES="ncurses-base ncurses ncurses-libs ncurses-devel gcc-gfortran"
# Extra packages not availale in rhel8, nice for Verilator and needed for sail respectively
if [ "$RHEL_VERSION" = 9 ]; then
if (( RHEL_VERSION == 9 )); then
VERILATOR_PACKAGES="$VERILATOR_PACKAGES perl-doc"
SAIL_PACKAGES="z3"
fi
# A newer version of gcc is required for qemu
OTHER_PACKAGES="gcc-toolset-13"
elif [ "$FAMILY" = ubuntu ]; then
elif [ "$FAMILY" == ubuntu ]; then
PACKAGE_MANAGER=apt-get
UPDATE_COMMAND="sudo apt-get update -y && sudo apt-get upgrade -y --with-new-pkgs"
GENERAL_PACKAGES="rsync git make cmake python3 python3-pip python3-venv curl wget ftp tar pkg-config dialog mutt ssmtp"
@ -76,25 +76,25 @@ elif [ "$FAMILY" = ubuntu ]; then
VERILATOR_PACKAGES="$VERILATOR_PACKAGES mold"
fi
# Newer version of gcc needed for Ubuntu 20.04 for Verilator
if [ "$UBUNTU_VERSION" = 20 ]; then
if (( UBUNTU_VERSION == 20 )); then
OTHER_PACKAGES="gcc-10 g++-10 cpp-10"
fi
fi
# Check if required packages are installed or install/update them depending on passed flag.
if [ "${1}" = "--check" ]; then
if [ "${1}" == "--check" ]; then
printf "${SECTION_COLOR}%$(tput cols)s" | tr ' ' '#'
printf "%$(tput cols)s" | tr ' ' '#'
echo -e "Checking Dependencies from Package Manager"
printf "%$(tput cols)s" | tr ' ' '#'
printf "%$(tput cols)s${ENDC}" | tr ' ' '#'
if [ "$FAMILY" = rhel ]; then
if [ "$FAMILY" == rhel ]; then
for pack in $GENERAL_PACKAGES $GNU_PACKAGES $QEMU_PACKAGES $SPIKE_PACKAGES $VERILATOR_PACKAGES $SAIL_PACKAGES $BUILDROOT_PACKAGES $OTHER_PACKAGES; do
rpm -q "$pack" > /dev/null || (echo -e "${FAIL_COLOR}Missing packages detected (${WARNING_COLOR}$pack${FAIL_COLOR}). Run as root to auto-install or run wally-package-install.sh first.${ENDC}" && exit 1)
done
elif [ "$FAMILY" = ubuntu ]; then
elif [ "$FAMILY" == ubuntu ]; then
for pack in $GENERAL_PACKAGES $GNU_PACKAGES $QEMU_PACKAGES $SPIKE_PACKAGES $VERILATOR_PACKAGES $SAIL_PACKAGES $BUILDROOT_PACKAGES $OTHER_PACKAGES; do
dpkg -l "$pack" | grep "ii" > /dev/null || (echo -e "${FAIL_COLOR}Missing packages detected (${WARNING_COLOR}$pack${FAIL_COLOR}). Run as root to auto-install or run wally-package-install.sh first." && exit 1)
done
@ -111,14 +111,14 @@ else
printf "%$(tput cols)s${ENDC}" | tr ' ' '#'
# Enable extra repos necessary for rhel
if [ "$FAMILY" = rhel ]; then
if [ "$FAMILY" == rhel ]; then
sudo dnf install -y dnf-plugins-core
sudo dnf group install -y "Development Tools"
if [ "$ID" = rhel ]; then
if [ "$ID" == rhel ]; then
sudo subscription-manager repos --enable "codeready-builder-for-rhel-$RHEL_VERSION-$(arch)-rpms"
sudo dnf install -y "https://dl.fedoraproject.org/pub/epel/epel-release-latest-$RHEL_VERSION.noarch.rpm"
else # RHEL clone
if [ "$RHEL_VERSION" = 8 ]; then
if (( RHEL_VERSION == 8 )); then
sudo dnf config-manager -y --set-enabled powertools
else # Version 9
sudo dnf config-manager -y --set-enabled crb

View File

@ -86,13 +86,13 @@ dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${dir}"/wally-distro-check.sh
# Check if root
ROOT=$( [ "${EUID:=$(id -u)}" = 0 ] && echo true || echo false);
ROOT=$( [ "${EUID:=$(id -u)}" == 0 ] && echo true || echo false);
# Set installation directory based on execution privileges
# If the script is run as root, the default installation path is /opt/riscv
# If the script is run as a user, the default installation path is ~/riscv
# The installation path can be overridden with an argument passed to the script.
if [ "$ROOT" = true ]; then
if [ "$ROOT" == true ]; then
export RISCV="${1:-/opt/riscv}"
else
export RISCV="${1:-$HOME/riscv}"
@ -110,16 +110,16 @@ echo "Installation path: $RISCV"
# Install/update system packages if root. Otherwise, check that packages are already installed.
STATUS="system packages"
if [ "$ROOT" = true ]; then
if [ "$ROOT" == true ]; then
source "${dir}"/wally-package-install.sh
else
source "${dir}"/wally-package-install.sh --check
fi
# Enable newer version of gcc for older distros (required for QEMU/Verilator)
if [ "$FAMILY" = rhel ]; then
if [ "$FAMILY" == rhel ]; then
source /opt/rh/gcc-toolset-13/enable
elif [ "$UBUNTU_VERSION" = 20 ]; then
elif (( UBUNTU_VERSION == 20 )); then
mkdir -p "$RISCV"/gcc-10/bin
for f in gcc cpp g++ gcc-ar gcc-nm gcc-ranlib gcov gcov-dump gcov-tool lto-dump; do
ln -vsf /usr/bin/$f-10 "$RISCV"/gcc-10/bin/$f
@ -154,7 +154,7 @@ pip install -U sphinx sphinx_rtd_theme matplotlib scipy scikit-learn adjustText
pip install -U riscv_isac # to generate new tests, such as quads with fp_dataset.py
# z3 is needed for sail and not availabe from dnf for rhel 8
if [ "$RHEL_VERSION" = 8 ]; then
if (( RHEL_VERSION == 8 )); then
pip install -U z3-solver
fi
@ -163,7 +163,7 @@ echo -e "${SUCCESS_COLOR}Python environment successfully configured.${ENDC}"
# Extra dependecies needed for older distros that don't have new enough versions available from package manager
if [ "$RHEL_VERSION" = 8 ] || [ "$UBUNTU_VERSION" = 20 ]; then
if (( RHEL_VERSION == 8 )) || (( UBUNTU_VERSION == 20 )); then
# Newer versin of glib required for Qemu.
# Anything newer than this won't build on red hat 8
STATUS="glib"
@ -185,7 +185,7 @@ if [ "$RHEL_VERSION" = 8 ] || [ "$UBUNTU_VERSION" = 20 ]; then
fi
# Newer version of gmp needed for sail-riscv model
if [ "$RHEL_VERSION" = 8 ]; then
if (( RHEL_VERSION == 8 )); then
STATUS="gmp"
if [ ! -e "$RISCV"/include/gmp.h ]; then
section_header "Installing gmp"
@ -308,7 +308,7 @@ fi
cd "$RISCV"
if [ "$FAMILY" = rhel ]; then
if [ "$FAMILY" == rhel ]; then
# Install opam from binary disribution on rhel as it is not available from dnf
# Opam is needed to install the sail compiler
section_header "Installing/Updating Opam"
@ -392,10 +392,10 @@ if [ ! -e "${RISCV}"/site-setup.sh ]; then
wget https://raw.githubusercontent.com/openhwgroup/cvw/main/site-setup.sh
wget https://raw.githubusercontent.com/openhwgroup/cvw/main/site-setup.csh
# Add necessary lines to site-setup script to activate newer version of gcc for older distros
if [ "$FAMILY" = rhel ]; then
if [ "$FAMILY" == rhel ]; then
echo "# Activate newer gcc version" >> site-setup.sh
echo "source /opt/rh/gcc-toolset-13/enable" >> site-setup.sh
elif [ "$UBUNTU_VERSION" = 20 ]; then
elif (( UBUNTU_VERSION == 20 )); then
echo "# Activate newer gcc version" >> site-setup.sh
echo "export PATH=\$RISCV/gcc-10/bin:\$PATH" >> site-setup.sh
echo "# Activate newer gcc version" >> site-setup.csh