shorebirdtech / shorebird

Code Push for Flutter and other tools for Flutter businesses.
https://shorebird.dev
Other
1.97k stars 118 forks source link

docs: Not clear how to pass --force to installer #1954

Open eseidel opened 3 weeks ago

eseidel commented 3 weeks ago
eseidel@erics-mbp shorebird % curl --proto '=https' --tlsv1.2 https://raw.githubusercontent.com/shorebirdtech/install/main/install.sh -sSf | bash           
Error: Existing Shorebird installation detected. Use --force to overwrite.
eseidel@erics-mbp shorebird % curl --proto '=https' --tlsv1.2 https://raw.githubusercontent.com/shorebirdtech/install/main/install.sh -sSf | bash  --force
bash: --force: invalid option
Usage:  bash [GNU long option] [option] ...
        bash [GNU long option] [option] script-file ...
GNU long options:
        --debug
        --debugger
        --dump-po-strings
        --dump-strings
        --help
        --init-file
        --login
        --noediting
        --noprofile
        --norc
        --posix
        --protected
        --rcfile
        --restricted
        --verbose
        --version
        --wordexp
Shell options:
        -irsD or -c command or -O shopt_option          (invocation only)
        -abefhkmnptuvxBCHP or -o option
eseidel commented 3 weeks ago

It must be possible, I'm just not sure how to pass it. From https://docs.shorebird.dev/

eseidel commented 3 weeks ago

Doing:

eseidel@erics-mbp shorebird % curl https://raw.githubusercontent.com/shorebirdtech/install/main/install.sh > install.sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3567  100  3567    0     0  68871      0 --:--:-- --:--:-- --:--:-- 69941
eseidel@erics-mbp shorebird % bash install.sh 
Error: Existing Shorebird installation detected. Use --force to overwrite.
eseidel@erics-mbp shorebird % bash install.sh --force
Existing Shorebird installation detected. Overwriting...
felangel commented 3 weeks ago

https://github.com/shorebirdtech/setup-shorebird/blob/b7e70829acb30442c8553fdc343db0ac04c90798/action.yml#L14C8-L14C138

This could be much better documented, agreed 👍

ShahanMalik commented 2 days ago

Copy this code and paste it in PowerShell

$ErrorActionPreference = "Stop"

$installDirectory = [IO.Path]::Combine($home, ".shorebird")

function Test-GitInstalled {
    if (Get-Command git -ErrorAction SilentlyContinue) {
        Write-Debug "Git is installed."
    }
    else {
        Write-Output "No git installation detected. Git is required to use shorebird."
        exit 1
    }
}

function Compare-GitVersions {
    param (
        [string]$version1,
        [string]$version2
    )

    $version1Components = $version1 -split '\.'
    $version2Components = $version2 -split '\.'

    for ($i = 0; $i -lt 3; $i++) {
        $version1Number = [int]$version1Components[$i]
        $version2Number = [int]$version2Components[$i]

        if ($version1Number -lt $version2Number) {
            return -1
        }
        elseif ($version1Number -gt $version2Number) {
            return 1
        }
    }

    return 0
}

function Test-GitVersion {
    $minGitVersion = "2.25.1"
    $gitVersion = (Get-Item (Get-Command git).Source).VersionInfo.ProductVersionRaw
    $comparisonResult = Compare-GitVersions -version1 $gitVersion -version2 $minGitVersion
    if ($comparisonResult -eq -1) {
        Write-Output "Installed git version $gitVersion is older than required git version $minGitVersion."
        exit 1
    }
}

function Update-Path {
    $path = [Environment]::GetEnvironmentVariable("PATH", "User")
    if ($path.contains($installDirectory)) {
        return $false
    }
    $binPath = [IO.Path]::Combine($installDirectory, "bin")
    [Environment]::SetEnvironmentVariable(
        "Path", $path + [IO.Path]::PathSeparator + $binPath, "User"
    )

    return $true
}

Test-GitInstalled
Test-GitVersion

$force = $true

if (Test-Path $installDirectory) {
    if ($force) {
        Write-Output "Existing Shorebird installation detected. Overwriting..."
        Remove-Item -Recurse -Force $installDirectory
    }
    else {
        Write-Output "Error: Existing Shorebird installation detected. Use --force to overwrite."
        return
    }
}

Write-Output "Installing Shorebird to $installDirectory..."

& git clone https://github.com/shorebirdtech/shorebird.git -b stable $installDirectory

Push-Location $installDirectory\bin
& .\shorebird.ps1 --version
Pop-Location

$wasPathUpdated = Update-Path
# 1F426 is the code for 🐦. See https://unicode.org/emoji/charts/full-emoji-list.html#1f426.
$birdEmoji = [System.Char]::ConvertFromUtf32([System.Convert]::toInt32("1F426", 16))

Write-Output @"

$birdEmoji Shorebird has been installed!

"@

if ($wasPathUpdated) {
    Write-Output @"
Please restart your terminal to start using Shorebird.
"@
}

Write-Output @"
To get started, run the following command:

shorebird --help

For more information, visit https://docs.shorebird.dev
"@