Skip to content

Commit

Permalink
Add ZIP supported installer type
Browse files Browse the repository at this point in the history
  • Loading branch information
danhutchings committed Mar 6, 2024
1 parent 087a93f commit c461dd2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
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

0 comments on commit c461dd2

Please sign in to comment.