Skip to content

Commit

Permalink
cleanup: update files, docs
Browse files Browse the repository at this point in the history
Signed-off-by: K.B.Dharun Krishna <[email protected]>
  • Loading branch information
kbdharun committed Jul 10, 2024
1 parent 0db9f03 commit 7cf30ad
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
core/plugins.go
downloads/*
example/downloads/*
example/sources/*
sources/*
test/*
build
docs/website/dist/*
docs/website/node_modules/*
Containerfile
go.work
recipe.yml
*~
14 changes: 9 additions & 5 deletions api/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,23 +217,27 @@ func checksumValidation(source Source, path string) error {
if len(strings.TrimSpace(source.Checksum)) == 0 {
return nil
}

// Open the file
file, err := os.Open(path)
if err != nil {
return err
return fmt.Errorf("could not open file: %v", err)
}

// Close the file when the function ends
defer file.Close()

// Calculate the checksum
checksum := sha256.New()
_, err = io.Copy(checksum, file)
if err != nil {
return fmt.Errorf("could not calculate tar file checksum")
return fmt.Errorf("could not calculate checksum: %v", err)
}

// Validate the checksum
if fmt.Sprintf("%x", checksum.Sum(nil)) != source.Checksum {
return fmt.Errorf("tar file checksum doesn't match")
// Validate the checksum based on source type
calculatedChecksum := fmt.Sprintf("%x", checksum.Sum(nil))
if (source.Type == "tar" || source.Type == "file") && calculatedChecksum != source.Checksum {
return fmt.Errorf("%s source module checksum doesn't match: expected %s, got %s", source.Type, source.Checksum, calculatedChecksum)
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions docs/articles/en/use-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ You will find that some modules have a common `source` field, this instructs Vib
- chmod +x /usr/bin/cur-gpu
```
In the above example we define a `shell` module that downloads a tarball from a GitHub release and then copies the binaries to `/usr/bin`. A source can be of two types:
In the above example we define a `shell` module that downloads a tarball from a GitHub release and then copies the binaries to `/usr/bin`. A source can be of three types:

- `tar`: a tarball archive. It can also define a `Checksum` field to verify the integrity of the downloaded file using a `sha256` hash.
- `tar`: a tarball archive. You can also define a `checksum` field to verify the integrity of the downloaded archive using a `sha256` hash.
- `file`: a single file. You can also define a `checksum` field to verify the integrity of the downloaded file using a `sha256` hash.
- `git`: a Git repository.

In the latter case, you can specify the branch, tag or commit to checkout like this:
Expand All @@ -85,6 +86,7 @@ modules:

Supported fields for a git source are:

- `url`: the address of the repository to clone
- `tag`: the tag to checkout, collides with `branch` and `commit`.
- `branch`: the branch to checkout, collides with `tag`.
- `commit`: the commit to checkout, collides with `tag` and `branch`. It can be a commit hash or `latest` to checkout the latest commit.
Expand Down
3 changes: 2 additions & 1 deletion docs/website/src/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ stages:
args:
DEBIAN_FRONTEND: noninteractive
runs:
- echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/01norecommends
commands:
- echo 'APT::Install-Recommends "0";' > /etc/apt/apt.conf.d/01norecommends
modules:
- name: update
type: shell
Expand Down

0 comments on commit 7cf30ad

Please sign in to comment.