github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/scripts/ci/deploy-generator/remote-installer/main.go (about) 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.JoinMessage(err)) 19 } 20 } 21 22 func run() error { 23 version := constants.RemoteInstallerVersion 24 25 goos := runtime.GOOS 26 goarch := runtime.GOARCH 27 if len(os.Args) == 3 { 28 goos = os.Args[1] 29 goarch = os.Args[2] 30 } 31 platform := goos + "-" + goarch 32 33 relPath := filepath.Join("remote-installer", constants.ChannelName, platform) 34 relVersionedPath := filepath.Join("remote-installer", constants.ChannelName, version, platform) 35 36 buildPath := filepath.Join(environment.GetRootPathUnsafe(), "build") 37 38 ext := "" 39 if goos == "windows" { 40 ext = ".exe" 41 } 42 sourceFile := filepath.Join(buildPath, constants.StateRemoteInstallerCmd+ext) 43 if !fileutils.FileExists(sourceFile) { 44 return errs.New("source file does not exist: %s", sourceFile) 45 } 46 47 fmt.Printf("Copying %s to %s\n", sourceFile, relPath) 48 if err := fileutils.CopyFile(sourceFile, filepath.Join(buildPath, relPath, constants.StateRemoteInstallerCmd+ext)); err != nil { 49 return errs.Wrap(err, "failed to copy source file to channel path") 50 } 51 52 fmt.Printf("Copying %s to %s\n", sourceFile, relVersionedPath) 53 if err := fileutils.CopyFile(sourceFile, filepath.Join(buildPath, relVersionedPath, constants.StateRemoteInstallerCmd+ext)); err != nil { 54 return errs.Wrap(err, "failed to copy source file to version path") 55 } 56 57 return nil 58 }