Skip to content

Commit

Permalink
feat: "zero" install now lives up to its name (jbangdev#1219)
Browse files Browse the repository at this point in the history
  • Loading branch information
quintesse authored Mar 18, 2022
1 parent d942ada commit ea20eff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 34 deletions.
24 changes: 9 additions & 15 deletions src/main/scripts/jbang
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,15 @@ if [ -f "$abs_jbang_dir/jbang.jar" ]; then
elif [ -f "$abs_jbang_dir/.jbang/jbang.jar" ]; then
jarPath=$abs_jbang_dir/.jbang/jbang.jar
else
if [[ ! -f "$JBDIR/bin/jbang.jar" || ! -f "$JBDIR/bin/jbang" ]]; then
echo "Downloading JBang..." 1>&2
mkdir -p "$TDIR/urls"
jburl="https://github.com/jbangdev/jbang/releases/latest/download/jbang.tar"
download $jburl "$TDIR/urls/jbang.tar"
if [ $retval -ne 0 ]; then echo "Error downloading JBang" 1>&2; exit $retval; fi
echo "Installing JBang..." 1>&2
rm -rf "$TDIR/urls/jbang"
tar xf "$TDIR/urls/jbang.tar" -C "$TDIR/urls"
if [ $retval -ne 0 ]; then echo "Error installing JBang" 1>&2; exit $retval; fi
mkdir -p "$JBDIR/bin"
rm -f "$JBDIR/bin/jbang" "$JBDIR/bin"/jbang.*
cp -f "$TDIR/urls/jbang/bin"/* "$JBDIR/bin"
fi
"$JBDIR"/bin/jbang "$@"
zidir=$(mktemp -d "$(basename $0).XXXXXXXXXX")
trap "rm -rf $zidir" EXIT
jburl="https://github.com/jbangdev/jbang/releases/latest/download/jbang.tar"
download $jburl "$zidir/jbang.tar"
if [ $retval -ne 0 ]; then echo "Error downloading JBang" 1>&2; exit $retval; fi
tar xf "$zidir/jbang.tar" -C "$zidir"
if [ $retval -ne 0 ]; then echo "Error unpacking JBang" 1>&2; exit $retval; fi
"$zidir"/jbang/bin/jbang "$@"
rm -rf "$zidir"
exit $?
fi
if [ -f "$jarPath.new" ]; then
Expand Down
33 changes: 14 additions & 19 deletions src/main/scripts/jbang.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,31 @@ if (Test-Path "$PSScriptRoot\jbang.jar") {
} elseif (Test-Path "$PSScriptRoot\.jbang\jbang.jar") {
$jarPath="$PSScriptRoot\.jbang\jbang.jar"
} else {
if (-not (Test-Path "$JBDIR\bin\jbang.jar") -or -not (Test-Path "$JBDIR\bin\jbang.ps1")) {
[Console]::Error.WriteLine("Downloading JBang...")
New-Item -ItemType Directory -Force -Path "$TDIR\urls" >$null 2>&1
$zidir = New-TemporaryFile | % { Remove-Item $_; New-Item -ItemType Directory -Path $_ }
try {
$jburl="https://github.com/jbangdev/jbang/releases/latest/download/jbang.zip"
try { Invoke-WebRequest "$jburl" -OutFile "$TDIR\urls\jbang.zip"; $ok=$? } catch {
try { Invoke-WebRequest "$jburl" -OutFile "$zidir\jbang.zip"; $ok=$? } catch {
$ok=$false
$err=$_
}
if (-not ($ok)) {
[Console]::Error.WriteLine("Error downloading JBang from $jburl to $TDIR\urls\jbang.zip")
if (-not ($ok)) {
[Console]::Error.WriteLine("Error downloading JBang")
[Console]::Error.WriteLine($err)
break
break
}
[Console]::Error.WriteLine("Installing JBang...")
Remove-Item -LiteralPath "$TDIR\urls\jbang" -Force -Recurse -ErrorAction Ignore >$null 2>&1
try { Expand-Archive -Path "$TDIR\urls\jbang.zip" -DestinationPath "$TDIR\urls"; $ok=$? } catch {
$ok=$false
try { Expand-Archive -Path "$zidir\jbang.zip" -DestinationPath "$zidir"; $ok=$? } catch {
$ok=$false
$err=$_
}
if (-not ($ok)) {
[Console]::Error.WriteLine("Error unzipping JBang from $TDIR\urls\jbang.zip to $TDIR\urls")
if (-not ($ok)) {
[Console]::Error.WriteLine("Error unpacking JBang")
[Console]::Error.WriteLine($err)
break
break
}
New-Item -ItemType Directory -Force -Path "$JBDIR\bin" >$null 2>&1
Remove-Item -LiteralPath "$JBDIR\bin\jbang" -Force -ErrorAction Ignore >$null 2>&1
Remove-Item -Path "$JBDIR\bin\jbang.*" -Force -ErrorAction Ignore >$null 2>&1
Copy-Item -Path "$TDIR\urls\jbang\bin\*" -Destination "$JBDIR\bin" -Force >$null 2>&1
. "$zidir\jbang\bin\jbang.ps1" @args
} finally {
Remove-Item -LiteralPath "$zidir" -Force -Recurse -ErrorAction Ignore >$null 2>&1
}
. "$JBDIR\bin\jbang.ps1" @args
break
}
if (Test-Path "$jarPath.new") {
Expand Down

0 comments on commit ea20eff

Please sign in to comment.