diff --git a/build_library/torcx_manifest.sh b/build_library/torcx_manifest.sh new file mode 100644 index 0000000000..fbc9cca0d0 --- /dev/null +++ b/build_library/torcx_manifest.sh @@ -0,0 +1,97 @@ +# Copyright (c) 2017 The Container Linux by CoreOS Authors. All rights +# reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# torcx_manifest.sh contains helper functions for creating, editing, and +# reading torcx manifest files. + +# create_empty creates an empty torcx manfiest at the given path. +function torcx_manifest::create_empty() { + local path="${1}" + jq '.' > "${path}" < "${path}" +} + +# get_pkg_names returns the list of packages in a given manifest. Each package +# may have one or more versions associated with it. +# +# Example: +# pkg_name_arr=($(torcx_manifest::get_pkg_names "torcx_manifest.json")) +function torcx_manifest::get_pkg_names() { + local file="${1}" + jq -r '.value.packages[].name' < "${file}" +} + +# get_digests returns the list of digests for a given package. +function torcx_manifest::get_digests() { + local file="${1}" + local name="${2}" + jq -r ".value.packages[] | select(.name == \"${name}\").versions[].casDigest" < "${file}" +}