From 7cf30ad330935ec4687d1783851aa9ce87f0c983 Mon Sep 17 00:00:00 2001 From: "K.B.Dharun Krishna" Date: Wed, 10 Jul 2024 15:03:44 +0530 Subject: [PATCH] cleanup: update files, docs Signed-off-by: K.B.Dharun Krishna --- .gitignore | 4 ++++ api/download.go | 14 +++++++++----- docs/articles/en/use-modules.md | 6 ++++-- docs/website/src/index.hbs | 3 ++- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 56da0e2..00666d8 100644 --- a/.gitignore +++ b/.gitignore @@ -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 *~ diff --git a/api/download.go b/api/download.go index d961a61..f1511e1 100644 --- a/api/download.go +++ b/api/download.go @@ -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 diff --git a/docs/articles/en/use-modules.md b/docs/articles/en/use-modules.md index 06dbf58..87f36f6 100644 --- a/docs/articles/en/use-modules.md +++ b/docs/articles/en/use-modules.md @@ -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: @@ -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. diff --git a/docs/website/src/index.hbs b/docs/website/src/index.hbs index c533b9b..0457e48 100644 --- a/docs/website/src/index.hbs +++ b/docs/website/src/index.hbs @@ -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