Simplify Go installation and support standard OpenCode releases
This commit is contained in:
@@ -19,18 +19,13 @@ type Config struct {
|
||||
Path string `json:"path"`
|
||||
}
|
||||
|
||||
// Load finds the manifest next to the actual Go binary, including via a system PATH symlink.
|
||||
// A standalone go-installed CLI can also select a prefix with PIPELINES_PREFIX.
|
||||
// Load selects a legacy managed installation only via an explicit PIPELINES_PREFIX.
|
||||
func Load(executable string) (*Config, error) {
|
||||
resolved, err := filepath.EvalSymlinks(executable)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
prefix := os.Getenv("PIPELINES_PREFIX")
|
||||
if prefix == "" {
|
||||
prefix = filepath.Dir(filepath.Dir(resolved))
|
||||
return nil, nil
|
||||
}
|
||||
prefix, err = filepath.Abs(prefix)
|
||||
prefix, err := filepath.Abs(prefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -60,8 +55,8 @@ func (c Config) Environment() error {
|
||||
}
|
||||
}
|
||||
}
|
||||
for key, value := range map[string]string{"PIPELINES_URL": "ws://127.0.0.1:" + strconv.Itoa(c.ServerPort) + "/connect", "PIPELINES_OPENCODE": c.OpenCode, "PATH": c.Path} {
|
||||
if key != "PATH" && os.Getenv(key) != "" {
|
||||
for key, value := range map[string]string{"PIPELINES_URL": "ws://127.0.0.1:" + strconv.Itoa(c.ServerPort) + "/connect", "PIPELINES_OPENCODE": c.OpenCode} {
|
||||
if os.Getenv(key) != "" {
|
||||
continue
|
||||
}
|
||||
if err := os.Setenv(key, value); err != nil {
|
||||
|
||||
@@ -18,6 +18,7 @@ func TestCompiledCommandFindsManifestThroughSystemLink(t *testing.T) {
|
||||
os.WriteFile(filepath.Join(root, "pipelines-install.json"), data, 0600)
|
||||
link := filepath.Join(t.TempDir(), "pipelines")
|
||||
os.Symlink(binary, link)
|
||||
t.Setenv("PIPELINES_PREFIX", root)
|
||||
loaded, err := Load(link)
|
||||
if err != nil || loaded == nil || loaded.Prefix != root {
|
||||
t.Fatal(loaded, err)
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package installation
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"debug/buildinfo"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Uninstall removes only verified binaries from the current command's Go bin directory.
|
||||
// Data is deliberately retained: custom server database paths cannot be safely inferred.
|
||||
func Uninstall(executable string, args []string, in io.Reader, out io.Writer) error {
|
||||
f := flag.NewFlagSet("uninstall", flag.ContinueOnError)
|
||||
f.SetOutput(out)
|
||||
yes := f.Bool("yes", false, "Skip confirmation")
|
||||
if err := f.Parse(args); err != nil {
|
||||
if err == flag.ErrHelp {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
if len(f.Args()) > 0 {
|
||||
return fmt.Errorf("uninstall takes no positional arguments")
|
||||
}
|
||||
resolved, err := filepath.EvalSymlinks(executable)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dir := filepath.Dir(resolved)
|
||||
var files []string
|
||||
for _, command := range []string{"pipelines", "pipelines-server", "pipelines-tui"} {
|
||||
path := filepath.Join(dir, command)
|
||||
info, err := buildinfo.ReadFile(path)
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot verify %s; no binaries removed: %w", path, err)
|
||||
}
|
||||
if info.Path != "git.a-wan.net/alan/pipelines/cmd/"+command {
|
||||
return fmt.Errorf("%s is not a Pipelines Go binary; no binaries removed", path)
|
||||
}
|
||||
files = append(files, path)
|
||||
}
|
||||
if !*yes {
|
||||
fmt.Fprintf(out, "Remove %s? Data and drafts are retained. [y/N] ", strings.Join(files, ", "))
|
||||
answer, err := bufio.NewReader(in).ReadString('\n')
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(strings.ToLower(answer)) != "y" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
for _, path := range files {
|
||||
if err := os.Remove(path); err != nil {
|
||||
return fmt.Errorf("remove %s: %w (use the permissions appropriate to your bin directory)", path, err)
|
||||
}
|
||||
}
|
||||
fmt.Fprintln(out, "Removed Go binaries. Pipeline history, drafts, and OpenCode configuration were retained.")
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user