Skip to content

Commit

Permalink
Revert "feat: "zero" install now lives up to its name (#1219)"
Browse files Browse the repository at this point in the history
This reverts commit ea20eff.
  • Loading branch information
maxandersen committed Mar 19, 2022
1 parent 9397a94 commit ef580a7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
24 changes: 15 additions & 9 deletions src/main/scripts/jbang
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,21 @@ 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
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"
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 "$@"
exit $?
fi
if [ -f "$jarPath.new" ]; then
Expand Down
33 changes: 19 additions & 14 deletions src/main/scripts/jbang.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,31 +66,36 @@ if (Test-Path "$PSScriptRoot\jbang.jar") {
} elseif (Test-Path "$PSScriptRoot\.jbang\jbang.jar") {
$jarPath="$PSScriptRoot\.jbang\jbang.jar"
} else {
$zidir = New-TemporaryFile | % { Remove-Item $_; New-Item -ItemType Directory -Path $_ }
try {
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
$jburl="https://github.com/jbangdev/jbang/releases/latest/download/jbang.zip"
try { Invoke-WebRequest "$jburl" -OutFile "$zidir\jbang.zip"; $ok=$? } catch {
try { Invoke-WebRequest "$jburl" -OutFile "$TDIR\urls\jbang.zip"; $ok=$? } catch {
$ok=$false
$err=$_
}
if (-not ($ok)) {
[Console]::Error.WriteLine("Error downloading JBang")
if (-not ($ok)) {
[Console]::Error.WriteLine("Error downloading JBang from $jburl to $TDIR\urls\jbang.zip")
[Console]::Error.WriteLine($err)
break
break
}
try { Expand-Archive -Path "$zidir\jbang.zip" -DestinationPath "$zidir"; $ok=$? } catch {
$ok=$false
[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
$err=$_
}
if (-not ($ok)) {
[Console]::Error.WriteLine("Error unpacking JBang")
if (-not ($ok)) {
[Console]::Error.WriteLine("Error unzipping JBang from $TDIR\urls\jbang.zip to $TDIR\urls")
[Console]::Error.WriteLine($err)
break
break
}
. "$zidir\jbang\bin\jbang.ps1" @args
} finally {
Remove-Item -LiteralPath "$zidir" -Force -Recurse -ErrorAction Ignore >$null 2>&1
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
}
. "$JBDIR\bin\jbang.ps1" @args
break
}
if (Test-Path "$jarPath.new") {
Expand Down

0 comments on commit ef580a7

Please sign in to comment.