Skip to content

Instantly share code, notes, and snippets.

@NewEraCracker
Created June 1, 2023 11:57
Show Gist options
  • Save NewEraCracker/43533159b9e56b77ce6895f8d0b6d4de to your computer and use it in GitHub Desktop.
Save NewEraCracker/43533159b9e56b77ce6895f8d0b6d4de to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
OPENSSL_VER=1.1.1u
OPENSSL_DIR="/opt/openssl-$OPENSSL_VER"
OPENSSL_URL="https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz"
# OPENSSL_VER=1_1_1u+quic
# OPENSSL_DIR="/opt/openssl-$OPENSSL_VER"
# OPENSSL_URL="https://github.com/quictls/openssl/archive/OpenSSL_$OPENSSL_VER.tar.gz"
NODEJS_VER=18.16.0
NODEJS_DIR="/opt/nodejs-$NODEJS_VER"
NODEJS_URL="https://nodejs.org/dist/v$NODEJS_VER/node-v$NODEJS_VER.tar.gz"
CPU_CORES=$(nproc || grep -c ^processor /proc/cpuinfo || true)
CPU_CORES=${CPU_CORES:-2}
# Store the current directory
ORIG_PWD=$(pwd)
# Check if OpenSSL is already installed
if [ -d "$OPENSSL_DIR" ]; then
echo "OpenSSL is already installed at $OPENSSL_DIR"
else
# Download OpenSSL
mkdir -p "/tmp/openssl_$OPENSSL_VER"
cd "/tmp/openssl_$OPENSSL_VER"
curl -sL "$OPENSSL_URL" | tar zxv --strip=1 -C "/tmp/openssl_$OPENSSL_VER"
# Compile OpenSSL
./config --prefix="$OPENSSL_DIR" --openssldir="$OPENSSL_DIR"
make -j "$CPU_CORES"
make install
cd && rm -rf "/tmp/openssl_$OPENSSL_VER"
fi
# Check if Node.js is already installed
if [ -d "$NODEJS_DIR" ]; then
echo "Node.js is already installed at $NODEJS_DIR"
else
# Download Node.js
mkdir -p "/tmp/nodejs_$NODEJS_VER"
cd "/tmp/nodejs_$NODEJS_VER"
curl -sL "$NODEJS_URL" | tar zxv --strip=1 -C "/tmp/nodejs_$NODEJS_VER"
# Compile Node.js with shared OpenSSL
./configure --prefix="$NODEJS_DIR" --verbose --shared-openssl --shared-openssl-includes="$OPENSSL_DIR/include/" --shared-openssl-libpath="$OPENSSL_DIR/lib/"
make -j "$CPU_CORES"
make install
cd && rm -rf "/tmp/nodejs_$NODEJS_VER"
fi
# Return to the original directory
cd "$ORIG_PWD"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment