diff --git a/cli/cmd/upgrade/upgrade.go b/cli/cmd/upgrade/upgrade.go index d7805be3f289..06a17f7341bf 100644 --- a/cli/cmd/upgrade/upgrade.go +++ b/cli/cmd/upgrade/upgrade.go @@ -10,6 +10,7 @@ import ( func UpgradeCmd(ch *cmdutil.Helper) *cobra.Command { var version string var nightly bool + var force bool upgradeCmd := &cobra.Command{ Use: "upgrade", @@ -24,19 +25,20 @@ func UpgradeCmd(ch *cmdutil.Helper) *cobra.Command { } version = "v" + v.String() - return installscript.Install(cmd.Context(), version) + return installscript.Install(cmd.Context(), version, force) } if nightly { - return installscript.Install(cmd.Context(), "nightly") + return installscript.Install(cmd.Context(), "nightly", force) } - return installscript.Install(cmd.Context(), "") + return installscript.Install(cmd.Context(), "", force) }, } upgradeCmd.Flags().StringVar(&version, "version", "", "Install a specific version of Rill") upgradeCmd.Flags().BoolVar(&nightly, "nightly", false, "Install the latest nightly build") + upgradeCmd.Flags().BoolVar(&force, "force", false, "Reinstall even if the latest version is already installed") return upgradeCmd } diff --git a/cli/pkg/installscript/installscript.go b/cli/pkg/installscript/installscript.go index a997405593f2..5431b8e67063 100644 --- a/cli/pkg/installscript/installscript.go +++ b/cli/pkg/installscript/installscript.go @@ -9,15 +9,19 @@ import ( "os/exec" ) -func Install(ctx context.Context, version string) error { - return execScript(ctx, version, "--version", version) +func Install(ctx context.Context, version string, force bool) error { + var env []string + if force { + env = append(os.Environ(), "RILL_INSTALL_FORCE=1") + } + return execScript(ctx, version, env, "--version", version) } func Uninstall(ctx context.Context) error { - return execScript(ctx, "", "--uninstall") + return execScript(ctx, "", nil, "--uninstall") } -func execScript(ctx context.Context, version string, args ...string) error { +func execScript(ctx context.Context, version string, env []string, args ...string) error { script, err := createScriptFile(ctx, version) if err != nil { return err @@ -26,6 +30,7 @@ func execScript(ctx context.Context, version string, args ...string) error { scriptArgs := append([]string{script}, args...) cmd := exec.CommandContext(ctx, "/bin/sh", scriptArgs...) + cmd.Env = env cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr diff --git a/docs/docs/developers/get-started/install.md b/docs/docs/developers/get-started/install.md index 2758ffbb3762..8aefcd710193 100644 --- a/docs/docs/developers/get-started/install.md +++ b/docs/docs/developers/get-started/install.md @@ -44,6 +44,11 @@ To ensure you're on the latest version of Rill and enjoying all of our newest fe rill upgrade ``` +If the latest version is already installed, the upgrade is skipped. To reinstall anyway, run `rill upgrade --force`, or set `RILL_INSTALL_FORCE=1` when using the installation script: +```bash +curl https://rill.sh | RILL_INSTALL_FORCE=1 sh +``` + :::info What about Rill Cloud? Rill Cloud is always on the latest stable version of Rill. To check the latest version available, please see our [Releases](https://github.com/rilldata/rill/releases) page. diff --git a/docs/docs/reference/cli/upgrade.md b/docs/docs/reference/cli/upgrade.md index 1d8382b2c1c4..072ddc7cada7 100644 --- a/docs/docs/reference/cli/upgrade.md +++ b/docs/docs/reference/cli/upgrade.md @@ -13,6 +13,7 @@ rill upgrade [flags] ### Flags ``` + --force Reinstall even if the latest version is already installed --nightly Install the latest nightly build --version string Install a specific version of Rill ``` diff --git a/scripts/install.sh b/scripts/install.sh index 063ad8fbaf83..ea0ba1136b26 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -62,11 +62,6 @@ sha256Verify() { # Download the binary and check the integrity using the SHA256 checksum downloadBinary() { CDN="cdn.rilldata.com" - - LATEST_URL="https://${CDN}/rill/latest.txt" - if [ "${VERSION}" = "latest" ]; then - VERSION=$(curl --silent --show-error "${LATEST_URL}") - fi BINARY_URL="https://${CDN}/rill/${VERSION}/rill_${PLATFORM}.zip" CHECKSUM_URL="https://${CDN}/rill/${VERSION}/checksums.txt" @@ -91,6 +86,24 @@ downloadBinary() { unzip -q "rill_${PLATFORM}.zip" } +# Resolve 'latest' to a concrete version and exit if it is already installed. +resolveLatestVersion() { + if [ "${VERSION}" != "latest" ]; then + return + fi + VERSION=$(curl --silent --show-error "https://cdn.rilldata.com/rill/latest.txt") + + if [ -n "$RILL_INSTALL_FORCE" ] || ! [ -x "$INSTALL_DIR/rill" ]; then + return + fi + # Output format: 'rill version v0.90.3 (build commit: ... date: ...)' + INSTALLED_VERSION=$("$INSTALL_DIR"/rill version 2>/dev/null | cut -d' ' -f3) || true + if [ "$INSTALLED_VERSION" = "$VERSION" ]; then + printf "Rill %s is already installed. To reinstall, run 'rill upgrade --force' or set RILL_INSTALL_FORCE=1.\n" "$VERSION" + exit 0 + fi +} + # Print install options printInstallOptions() { printf "\nWhere would you like to install rill? (Default [1])\n\n" @@ -298,6 +311,7 @@ installRill() { checkDependencies initPlatform resolveInstallDir + resolveLatestVersion initTmpDir downloadBinary installBinary