From 18755282e71d7184f512ce7474f7286a5f4431dd Mon Sep 17 00:00:00 2001 From: OBarronCS <55004530+OBarronCS@users.noreply.github.com> Date: Fri, 18 Apr 2025 04:11:40 -0700 Subject: [PATCH] Dev setup - check if Zig/jemalloc are already installed before downloading (#2899) * Check if Zig/jemalloc are already installed before downloading * reformat --- setup-dev.sh | 112 +++++++++++++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/setup-dev.sh b/setup-dev.sh index d6f26a341..9ac7e8228 100755 --- a/setup-dev.sh +++ b/setup-dev.sh @@ -92,21 +92,26 @@ download_zig_binary() { # Install zig to current directory # We use zig to compile some test binaries as it is much easier than with gcc - ZIG_TAR_URL="https://ziglang.org/download/0.10.1/zig-linux-x86_64-0.10.1.tar.xz" - ZIG_TAR_SHA256="6699f0e7293081b42428f32c9d9c983854094bd15fee5489f12c4cf4518cc380" - curl --output /tmp/zig.tar.xz "${ZIG_TAR_URL}" - ACTUAL_SHA256=$(sha256sum /tmp/zig.tar.xz | cut -d' ' -f1) - if [ "${ACTUAL_SHA256}" != "${ZIG_TAR_SHA256}" ]; then - echo "Zig binary checksum mismatch" - echo "Expected: ${ZIG_TAR_SHA256}" - echo "Actual: ${ACTUAL_SHA256}" - exit 1 - fi + if command -v "${ZIGPATH}"/zig &> /dev/null; then + echo "Zig is already installed. Skipping build and install." + else + echo "Downloading and installing Zig..." + ZIG_TAR_URL="https://ziglang.org/download/0.10.1/zig-linux-x86_64-0.10.1.tar.xz" + ZIG_TAR_SHA256="6699f0e7293081b42428f32c9d9c983854094bd15fee5489f12c4cf4518cc380" + curl --output /tmp/zig.tar.xz "${ZIG_TAR_URL}" + ACTUAL_SHA256=$(sha256sum /tmp/zig.tar.xz | cut -d' ' -f1) + if [ "${ACTUAL_SHA256}" != "${ZIG_TAR_SHA256}" ]; then + echo "Zig binary checksum mismatch" + echo "Expected: ${ZIG_TAR_SHA256}" + echo "Actual: ${ACTUAL_SHA256}" + exit 1 + fi - tar -C /tmp -xJf /tmp/zig.tar.xz + tar -C /tmp -xJf /tmp/zig.tar.xz - mv /tmp/zig-linux-x86_64-* ${ZIGPATH} &> /dev/null || true - echo "Zig installed to ${ZIGPATH}" + mv /tmp/zig-linux-x86_64-* ${ZIGPATH} &> /dev/null || true + echo "Zig installed to ${ZIGPATH}" + fi } install_apt() { @@ -221,61 +226,62 @@ install_dnf() { install_jemalloc() { - # Install jemalloc version 5.3.0 - JEMALLOC_TAR_URL="https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2" - JEMALLOC_TAR_SHA256="2db82d1e7119df3e71b7640219b6dfe84789bc0537983c3b7ac4f7189aecfeaa" - JEMALLOC_TAR_PATH="/tmp/jemalloc-5.3.0.tar.bz2" - JEMALLOC_EXTRACT_PATH="/tmp/jemalloc-5.3.0" - - # Check if jemalloc tarball already exists and has the correct checksum - if [ -f "${JEMALLOC_TAR_PATH}" ]; then - ACTUAL_SHA256=$(sha256sum "${JEMALLOC_TAR_PATH}" | cut -d' ' -f1) - if [ "${ACTUAL_SHA256}" != "${JEMALLOC_TAR_SHA256}" ]; then - echo "Jemalloc tarball exists but has incorrect checksum. Re-downloading..." + # Check if jemalloc is already installed + if command -v jemalloc-config &> /dev/null; then + echo "Jemalloc already installed. Skipping build and install." + else + echo "Jemalloc not found in system. Downloading, configuring, building, and installing..." + + # Install jemalloc version 5.3.0 + JEMALLOC_TAR_URL="https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2" + JEMALLOC_TAR_SHA256="2db82d1e7119df3e71b7640219b6dfe84789bc0537983c3b7ac4f7189aecfeaa" + JEMALLOC_TAR_PATH="/tmp/jemalloc-5.3.0.tar.bz2" + JEMALLOC_EXTRACT_PATH="/tmp/jemalloc-5.3.0" + + # Check if jemalloc tarball already exists and has the correct checksum + if [ -f "${JEMALLOC_TAR_PATH}" ]; then + ACTUAL_SHA256=$(sha256sum "${JEMALLOC_TAR_PATH}" | cut -d' ' -f1) + if [ "${ACTUAL_SHA256}" != "${JEMALLOC_TAR_SHA256}" ]; then + echo "Jemalloc tarball exists but has incorrect checksum. Re-downloading..." + curl --location --output "${JEMALLOC_TAR_PATH}" "${JEMALLOC_TAR_URL}" + ACTUAL_SHA256=$(sha256sum "${JEMALLOC_TAR_PATH}" | cut -d' ' -f1) + if [ "${ACTUAL_SHA256}" != "${JEMALLOC_TAR_SHA256}" ]; then + echo "Jemalloc binary checksum mismatch after re-download." + echo "Expected: ${JEMALLOC_TAR_SHA256}" + echo "Actual: ${ACTUAL_SHA256}" + exit 1 + fi + else + echo "Jemalloc tarball already exists and has correct checksum. Skipping download." + fi + else + echo "Downloading jemalloc..." curl --location --output "${JEMALLOC_TAR_PATH}" "${JEMALLOC_TAR_URL}" ACTUAL_SHA256=$(sha256sum "${JEMALLOC_TAR_PATH}" | cut -d' ' -f1) if [ "${ACTUAL_SHA256}" != "${JEMALLOC_TAR_SHA256}" ]; then - echo "Jemalloc binary checksum mismatch after re-download." + echo "Jemalloc binary checksum mismatch" echo "Expected: ${JEMALLOC_TAR_SHA256}" echo "Actual: ${ACTUAL_SHA256}" exit 1 fi - else - echo "Jemalloc tarball already exists and has correct checksum. Skipping download." - fi - else - echo "Downloading jemalloc..." - curl --location --output "${JEMALLOC_TAR_PATH}" "${JEMALLOC_TAR_URL}" - ACTUAL_SHA256=$(sha256sum "${JEMALLOC_TAR_PATH}" | cut -d' ' -f1) - if [ "${ACTUAL_SHA256}" != "${JEMALLOC_TAR_SHA256}" ]; then - echo "Jemalloc binary checksum mismatch" - echo "Expected: ${JEMALLOC_TAR_SHA256}" - echo "Actual: ${ACTUAL_SHA256}" - exit 1 fi - fi - # Check if jemalloc source code has already been extracted - if [ -d "${JEMALLOC_EXTRACT_PATH}" ]; then - echo "Jemalloc source code already extracted. Skipping extraction." - else - echo "Extracting jemalloc..." - tar -C /tmp -xf "${JEMALLOC_TAR_PATH}" - fi + # Check if jemalloc source code has already been extracted + if [ -d "${JEMALLOC_EXTRACT_PATH}" ]; then + echo "Jemalloc source code already extracted. Skipping extraction." + else + echo "Extracting jemalloc..." + tar -C /tmp -xf "${JEMALLOC_TAR_PATH}" + fi - # Check if jemalloc is already installed - if ! command -v jemalloc-config &> /dev/null; then - echo "Jemalloc not found in system. Configuring, building, and installing..." pushd "${JEMALLOC_EXTRACT_PATH}" ./configure make sudo make install popd - else - echo "Jemalloc already installed. Skipping build and install." - fi - echo "Jemalloc installation complete." + echo "Jemalloc installation complete." + fi # TODO: autoconf needs to be installed with script as well? } @@ -323,7 +329,7 @@ if linux; then . /etc/os-release echo ${VERSION_ID} version ) - install_dnf $fedora_verion + install_dnf $fedora_version ;; *) # we can add more install command for each distros. echo "\"$distro\" is not supported distro. Will search for 'apt' or 'pacman' package managers."