-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add uninstall command + embed install script * Parse version into canonical form * Fix embed directive * Self review * Change bash to sh
- Loading branch information
1 parent
2ec9c2d
commit adc205a
Showing
7 changed files
with
103 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package uninstall | ||
|
||
import ( | ||
"github.com/rilldata/rill/cli/pkg/cmdutil" | ||
"github.com/rilldata/rill/cli/pkg/installscript" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func UninstallCmd(ch *cmdutil.Helper) *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "uninstall", | ||
Short: "Uninstall the Rill binary", | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, _ []string) error { | ||
return installscript.Uninstall(cmd.Context()) | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package installscript | ||
|
||
import ( | ||
"context" | ||
"embed" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
) | ||
|
||
//go:embed embed/* | ||
var embedFS embed.FS | ||
|
||
func Install(ctx context.Context, version string) error { | ||
if version != "" { | ||
return execScript(ctx, "--version", version) | ||
} | ||
return execScript(ctx) | ||
} | ||
|
||
func Uninstall(ctx context.Context) error { | ||
return execScript(ctx, "--uninstall") | ||
} | ||
|
||
func execScript(ctx context.Context, args ...string) error { | ||
script, err := createScriptFile() | ||
if err != nil { | ||
return err | ||
} | ||
defer os.Remove(script) | ||
|
||
// Execute the script with bash | ||
args = append([]string{script}, args...) | ||
cmd := exec.CommandContext(ctx, "/bin/sh", args...) | ||
cmd.Stdout = os.Stdout | ||
cmd.Stderr = os.Stderr | ||
return cmd.Run() | ||
} | ||
|
||
func createScriptFile() (string, error) { | ||
// Open the embedded install script file | ||
in, err := embedFS.Open("embed/install.sh") | ||
if err != nil { | ||
return "", fmt.Errorf("install script not embedded (is this a dev build?): %w", err) | ||
} | ||
defer in.Close() | ||
|
||
// Write the install script to a temporary file | ||
out, err := os.CreateTemp("", "install*.sh") | ||
if err != nil { | ||
return "", err | ||
} | ||
defer out.Close() | ||
|
||
_, err = io.Copy(out, in) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Return the temp script path | ||
return out.Name(), nil | ||
} |