From f66938e35576fcb3cf501643c4a4914fd54054db Mon Sep 17 00:00:00 2001 From: Henrik Grimler Date: Tue, 1 Mar 2022 09:01:55 +0100 Subject: [PATCH] scripts/build/setup: add termux_setup_nodejs function To be used by packages that need nodejs during build (gitea and frida-server for example). Use LTS version for now (gitea had issues with latest version). --- build-package.sh | 4 +++ scripts/build/setup/termux_setup_nodejs.sh | 42 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 scripts/build/setup/termux_setup_nodejs.sh diff --git a/build-package.sh b/build-package.sh index 92e9a2294..5c03fe95d 100755 --- a/build-package.sh +++ b/build-package.sh @@ -75,6 +75,10 @@ source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_zig.sh" # shellcheck source=scripts/build/setup/termux_setup_ninja.sh source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_ninja.sh" +# Utility function to setup a current ninja build system. +# shellcheck source=scripts/build/setup/termux_setup_nodejs.sh +source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_nodejs.sh" + # Utility function to setup a current meson build system. # shellcheck source=scripts/build/setup/termux_setup_meson.sh source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_meson.sh" diff --git a/scripts/build/setup/termux_setup_nodejs.sh b/scripts/build/setup/termux_setup_nodejs.sh new file mode 100644 index 000000000..b1473c97e --- /dev/null +++ b/scripts/build/setup/termux_setup_nodejs.sh @@ -0,0 +1,42 @@ +termux_setup_nodejs() { + # Use LTS version for now + local NODEJS_VERSION=16.14.0 + local NODEJS_FOLDER + + if [ "${TERMUX_PACKAGES_OFFLINE-false}" = "true" ]; then + NODEJS_FOLDER=${TERMUX_SCRIPTDIR}/build-tools/nodejs-${NODEJS_VERSION} + else + NODEJS_FOLDER=${TERMUX_COMMON_CACHEDIR}/nodejs-$NODEJS_VERSION + fi + + if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then + if [ ! -x "$NODEJS_FOLDER/nodejs" ]; then + mkdir -p "$NODEJS_FOLDER" + local NODEJS_TAR_FILE=$TERMUX_PKG_TMPDIR/nodejs-$NODEJS_VERSION.tar.xz + termux_download https://nodejs.org/dist/v${NODEJS_VERSION}/node-v${NODEJS_VERSION}-linux-x64.tar.xz \ + "$NODEJS_TAR_FILE" \ + 0570b9354959f651b814e56a4ce98d4a067bf2385b9a0e6be075739bc65b0fae + tar -xf "$NODEJS_TAR_FILE" -C "$NODEJS_FOLDER" --strip-components=1 + fi + export PATH=$NODEJS_FOLDER/bin:$PATH + else + local NODEJS_PKG_VERSION=$(bash -c ". $TERMUX_SCRIPTDIR/packages/nodejs/build.sh; echo \$TERMUX_PKG_VERSION") + if ([ ! -e "$TERMUX_BUILT_PACKAGES_DIRECTORY/nodejs" ] || + [ "$(cat "$TERMUX_BUILT_PACKAGES_DIRECTORY/nodejs")" != "$NODEJS_PKG_VERSION" ]) && + ([[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "debian" && "$(dpkg-query -W -f '${db:Status-Status}\n' nodejs 2>/dev/null)" != "installed" ]] || + [[ "$TERMUX_MAIN_PACKAGE_FORMAT" = "pacman" && ! "$(pacman -Q nodejs 2>/dev/null)" ]]); then + echo "Package 'nodejs' is not installed." + echo "You can install it with" + echo + echo " pkg install nodejs" + echo + echo " pacman -S nodejs" + echo + echo "or build it from source with" + echo + echo " ./build-package.sh nodejs" + echo + exit 1 + fi + fi +}