#!/usr/bin/env sh set -e argv_0=$0 projectdir=$(dirname $0) projectdir=$(readlink -f "$projectdir") tmp_dir="$projectdir/.blaze" bun_dir="$tmp_dir/bun" bun="bun" has_curl=$(command -v curl) has_wget=$(command -v wget) if [ -z "$has_curl" ] && [ -z "$has_wget" ]; then echo "error: No curl or wget found. Please install one of them." exit 1 fi mkdir -p "$tmp_dir" getprop() { value=$(cat "$projectdir/blaze/wrapper/blaze_wrapper.properties" | grep "$1" | cut -d'=' -f2) echo $value } print() { printf "\033[${1}m$2\033[0m" printf " $3\n" } blaze_srcpath=$(getprop "blaze.srcpath") blaze_srcpath=$(readlink -f "$blaze_srcpath") if [ -z "$blaze_srcpath" ]; then print "31" "error" "blaze.srcpath is not set in blaze_wrapper.properties" exit 1 fi pushd() { if [ -z "$1" ]; then return 1 fi if [ -z "$DIRSTACK" ]; then DIRSTACK="$1" else DIRSTACK="$1:$DIRSTACK" fi cd "$1" } popd() { if [ -z "$DIRSTACK" ]; then return 1 fi cd "$(echo "$DIRSTACK" | cut -d: -f1)" DIRSTACK=$(echo "$DIRSTACK" | cut -d: -f2-) } summary() { title=$1 if [ -z "$title" ]; then title="Final" fi printf "\033[1m -- $title Configuration Summary -- \033[0m\n\n" print "32" "info" "Project root directory: $projectdir" print "32" "info" "BlazeBuild directory: $blaze_srcpath" print "32" "info" "Temporary directory: $tmp_dir" print "32" "info" "Bun executable: $bun" printf "\n" } bun_run_installer() { rm -rf "$bun_dir" mkdir -p "$bun_dir" if [ ! -z "$has_curl" ]; then export BUN_INSTALL="$bun_dir" && export PATH="$BUN_INSTALL":"$PATH":"$BUN_INSTALL" && export SHELL=blazew && (curl -fsSL https://bun.sh/install | bash -s "bun-v$1") >"$tmp_dir/bun_install.log" 2>&1 else export BUN_INSTALL="$bun_dir" && export PATH="$BUN_INSTALL":"$PATH":"$BUN_INSTALL" && export SHELL=blazew && (wget -qO- https://bun.sh/install | bash -s "bun-v$1") >"$tmp_dir/bun_install.log" 2>&1 fi bun="$bun_dir/bin/bun" } install_bun() { local bun_version=$(getprop "bun.version") if [ -z "$bun_version" ]; then print "31" "error" "bun.version is not set in blaze_wrapper.properties" exit 1 fi export PATH="$bun_dir/bin":"$PATH":"$bun_dir/bin" if [ -z "$(command -v bun)" ]; then print "33" "warn" "Could not find bun installation" print "32" "info" "Installing bun" bun_run_installer $bun_version else existing_version=$(bun --version) if [ "$existing_version" != "$bun_version" ]; then print "33" "warn" "Bun version mismatch in existing installation: required $bun_version, found $existing_version" print "32" "info" "Installing bun version: $bun_version" bun_run_installer $bun_version else bun="$(command -v bun)" fi fi } if [ "$BLAZEW_DEBUG" = "1" ]; then summary "Initial" fi install_bun if [ "$BLAZEW_DEBUG" = "1" ]; then printf "\n" summary fi $bun $projectdir/blaze/wrapper/blaze_wrapper.js $@