Skip to content

Commit

Permalink
add unquarantine functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
crhuber committed May 29, 2024
1 parent 4f07b01 commit b96d8d1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
14 changes: 5 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@ jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
- name: Checkout
uses: actions/checkout@v2
-
name: Unshallow
- name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.21.x
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import (
"github.com/urfave/cli/v2"
)

var Version = "dev"
var (
version = "dev"
commit = "none"
date = "unknown"
)

func main() {

Expand All @@ -24,7 +28,7 @@ func main() {

app := &cli.App{
Name: "kelp",
Version: Version,
Version: version,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Expand Down
31 changes: 28 additions & 3 deletions pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"log"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strings"

Expand Down Expand Up @@ -47,7 +49,12 @@ func Install(owner, repo, release string) error {
if err != nil {
return err
}
installBinary(tempdir)
destinations := installBinary(tempdir)
if runtime.GOOS == "darwin" {
for _, d := range destinations {
unquarantineFile(d)
}
}
os.RemoveAll(tempdir)

} else {
Expand All @@ -65,13 +72,28 @@ func Install(owner, repo, release string) error {
if err != nil {
return err
}
installBinary(tempdir)
destinations := installBinary(tempdir)
if runtime.GOOS == "darwin" {
for _, d := range destinations {
unquarantineFile(d)
}
}
os.RemoveAll(tempdir)

}
return nil
}

func unquarantineFile(filepath string) error {
fmt.Printf("🛃 Unquarantining %s...\n", filepath)
cmd := exec.Command("xattr", "-d", "com.apple.quarantine", filepath)
err := cmd.Run()
if err != nil {
return err
}
return nil
}

// downloadFile downloads files
func downloadFile(filepath string, url string) error {
fmt.Printf("===> Downloading %s...\n", url)
Expand Down Expand Up @@ -173,12 +195,13 @@ func extractPackage(downloadPath, tempDir string) error {
return errors.New("archive file format not known")
}

func installBinary(tempDir string) {
func installBinary(tempDir string) []string {
fmt.Println("🧐 Checking for binary files in extract...")
files, err := utils.FilePathWalkDir(tempDir)
if err != nil {
log.Panic("Could not walk directory")
}
destinations := []string{}
for _, file := range files {
mime, _ := mimetype.DetectFile(string(file))
// only install binary files
Expand All @@ -190,8 +213,10 @@ func installBinary(tempDir string) {
fmt.Printf("💾 Copying %v to kelp bin...\n", fileName)
utils.CopyFile(file, destination)
fmt.Printf("✅ Installed %v !\n", fileName)
destinations = append(destinations, destination)
}
}
return destinations
}

func getHighestScore(assetScores map[int]int) Pair {
Expand Down

0 comments on commit b96d8d1

Please sign in to comment.