|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "os" |
| 6 | + "path/filepath" |
| 7 | + "runtime" |
| 8 | + |
| 9 | + "github.com/ActiveState/cli/internal/constants" |
| 10 | + "github.com/ActiveState/cli/internal/environment" |
| 11 | + "github.com/ActiveState/cli/internal/errs" |
| 12 | + "github.com/ActiveState/cli/internal/fileutils" |
| 13 | +) |
| 14 | + |
| 15 | +func main() { |
| 16 | + err := run() |
| 17 | + if err != nil { |
| 18 | + fmt.Fprintf(os.Stderr, "%s error: %v", os.Args[0], errs.Join(err, ":")) |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +func run() error { |
| 23 | + channel := constants.BranchName |
| 24 | + version := constants.RemoteInstallerVersion |
| 25 | + |
| 26 | + goos := runtime.GOOS |
| 27 | + goarch := runtime.GOARCH |
| 28 | + if len(os.Args) == 3 { |
| 29 | + goos = os.Args[1] |
| 30 | + goarch = os.Args[2] |
| 31 | + } |
| 32 | + platform := goos + "-" + goarch |
| 33 | + |
| 34 | + relChannelPath := filepath.Join("remote-installer", channel, platform) |
| 35 | + relVersionedPath := filepath.Join("remote-installer", channel, version, platform) |
| 36 | + |
| 37 | + buildPath := filepath.Join(environment.GetRootPathUnsafe(), "build") |
| 38 | + |
| 39 | + ext := "" |
| 40 | + if goos == "windows" { |
| 41 | + ext = ".exe" |
| 42 | + } |
| 43 | + sourceFile := filepath.Join(buildPath, constants.StateRemoteInstallerCmd+ext) |
| 44 | + if !fileutils.FileExists(sourceFile) { |
| 45 | + return errs.New("source file does not exist: %s", sourceFile) |
| 46 | + } |
| 47 | + |
| 48 | + fmt.Printf("Copying %s to %s\n", sourceFile, relChannelPath) |
| 49 | + if err := fileutils.CopyFile(sourceFile, filepath.Join(buildPath, relChannelPath, constants.StateRemoteInstallerCmd+ext)); err != nil { |
| 50 | + return errs.Wrap(err, "failed to copy source file to channel path") |
| 51 | + } |
| 52 | + |
| 53 | + fmt.Printf("Copying %s to %s\n", sourceFile, relVersionedPath) |
| 54 | + if err := fileutils.CopyFile(sourceFile, filepath.Join(buildPath, relVersionedPath, constants.StateRemoteInstallerCmd+ext)); err != nil { |
| 55 | + return errs.Wrap(err, "failed to copy source file to version path") |
| 56 | + } |
| 57 | + |
| 58 | + return nil |
| 59 | +} |
0 commit comments