github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/runtime/setup/implementations/camel/ape_installer_lin_win.go (about) 1 //go:build !darwin 2 // +build !darwin 3 4 package camel 5 6 import ( 7 "bufio" 8 "fmt" 9 "os" 10 "path/filepath" 11 "regexp" 12 "runtime" 13 14 "github.com/ActiveState/cli/internal/errs" 15 "github.com/ActiveState/cli/internal/fileutils" 16 "github.com/ActiveState/cli/internal/locale" 17 ) 18 19 // installActivePerl will unpack the installer archive, locate the install script, and then use the installer 20 // script to install an ActivePerl runtime to the configured runtime dir. Any failures 21 // during this process will result in a failed installation and the install-dir being removed. 22 func (m *MetaData) perlRelocationDir(installRoot string) (string, error) { 23 relocFile := filepath.Join("bin", "reloc_perl") 24 if runtime.GOOS == "windows" { 25 relocFile = filepath.Join("bin", "config_data") 26 } 27 relocFilePath := filepath.Join(installRoot, relocFile) 28 if !fileutils.FileExists(relocFilePath) { 29 return "", locale.NewError("installer_err_runtime_no_file", "", installRoot, relocFile) 30 } 31 32 f, err := os.Open(relocFilePath) 33 if err != nil { 34 return "", errs.Wrap(err, "Open %s failed", relocFilePath) 35 } 36 defer f.Close() 37 38 scanner := bufio.NewScanner(f) 39 scanner.Scan() 40 line := scanner.Text() 41 42 // Can't use filepath.Separator because we need to escape the backslash on Windows 43 separator := `/` 44 if runtime.GOOS == "windows" { 45 separator = `\\` 46 } 47 48 rx := regexp.MustCompile(fmt.Sprintf(`#!(.*)%sbin`, separator)) 49 match := rx.FindStringSubmatch(line) 50 if len(match) != 2 { 51 return "", &ErrNoPrefixes{locale.NewError("installer_err_fail_obtain_prefixes", "", installRoot)} 52 } 53 54 return match[1], nil 55 }