func installGauge() { updateGaugeInstallPrefix() copyGaugeFiles(deployDir) if _, err := common.MirrorDir(deployDir, *gaugeInstallPrefix); err != nil { panic(fmt.Sprintf("Could not install gauge : %s", err)) } }
// InstallPluginFromZipFile installs plugin from given zip file func InstallPluginFromZipFile(zipFile string, pluginName string) InstallResult { tempDir := common.GetTempDir() defer common.Remove(tempDir) unzippedPluginDir, err := common.UnzipArchive(zipFile, tempDir) if err != nil { return installError(err) } gp, err := parsePluginJSON(unzippedPluginDir, pluginName) if err != nil { return installError(err) } if err = runPlatformCommands(gp.PreInstall, unzippedPluginDir); err != nil { return installError(err) } pluginInstallDir, err := getPluginInstallDir(gp.ID, getVersionedPluginDirName(zipFile)) if err != nil { return installError(err) } // copy files to gauge plugin install location logger.Info("Installing plugin %s %s", gp.ID, filepath.Base(pluginInstallDir)) if _, err = common.MirrorDir(unzippedPluginDir, pluginInstallDir); err != nil { return installError(err) } if err = runPlatformCommands(gp.PostInstall, pluginInstallDir); err != nil { return installError(err) } return installSuccess("") }
func installGaugeGo(installPrefix string) { defer os.RemoveAll(deploy) copyGaugeGoFiles(deployDir) goRunnerInstallPath := filepath.Join(installPrefix, "go", getGaugeGoVersion()) log.Printf("Copying %s -> %s\n", deployDir, goRunnerInstallPath) common.MirrorDir(deployDir, goRunnerInstallPath) }
func copyPluginFilesToGauge(installDesc *installDescription, versionInstallDesc *versionInstallDescription, pluginContents string) error { pluginsDir, err := common.GetPrimaryPluginsInstallDir() if err != nil { return err } versionedPluginDir := path.Join(pluginsDir, installDesc.Name, versionInstallDesc.Version) if common.DirExists(versionedPluginDir) { return errors.New(fmt.Sprintf("Plugin %s %s already installed at %s", installDesc.Name, versionInstallDesc.Version, versionedPluginDir)) } return common.MirrorDir(pluginContents, versionedPluginDir) }
func copyPluginFilesToGaugeInstallDir(unzippedPluginDir string, pluginId string, version string) error { logger.Log.Info("Installing Plugin => %s %s\n", pluginId, version) pluginsDir, err := common.GetPrimaryPluginsInstallDir() if err != nil { return err } versionedPluginDir := path.Join(pluginsDir, pluginId, version) if common.DirExists(versionedPluginDir) { return errors.New(fmt.Sprintf("Plugin %s %s already installed at %s", pluginId, version, versionedPluginDir)) } return common.MirrorDir(unzippedPluginDir, versionedPluginDir) }
func initializeTemplate(templateName string) error { tempDir := common.GetTempDir() defer util.Remove(tempDir) unzippedTemplate, err := util.DownloadAndUnzip(getTemplateURL(templateName), tempDir) if err != nil { return err } wd := config.ProjectRoot logger.Info("Copying Gauge template %s to current directory ...", templateName) filesAdded, err := common.MirrorDir(filepath.Join(unzippedTemplate, templateName), wd) if err != nil { return fmt.Errorf("Failed to copy Gauge template: %s", err.Error()) } metadataFile := filepath.Join(wd, metadataFileName) metadataContents, err := common.ReadFileContents(metadataFile) if err != nil { return fmt.Errorf("Failed to read file contents of %s: %s", metadataFile, err.Error()) } metadata := &templateMetadata{} err = json.Unmarshal([]byte(metadataContents), metadata) if err != nil { return err } if metadata.PostInstallCmd != "" { command := strings.Split(metadata.PostInstallCmd, " ") cmd, err := common.ExecuteSystemCommand(command, wd, os.Stdout, os.Stderr) cmd.Wait() if err != nil { for _, file := range filesAdded { pathSegments := strings.Split(file, string(filepath.Separator)) util.Remove(filepath.Join(wd, pathSegments[0])) } return fmt.Errorf("Failed to run post install commands: %s", err.Error()) } } util.Remove(metadataFile) return nil }
// key will be the source file and value will be the target func installFiles(files map[string]string, installDir string) { for src, dst := range files { base := filepath.Base(src) installDst := filepath.Join(installDir, dst) log.Printf("Install %s -> %s\n", src, installDst) stat, err := os.Stat(src) if err != nil { panic(err) } if stat.IsDir() { _, err = common.MirrorDir(src, installDst) } else { err = common.MirrorFile(src, filepath.Join(installDst, base)) } if err != nil { panic(err) } } }
func copyReportTemplateFiles(reportDir string) error { reportTemplateDir := filepath.Join(pluginDir, reportTemplateDir) _, err := common.MirrorDir(reportTemplateDir, reportDir) return err }