Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ZIP supported installer type #127

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/catalog/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type InstallerItem struct {
Location string `yaml:"location"`
Hash string `yaml:"hash"`
Arguments []string `yaml:"arguments"`
Command string `yaml:"command"`
}

// InstallCheck holds information about how to check the status of a catalog item
Expand Down
59 changes: 59 additions & 0 deletions pkg/installer/installer.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package installer

import (
"archive/zip"
"bufio"
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -151,6 +153,63 @@ func installItem(item catalog.Item, itemURL, cachePath string) string {
installCmd = commandPs1
installArgs = []string{"-NoProfile", "-NoLogo", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", absFile}

} else if item.Installer.Type == "zip" {
gorillalog.Info("Extracting zip for", item.DisplayName)
dst := "output"
archive, err := zip.OpenReader(absFile)
if err != nil {
panic(err)
}
defer archive.Close()
// Extract the files from the zip
for _, f := range archive.File {

// Create the destination file path
filePath := filepath.Join(dst, f.Name)

// Print the file path
fmt.Println("Extracting file ", filePath)

// Check if the file is a directory
if f.FileInfo().IsDir() {
// Create the directory
fmt.Println("Creating directory...")
if err := os.MkdirAll(filePath, os.ModePerm); err != nil {
panic(err)
}
continue
}

// Create the parent directory if it doesn't exist
if err := os.MkdirAll(filepath.Dir(filePath), os.ModePerm); err != nil {
panic(err)
}

// Create an empty destination file
dstFile, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
if err != nil {
panic(err)
}

// Open the file in the zip and copy its contents to the destination file
srcFile, err := f.Open()
if err != nil {
panic(err)
}
if _, err := io.Copy(dstFile, srcFile); err != nil {
panic(err)
}

// Close the files
dstFile.Close()
srcFile.Close()
}
// tarArgs := []string{"-xf", absFile, "-C", cachePath}
// runCommand(commandTar, tarArgs)
gorillalog.Info("Running install command for", item.DisplayName)
installCmd = item.Installer.Command
installArgs = item.Installer.Arguments

} else {
msg := fmt.Sprint("Unsupported installer type", item.Installer.Type)
gorillalog.Warn(msg)
Expand Down
Loading