From eb1cea5e5f22a18a83432bece01292361c953fd4 Mon Sep 17 00:00:00 2001 From: Nameless Date: Tue, 26 Nov 2024 13:06:19 -0600 Subject: [PATCH 1/3] get-lit.sh: improve luvit installation * improve error reporting * improve user facing feedback (such as where to find the binaries) * improve reliability (retry fetching from lit.luvit.io) * allow selecting a luvit version to install * fix for luvit 2.15+ new download url work: cleanup work: add get-lit.ps1 work: clean up download --- get-lit.ps1 | 192 +++++++++++++++++++++++++++++++++++++++++----------- get-lit.sh | 120 +++++++++++++++++++++++++++----- 2 files changed, 256 insertions(+), 56 deletions(-) diff --git a/get-lit.ps1 b/get-lit.ps1 index 7392d97..bb2b326 100644 --- a/get-lit.ps1 +++ b/get-lit.ps1 @@ -1,41 +1,155 @@ +Set-StrictMode -Version Latest -$LUVI_VERSION = "2.14.0" +$LUVI_PREFIX = $PWD + +$LUVI_OS = "Windows" +$LUVI_ARCH = "amd64" +$LUVI_ENGINE = "luajit" + +$LUVI_VERSION = "2.15.0" $LIT_VERSION = "3.8.5" -# Environment variables take precedence -if (test-path env:LUVI_VERSION) { $LUVI_VERSION = $env:LUVI_VERSION } -if (test-path env:LIT_VERSION) { $LIT_VERSION = $env:LIT_VERSION } - -if (test-path env:LUVI_ARCH) { - $LUVI_ARCH = $env:LUVI_ARCH -} else { - if ([System.Environment]::Is64BitProcess) { - $LUVI_ARCH = "Windows-amd64" - } else { - $LUVI_ARCH = "Windows-ia32" - } -} -$LUVI_URL = "https://github.com/luvit/luvi/releases/download/v$LUVI_VERSION/luvi-regular-$LUVI_ARCH.exe" -$LIT_URL = "https://lit.luvit.io/packages/luvit/lit/v$LIT_VERSION.zip" - -function Download-File { - param ( - [string]$url, - [string]$file - ) - [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls12; - Write-Host "Downloading $url to $file" - $downloader = new-object System.Net.WebClient - $downloader.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials; - $downloader.DownloadFile($url, $file) -} - -# Download Files -Download-File $LUVI_URL "luvi.exe" -Download-File $LIT_URL "lit.zip" - -# Create lit.exe using lit -Start-Process ".\luvi.exe" -ArgumentList "lit.zip -- make lit.zip lit.exe luvi.exe" -Wait -NoNewWindow -# Cleanup -Remove-Item "lit.zip" -# Create luvit using lit -Start-Process ".\lit.exe" -ArgumentList "make lit://luvit/luvit luvit.exe luvi.exe" -Wait -NoNewWindow +$LUVIT_VERSION = "latest" + +# Check for environment variable overrides +if ($null -ne $env:LUVI_PREFIX) { $LUVI_PREFIX = $env:LUVI_PREFIX } +if ($null -ne $env:LUVI_OS) { $LUVI_OS = $env:LUVI_OS } +if ($null -ne $env:LUVI_ARCH) { $LUVI_ARCH = $env:LUVI_ARCH } +if ($null -ne $env:LUVI_ENGINE) { $LUVI_ENGINE = $env:LUVI_ENGINE } +if ($null -ne $env:LUVI_VERSION) { $LUVI_VERSION = $env:LUVI_VERSION } +if ($null -ne $env:LIT_VERSION) { $LIT_VERSION = $env:LIT_VERSION } +if ($null -ne $env:LUVIT_VERSION) { $LUVIT_VERSION = $env:LUVIT_VERSION } + +if ($null -eq $env:LUVI_OS) { + # OS detection + if (-not (Get-Variable -Name 'IsWindows' -ErrorAction SilentlyContinue) -or $IsWindows) { + $LUVI_OS = "Windows" + } + elseif ($IsLinux) { + $LUVI_OS = "Linux" + } + elseif ($IsMacOS) { + $LUVI_OS = "Darwin" + } + else { + $LUVI_OS = "$(uname -s)" + } +} + +if ($null -eq $env:LUVI_OS) { + # Architecture detection + if ($null -ne $env:PROCESSOR_ARCHITEW6432) { + $LUVI_ARCH = ($env:PROCESSOR_ARCHITEW6432).ToLower() + } + elseif ($null -ne $env:PROCESSOR_ARCHITECTURE) { + $LUVI_ARCH = ($env:PROCESSOR_ARCHITECTURE).ToLower() + } + else { + $LUVI_ARCH = "$(uname -m)" + } +} + +$exe_suffix = "" +if ($LUVI_OS -eq "Windows") { $exe_suffix = ".exe" } + +$lit_zip = Join-Path "${LUVI_PREFIX}" "lit.zip" +$luvit_zip = Join-Path "${LUVI_PREFIX}" "luvit.zip" +$luvi_bin = Join-Path "${LUVI_PREFIX}" "luvi${exe_suffix}" +$lit_bin = Join-Path "${LUVI_PREFIX}" "lit${exe_suffix}" +$luvit_bin = Join-Path "${LUVI_PREFIX}" "luvit${exe_suffix}" + +function Cleanup([int] $exit_code) { + if (Test-Path $lit_zip) { Remove-Item $lit_zip -Force } + if (Test-Path $luvit_zip) { Remove-Item $luvit_zip -Force } + exit $exit_code +} + +function Download([string] $url, [string] $file) { + Write-Host "[*] Downloading ${file} from ${url}" + + [Net.ServicePointManager]::SecurityProtocol = 'Tls12' + $client = New-Object System.Net.WebClient + $client.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials + for ($i = 5; $i -ge 0; $i--) { + try { + $client.DownloadFile($url, $file) + return + } + catch [Net.WebException] { + if ($null -ne $_.Exception.Response) { + $status = [int]$_.Exception.Response.StatusCode + + Write-Host "[!] Failed to download ${url} to ${file} (HTTP ${status})" + } + else { + Write-Host "[!] Failed to download ${url} to ${file} ($($_.Exception.Message))" + } + + if ($i -gt 0) { + Write-Host "[*] Retrying in 5 seconds" + Start-Sleep 5 + } + } + } + + Write-Host "[!] Failed to download ${url} to ${file}" + Cleanup 1 +} + +function VersionGTE([string] $a, [string] $b) { + $a = $a -split '\.' + $b = $b -split '\.' + for ($i = 0; $i -lt $a.Length; $i++) { + if ($i -ge $b.Length) { return $true } + if ($a[$i] -gt $b[$i]) { return $true } + if ($a[$i] -lt $b[$i]) { return $false } + } + return $true +} + +if ($LUVI_VERSION -ne "latest") { $LUVI_VERSION = "v${LUVI_VERSION}" } +if ($LIT_VERSION -ne "latest") { $LIT_VERSION = "v${LIT_VERSION}" } +if ($LUVIT_VERSION -ne "latest") { $LUVIT_VERSION = "v${LUVIT_VERSION}" } + +$luvi_url = "https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-regular-${LUVI_OS}_${LUVI_ARCH}${exe_suffix}" +$lit_url = "https://lit.luvit.io/packages/luvit/lit/${LIT_VERSION}.zip" +$luvit_url = "https://lit.luvit.io/packages/luvit/luvit/${LUVIT_VERSION}.zip" + +if (${LUVI_VERSION} -eq "latest" -or (VersionGTE $LUVI_VERSION "2.15.0")) { + $luvi_url = "https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular${exe_suffix}" +} + +Write-Host "[+] Installing luvit, lit and luvi to ${LUVI_PREFIX}" + +# Download Luvi, and the sources for Lit and Luvit + +Download $luvi_url $luvi_bin +Download $lit_url $lit_zip +Download $luvit_url $luvit_zip + +# Install luvi + +if ("${LUVI_OS}" -ne "Windows") { + &chmod +x $luvi_bin +} + +# Install lit + +Write-Host "[*] Creating lit from lit.zip" +&"${luvi_bin}" "${lit_zip}" -- make "${lit_zip}" "${lit_bin}" "${luvi_bin}" +if (-not (Test-Path $lit_bin)) { + Write-Host "[!] Could not create lit" + Cleanup 1 +} + +# Install Luvit + +Write-Host "[*] Creating luvit from luvit.zip" +&"${lit_bin}" make "${luvit_zip}" "${luvit_bin}" "${luvi_bin}" +if (-not (Test-Path $luvit_bin)) { + Write-Host "[!] Could not create luvit" + Cleanup 1 +} + +Write-Host "[+] Installation complete at ${LUVI_PREFIX}" + +Cleanup 0 diff --git a/get-lit.sh b/get-lit.sh index 7cf68b5..c705095 100755 --- a/get-lit.sh +++ b/get-lit.sh @@ -1,23 +1,109 @@ #!/bin/sh -set -eu -LUVI_VERSION=${LUVI_VERSION:-2.14.0} +set -u # exit on unset variables. + +LUVI_PREFIX=${LUVI_PREFIX:-${PWD}} + +LUVI_OS=${LUVI_OS:-"$(uname -s)"} +LUVI_ARCH=${LUVI_ARCH:-"$(uname -m)"} +LUVI_ENGINE=${LUVI_ENGINE:-luajit} + +LUVI_VERSION=${LUVI_VERSION:-2.15.0} LIT_VERSION=${LIT_VERSION:-3.8.5} +LUVIT_VERSION=${LUVIT_VERSION:-latest} + +_lit_zip="${LUVI_PREFIX}/lit.zip" +_luvit_zip="${LUVI_PREFIX}/luvit.zip" +_luvi_bin="${LUVI_PREFIX}/luvi" +_lit_bin="${LUVI_PREFIX}/lit" +_luvit_bin="${LUVI_PREFIX}/luvit" + +cleanup() { + _exit=$1 + + echo "[*] Cleaning up" + rm -f "${_lit_zip}" + rm -f "${_luvit_zip}" + exit "${_exit}" +} + +# download a file from $1 and save it as $2 +download() { + _url=$1 + _file=$2 + + echo "[*] Downloading ${_file} from ${_url}" + + # --retry requires curl 7.12.3, from 2004 + _status="$(curl --retry 5 --retry-delay 5 -#Lfo "${_file}" -w "%{http_code}" "${_url}")" + _exit="$?" + if [ "${_exit}" -eq 2 ]; then # curl failed to start, probably not installed or version too old + echo "[!] Failed to download ${_file} (curl initialization failed)" + exit 1 + elif [ "${_exit}" -ne 0 ]; then # curl failed to download + echo "[!] Failed to download ${_file} (curl exit ${_exit})" + echo "curl: ${_status}" + exit 1 + fi + + if [ "${_status}" -ne 200 ]; then # the server did not give us the file + echo "[!] Failed to download ${_file} (HTTP ${_status})" + exit 1 + fi +} + +# check if version $1 is greater than or equal to $2 +version_gte() { + [ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ] || [ "$1" = "$2" ] +} + +# allow selecting latest, but real versions need a v prefix +[ "${LUVI_VERSION}" != "latest" ] && LUVI_VERSION="v${LUVI_VERSION}" +[ "${LIT_VERSION}" != "latest" ] && LIT_VERSION="v${LIT_VERSION}" +[ "${LUVIT_VERSION}" != "latest" ] && LUVIT_VERSION="v${LUVIT_VERSION}" + +_luvi_url="https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-regular-${LUVI_OS}_${LUVI_ARCH}" +_lit_url="https://lit.luvit.io/packages/luvit/lit/${LIT_VERSION}.zip" +_luvit_url="https://lit.luvit.io/packages/luvit/luvit/${LUVIT_VERSION}.zip" + +if [ "${LUVI_VERSION}" = "latest" ] || version_gte "${LUVI_VERSION}" "2.15.0"; then # select the new release format + _luvi_url="https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular" +fi + +echo "[+] Installing luvit, lit and luvi to ${LUVI_PREFIX}" +trap 'echo "[#] Cancelling installation"; cleanup 1' INT TERM + +# Download Luvi, and the sources for Lit and Luvit + +download "${_luvi_url}" "${_luvi_bin}" || cleanup 1 +download "${_lit_url}" "${_lit_zip}" || cleanup 1 +download "${_luvit_url}" "${_luvit_zip}" || cleanup 1 + +# Install luvi + +chmod +x "${_luvi_bin}" +if [ ! -x "${_luvi_bin}" ]; then + echo "[!] Could not make luvi executable" + cleanup 1 +fi + +# Install lit + +echo "[*] Creating lit from lit.zip" +"${_luvi_bin}" "${_lit_zip}" -- make "${_lit_zip}" "${_lit_bin}" "${_luvi_bin}" +if [ ! -x "${_lit_bin}" ]; then + echo "[!] Could not create lit" + cleanup 1 +fi -LUVI_ARCH=`uname -s`_`uname -m` -LUVI_URL="https://github.com/luvit/luvi/releases/download/v$LUVI_VERSION/luvi-regular-$LUVI_ARCH" -LIT_URL="https://lit.luvit.io/packages/luvit/lit/v$LIT_VERSION.zip" +# Install luvit -# Download Files -echo "Downloading $LUVI_URL to luvi" -curl -L -f -o luvi $LUVI_URL -chmod +x luvi +echo "[*] Creating luvit from luvit.zip" +"${_lit_bin}" make "${_luvit_zip}" "${_luvit_bin}" "${_luvi_bin}" +if [ ! -x "${_luvit_bin}" ]; then + echo "[!] Could not create luvit" + cleanup 1 +fi -echo "Downloading $LIT_URL to lit.zip" -curl -L -f -o lit.zip $LIT_URL +echo "[+] Installation complete at ${LUVI_PREFIX}" -# Create lit using lit -./luvi lit.zip -- make lit.zip lit luvi -# Cleanup -rm -f lit.zip -# Create luvit using lit -./lit make lit://luvit/luvit luvit luvi +cleanup 0 From ce1ccbd09b9811143f78c29df66e2a5fc95be834 Mon Sep 17 00:00:00 2001 From: Bilal2453 Date: Thu, 5 Mar 2026 01:00:42 +0300 Subject: [PATCH 2/3] get-lit: major fixes and improvements fix: properly fetch latest luvi fix: version comparison is not ignoring prefixed v fix: not exiting on lit failure fix: improper arch detection compatibility with older PS versions refactor: use Invoke-WebRequest instead of legacy WebClient refactor: clean the powershell script refactor: use [version] for PS version comparisons feat: allow version env variables starting with v feat: add check for the minimum luvi requirement for lit --- get-lit.ps1 | 114 ++++++++++++++++++++++++---------------------------- get-lit.sh | 22 +++++++--- 2 files changed, 69 insertions(+), 67 deletions(-) diff --git a/get-lit.ps1 b/get-lit.ps1 index bb2b326..a128b6f 100644 --- a/get-lit.ps1 +++ b/get-lit.ps1 @@ -1,42 +1,35 @@ Set-StrictMode -Version Latest -$LUVI_PREFIX = $PWD - -$LUVI_OS = "Windows" -$LUVI_ARCH = "amd64" -$LUVI_ENGINE = "luajit" - -$LUVI_VERSION = "2.15.0" -$LIT_VERSION = "3.8.5" -$LUVIT_VERSION = "latest" - -# Check for environment variable overrides -if ($null -ne $env:LUVI_PREFIX) { $LUVI_PREFIX = $env:LUVI_PREFIX } -if ($null -ne $env:LUVI_OS) { $LUVI_OS = $env:LUVI_OS } -if ($null -ne $env:LUVI_ARCH) { $LUVI_ARCH = $env:LUVI_ARCH } -if ($null -ne $env:LUVI_ENGINE) { $LUVI_ENGINE = $env:LUVI_ENGINE } -if ($null -ne $env:LUVI_VERSION) { $LUVI_VERSION = $env:LUVI_VERSION } -if ($null -ne $env:LIT_VERSION) { $LIT_VERSION = $env:LIT_VERSION } -if ($null -ne $env:LUVIT_VERSION) { $LUVIT_VERSION = $env:LUVIT_VERSION } - -if ($null -eq $env:LUVI_OS) { - # OS detection - if (-not (Get-Variable -Name 'IsWindows' -ErrorAction SilentlyContinue) -or $IsWindows) { +# Set up variables and their environment overrides +$LUVI_PREFIX = if ($env:LUVI_PREFIX) { $env:LUVI_PREFIX } else { $PWD } +$LUVI_ENGINE = if ($env:LUVI_ENGINE) { $env:LUVI_ENGINE } else { "luajit" } +$LUVI_VERSION = if ($env:LUVI_VERSION) { $env:LUVI_VERSION } else { "2.15.0" } +$LIT_VERSION = if ($env:LIT_VERSION) { $env:LIT_VERSION } else { "3.9.0" } +$LUVIT_VERSION = if ($env:LUVIT_VERSION) { $env:LUVIT_VERSION } else { "latest" } + +# OS detection +if ($env:LUVI_OS) { + $LUVI_OS = $env:LUVI_OS +} +else { + if (Get-Variable IsWindows -ErrorAction SilentlyContinue) { + # We are on PS >= 6 + if ($IsWindows) { $LUVI_OS = "Windows" } + elseif ($IsLinux) { $LUVI_OS = "Linux" } + elseif ($IsMacOS) { $LUVI_OS = "Darwin" } + else { $LUVI_OS = "$(uname -s)" } + } else { + # We are on PS <= 5.1, only available on Windows $LUVI_OS = "Windows" } - elseif ($IsLinux) { - $LUVI_OS = "Linux" - } - elseif ($IsMacOS) { - $LUVI_OS = "Darwin" - } - else { - $LUVI_OS = "$(uname -s)" - } } -if ($null -eq $env:LUVI_OS) { - # Architecture detection +# Architecture detection +if ($env:LUVI_ARCH) { + $LUVI_ARCH = $env:LUVI_ARCH +} +else { + $LUVI_ARCH = "amd64" if ($null -ne $env:PROCESSOR_ARCHITEW6432) { $LUVI_ARCH = ($env:PROCESSOR_ARCHITEW6432).ToLower() } @@ -58,6 +51,7 @@ $lit_bin = Join-Path "${LUVI_PREFIX}" "lit${exe_suffix}" $luvit_bin = Join-Path "${LUVI_PREFIX}" "luvit${exe_suffix}" function Cleanup([int] $exit_code) { + Write-Host "[*] Cleaning up" if (Test-Path $lit_zip) { Remove-Item $lit_zip -Force } if (Test-Path $luvit_zip) { Remove-Item $luvit_zip -Force } exit $exit_code @@ -66,27 +60,24 @@ function Cleanup([int] $exit_code) { function Download([string] $url, [string] $file) { Write-Host "[*] Downloading ${file} from ${url}" - [Net.ServicePointManager]::SecurityProtocol = 'Tls12' - $client = New-Object System.Net.WebClient - $client.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials - for ($i = 5; $i -ge 0; $i--) { + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + for ($i = 5; $i -gt 0; $i--) { try { - $client.DownloadFile($url, $file) + Invoke-WebRequest -Uri "$url" -OutFile "$file" -UseDefaultCredentials -ErrorAction Stop return } - catch [Net.WebException] { + catch { if ($null -ne $_.Exception.Response) { $status = [int]$_.Exception.Response.StatusCode - Write-Host "[!] Failed to download ${url} to ${file} (HTTP ${status})" } else { Write-Host "[!] Failed to download ${url} to ${file} ($($_.Exception.Message))" } - if ($i -gt 0) { - Write-Host "[*] Retrying in 5 seconds" - Start-Sleep 5 + if ($i -ge 1) { + Write-Host "[*] Retrying in 5 seconds ($(5 - $i + 1)/5)" + Start-Sleep -Seconds 5 } } } @@ -96,44 +87,47 @@ function Download([string] $url, [string] $file) { } function VersionGTE([string] $a, [string] $b) { - $a = $a -split '\.' - $b = $b -split '\.' - for ($i = 0; $i -lt $a.Length; $i++) { - if ($i -ge $b.Length) { return $true } - if ($a[$i] -gt $b[$i]) { return $true } - if ($a[$i] -lt $b[$i]) { return $false } - } - return $true + [version]$verA = $a -replace "v", "" + [version]$verB = $b -replace "v", "" + return $verA -ge $verB } +# Allow selecting latest, but real versions need a v prefix if ($LUVI_VERSION -ne "latest") { $LUVI_VERSION = "v${LUVI_VERSION}" } if ($LIT_VERSION -ne "latest") { $LIT_VERSION = "v${LIT_VERSION}" } if ($LUVIT_VERSION -ne "latest") { $LUVIT_VERSION = "v${LUVIT_VERSION}" } -$luvi_url = "https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-regular-${LUVI_OS}_${LUVI_ARCH}${exe_suffix}" -$lit_url = "https://lit.luvit.io/packages/luvit/lit/${LIT_VERSION}.zip" -$luvit_url = "https://lit.luvit.io/packages/luvit/luvit/${LUVIT_VERSION}.zip" - -if (${LUVI_VERSION} -eq "latest" -or (VersionGTE $LUVI_VERSION "2.15.0")) { +if (${LUVI_VERSION} -eq "latest") { + $luvi_url = "https://github.com/luvit/luvi/releases/latest/download/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular${exe_suffix}" +} +elseif (VersionGTE $LUVI_VERSION "2.15.0") { $luvi_url = "https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular${exe_suffix}" } +else { + $luvi_url = "https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-regular-${LUVI_OS}_${LUVI_ARCH}${exe_suffix}" +} +$lit_url = "https://lit.luvit.io/packages/luvit/lit/${LIT_VERSION}.zip" +$luvit_url = "https://lit.luvit.io/packages/luvit/luvit/${LUVIT_VERSION}.zip" Write-Host "[+] Installing luvit, lit and luvi to ${LUVI_PREFIX}" -# Download Luvi, and the sources for Lit and Luvit +# Lit 3.9.0 and newer require luvi >= 2.15.0 +if ((VersionGTE $LIT_VERSION "3.9.0") -and !(VersionGTE $LUVI_VERSION "2.15.0")) { + Write-Host "[!] Incompatible luvi version, lit $LIT_VERSION requires luvi 2.15.0 or newer you are using $LUVI_VERSION" + Cleanup 1 +} +# Download Luvi, and the sources for Lit and Luvit Download $luvi_url $luvi_bin Download $lit_url $lit_zip Download $luvit_url $luvit_zip # Install luvi - if ("${LUVI_OS}" -ne "Windows") { &chmod +x $luvi_bin } # Install lit - Write-Host "[*] Creating lit from lit.zip" &"${luvi_bin}" "${lit_zip}" -- make "${lit_zip}" "${lit_bin}" "${luvi_bin}" if (-not (Test-Path $lit_bin)) { @@ -142,7 +136,6 @@ if (-not (Test-Path $lit_bin)) { } # Install Luvit - Write-Host "[*] Creating luvit from luvit.zip" &"${lit_bin}" make "${luvit_zip}" "${luvit_bin}" "${luvi_bin}" if (-not (Test-Path $luvit_bin)) { @@ -151,5 +144,4 @@ if (-not (Test-Path $luvit_bin)) { } Write-Host "[+] Installation complete at ${LUVI_PREFIX}" - Cleanup 0 diff --git a/get-lit.sh b/get-lit.sh index c705095..aa8ae42 100755 --- a/get-lit.sh +++ b/get-lit.sh @@ -5,11 +5,11 @@ LUVI_PREFIX=${LUVI_PREFIX:-${PWD}} LUVI_OS=${LUVI_OS:-"$(uname -s)"} LUVI_ARCH=${LUVI_ARCH:-"$(uname -m)"} -LUVI_ENGINE=${LUVI_ENGINE:-luajit} +LUVI_ENGINE=${LUVI_ENGINE:-"luajit"} -LUVI_VERSION=${LUVI_VERSION:-2.15.0} -LIT_VERSION=${LIT_VERSION:-3.8.5} -LUVIT_VERSION=${LUVIT_VERSION:-latest} +LUVI_VERSION=${LUVI_VERSION:-"2.15.0"} +LIT_VERSION=${LIT_VERSION:-"3.9.0"} +LUVIT_VERSION=${LUVIT_VERSION:-"latest"} _lit_zip="${LUVI_PREFIX}/lit.zip" _luvit_zip="${LUVI_PREFIX}/luvit.zip" @@ -53,7 +53,9 @@ download() { # check if version $1 is greater than or equal to $2 version_gte() { - [ "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" ] || [ "$1" = "$2" ] + local v1="${1#v}" + local v2="${2#v}" + [ "$(printf '%s\n' "${v1}" "${v2}" | sort -V | head -n 1)" != "$v1" ] || [ "$v1" = "$v2" ] } # allow selecting latest, but real versions need a v prefix @@ -65,13 +67,21 @@ _luvi_url="https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi- _lit_url="https://lit.luvit.io/packages/luvit/lit/${LIT_VERSION}.zip" _luvit_url="https://lit.luvit.io/packages/luvit/luvit/${LUVIT_VERSION}.zip" -if [ "${LUVI_VERSION}" = "latest" ] || version_gte "${LUVI_VERSION}" "2.15.0"; then # select the new release format +if [ "${LUVI_VERSION}" = "latest" ]; then # select the latest endpoint + _luvi_url="https://github.com/luvit/luvi/releases/latest/download/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular" +elif version_gte "${LUVI_VERSION}" "2.15.0"; then # select the new release format _luvi_url="https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular" fi echo "[+] Installing luvit, lit and luvi to ${LUVI_PREFIX}" trap 'echo "[#] Cancelling installation"; cleanup 1' INT TERM +# lit 3.9.0 and newer require luvi >= 2.15.0 +if version_gte "${LIT_VERSION}" "3.9.0" && ! version_gte "${LUVI_VERSION}" "2.15.0"; then + echo "[!] Incompatible luvi version, lit ${LIT_VERSION} requires luvi 2.15.0 or newer" + cleanup 1 +fi + # Download Luvi, and the sources for Lit and Luvit download "${_luvi_url}" "${_luvi_bin}" || cleanup 1 From 0a2cae540ebe930d9aceaa4a7992e477b8b208d1 Mon Sep 17 00:00:00 2001 From: Bilal2453 Date: Thu, 26 Mar 2026 10:55:59 +0300 Subject: [PATCH 3/3] get-lit: add LUVI_FLAVOR While you cannot specify "tiny" as the target flavor due to Lit requiring OpenSSL, this is useful for specifying "regular-musl" on Linux. --- get-lit.ps1 | 7 ++++--- get-lit.sh | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/get-lit.ps1 b/get-lit.ps1 index a128b6f..270e87e 100644 --- a/get-lit.ps1 +++ b/get-lit.ps1 @@ -4,6 +4,7 @@ Set-StrictMode -Version Latest $LUVI_PREFIX = if ($env:LUVI_PREFIX) { $env:LUVI_PREFIX } else { $PWD } $LUVI_ENGINE = if ($env:LUVI_ENGINE) { $env:LUVI_ENGINE } else { "luajit" } $LUVI_VERSION = if ($env:LUVI_VERSION) { $env:LUVI_VERSION } else { "2.15.0" } +$LUVI_FLAVOR = if ($env:LUVI_FLAVOR) { $env:LUVI_FLAVOR } else { "regular" } $LIT_VERSION = if ($env:LIT_VERSION) { $env:LIT_VERSION } else { "3.9.0" } $LUVIT_VERSION = if ($env:LUVIT_VERSION) { $env:LUVIT_VERSION } else { "latest" } @@ -98,13 +99,13 @@ if ($LIT_VERSION -ne "latest") { $LIT_VERSION = "v${LIT_VERSION}" } if ($LUVIT_VERSION -ne "latest") { $LUVIT_VERSION = "v${LUVIT_VERSION}" } if (${LUVI_VERSION} -eq "latest") { - $luvi_url = "https://github.com/luvit/luvi/releases/latest/download/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular${exe_suffix}" + $luvi_url = "https://github.com/luvit/luvi/releases/latest/download/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-${LUVI_FLAVOR}${exe_suffix}" } elseif (VersionGTE $LUVI_VERSION "2.15.0") { - $luvi_url = "https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular${exe_suffix}" + $luvi_url = "https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-${LUVI_FLAVOR}${exe_suffix}" } else { - $luvi_url = "https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-regular-${LUVI_OS}_${LUVI_ARCH}${exe_suffix}" + $luvi_url = "https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_FLAVOR}-${LUVI_OS}_${LUVI_ARCH}${exe_suffix}" } $lit_url = "https://lit.luvit.io/packages/luvit/lit/${LIT_VERSION}.zip" $luvit_url = "https://lit.luvit.io/packages/luvit/luvit/${LUVIT_VERSION}.zip" diff --git a/get-lit.sh b/get-lit.sh index aa8ae42..4a60a65 100755 --- a/get-lit.sh +++ b/get-lit.sh @@ -6,6 +6,7 @@ LUVI_PREFIX=${LUVI_PREFIX:-${PWD}} LUVI_OS=${LUVI_OS:-"$(uname -s)"} LUVI_ARCH=${LUVI_ARCH:-"$(uname -m)"} LUVI_ENGINE=${LUVI_ENGINE:-"luajit"} +LUVI_FLAVOR=${LUVI_FLAVOR:-"regular"} LUVI_VERSION=${LUVI_VERSION:-"2.15.0"} LIT_VERSION=${LIT_VERSION:-"3.9.0"} @@ -63,14 +64,14 @@ version_gte() { [ "${LIT_VERSION}" != "latest" ] && LIT_VERSION="v${LIT_VERSION}" [ "${LUVIT_VERSION}" != "latest" ] && LUVIT_VERSION="v${LUVIT_VERSION}" -_luvi_url="https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-regular-${LUVI_OS}_${LUVI_ARCH}" +_luvi_url="https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_FLAVOR}-${LUVI_OS}_${LUVI_ARCH}" _lit_url="https://lit.luvit.io/packages/luvit/lit/${LIT_VERSION}.zip" _luvit_url="https://lit.luvit.io/packages/luvit/luvit/${LUVIT_VERSION}.zip" if [ "${LUVI_VERSION}" = "latest" ]; then # select the latest endpoint - _luvi_url="https://github.com/luvit/luvi/releases/latest/download/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular" + _luvi_url="https://github.com/luvit/luvi/releases/latest/download/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-${LUVI_FLAVOR}" elif version_gte "${LUVI_VERSION}" "2.15.0"; then # select the new release format - _luvi_url="https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-regular" + _luvi_url="https://github.com/luvit/luvi/releases/download/${LUVI_VERSION}/luvi-${LUVI_OS}-${LUVI_ARCH}-${LUVI_ENGINE}-${LUVI_FLAVOR}" fi echo "[+] Installing luvit, lit and luvi to ${LUVI_PREFIX}"