Skip to content

Commit 7c31ed8

Browse files
committed
Included json metadata generator
1 parent c77098d commit 7c31ed8

9 files changed

Lines changed: 134 additions & 8 deletions

File tree

.github/workflows/bash.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ jobs:
1515

1616
- name: Compile and extract artifacts from docker container
1717
run: |
18+
sudo apt install jo jq
1819
mkdir -p dist
1920
for arch in x86_64; do
2021
docker build --platform "${arch}" -f bash.dockerfile -t bash:latest .
2122
docker run --rm --platform "${arch}" \
2223
-v $(pwd):/workdir \
2324
bash:latest \
2425
cp /dist/bash "/workdir/dist/bash-${arch}"
25-
sha256sum ./dist/bash-${arch} | awk '{print $1}' > ./dist/bash-${arch}.sha256sum
26+
SHA="$(sha256sum ./dist/bash-${arch} | awk '{print $1}')"
27+
./metadata.sh --version "$(./dist/bash-${arch} --version | head -n1 | awk '{print $4}')" \
28+
--license GPL-3.0 "https://www.gnu.org/licenses/gpl.html" \
29+
--source "http://ftpmirror.gnu.org/gnu/bash/bash-5.3.tar.gz" \
30+
--sha "$SHA" > ./dist/bash-metadata.json
2631
done
2732
2833
- name: Set permissions for dist directory

.github/workflows/busybox.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ jobs:
1515

1616
- name: Compile and extract artifacts from docker container
1717
run: |
18+
sudo apt install jo jq
1819
mkdir -p dist
1920
for arch in x86_64; do
2021
docker build --platform "${arch}" -f busybox.dockerfile -t busybox:latest .
2122
docker run --rm --platform "${arch}" \
2223
-v $(pwd):/workdir \
2324
busybox:latest \
2425
cp /tools/busybox/busybox "/workdir/dist/busybox-${arch}"
25-
sha256sum ./dist/busybox-${arch} | awk '{print $1}' > ./dist/busybox-${arch}.sha256sum
26+
SHA="$(sha256sum ./dist/busybox-${arch} | awk '{print $1}')"
27+
./metadata.sh --version "$(./dist/busybox-${arch} | head -1 | awk '{print $2}')" \
28+
--license GPLv2 "https://www.busybox.net/license.html" \
29+
--source "https://github.com/mirror/busybox.git" \
30+
--sha "$SHA" > ./dist/busybox-metadata.json
2631
done
2732
2833
- name: Set permissions for dist directory

.github/workflows/bwrap.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ jobs:
1515

1616
- name: Compile and extract artifacts from docker container
1717
run: |
18+
sudo apt install jo jq
1819
mkdir -p dist
1920
for arch in x86_64; do
2021
docker build --platform "${arch}" -f bwrap.dockerfile -t bwrap:latest .
2122
docker run --rm --platform "${arch}" \
2223
-v $(pwd):/workdir \
2324
bwrap:latest \
2425
cp /tools/bwrap/build/bwrap "/workdir/dist/bwrap-${arch}"
25-
sha256sum ./dist/bwrap-${arch} | awk '{print $1}' > ./dist/bwrap-${arch}.sha256sum
26+
SHA="$(sha256sum ./dist/bwrap-${arch} | awk '{print $1}')"
27+
./metadata.sh --version "$(./dist/bwrap-${arch} --version | awk '{print $2}')" \
28+
--license LGPLv2+ "https://github.com/containers/bubblewrap/blob/main/LICENSE" \
29+
--source https://github.com/containers/bubblewrap \
30+
--sha "$SHA" > ./dist/bwrap-metadata.json
2631
done
2732
2833
- name: Set permissions for dist directory

.github/workflows/ciopfs.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ jobs:
1515

1616
- name: Compile and extract artifacts from docker container
1717
run: |
18+
sudo apt install jo jq
1819
mkdir -p dist
1920
for arch in x86_64; do
2021
docker build --platform "${arch}" -f ciopfs.dockerfile -t ciopfs:latest .
2122
docker run --rm --platform "${arch}" \
2223
-v $(pwd):/workdir \
2324
ciopfs:latest \
2425
cp /tools/ciopfs/ciopfs "/workdir/dist/ciopfs-${arch}"
25-
sha256sum ./dist/ciopfs-${arch} | awk '{print $1}' > ./dist/ciopfs-${arch}.sha256sum
26+
SHA="$(sha256sum ./dist/ciopfs-${arch} | awk '{print $1}')"
27+
./metadata.sh --version "$(2>&1 ./dist/ciopfs-${arch} --version | awk '{print $2}')" \
28+
--license GPLv2 "https://github.com/martanne/ciopfs/blob/master/ciopfs.c" \
29+
--source "https://github.com/martanne/ciopfs" \
30+
--sha "$SHA" > ./dist/ciopfs-metadata.json
2631
done
2732
2833
- name: Set permissions for dist directory

.github/workflows/dwarfs.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515

1616
- name: Compile and extract artifacts from docker container
1717
run: |
18+
sudo apt install jo jq
1819
mkdir -p dist
1920
# for arch in x86_64; do
2021
# docker build --platform "${arch}" -f dwarfs.dockerfile -t dwarfs:latest .
@@ -27,7 +28,13 @@ jobs:
2728
# Just copy the pre-built for now
2829
for arch in x86_64; do
2930
wget -O ./dist/dwarfs_aio-${arch} https://github.com/mhx/dwarfs/releases/download/v0.13.0/dwarfs-universal-0.13.0-Linux-${arch}
30-
sha256sum ./dist/dwarfs_aio-${arch} | awk '{print $1}' > ./dist/dwarfs_aio-${arch}.sha256sum
31+
chmod +x ./dist/dwarfs_aio-${arch}
32+
SHA=$(sha256sum ./dist/dwarfs_aio-${arch} | awk '{print $1}')
33+
./metadata.sh --version "$(./dist/dwarfs_aio-${arch} --version | grep -m1 dwarfs-universal | awk '{print $2}' | sed 's/(v/v/')" \
34+
--license MIT "https://github.com/mhx/dwarfs/blob/main/LICENSE" \
35+
--license GPL-3.0 "https://github.com/mhx/dwarfs/blob/main/LICENSE.GPL-3.0" \
36+
--source "https://github.com/mhx/dwarfs" \
37+
--sha "$SHA" > ./dist/dwarfs_aio-metadata.json
3138
done
3239
3340
- name: Set permissions for dist directory

.github/workflows/imagemagick.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ jobs:
1515

1616
- name: Compile and extract artifacts from docker container
1717
run: |
18+
sudo apt install jo jq
1819
mkdir -p dist
1920
for arch in x86_64; do
2021
docker build --platform "${arch}" -f imagemagick.dockerfile -t imagemagick:latest .
2122
docker run --rm --platform "${arch}" \
2223
-v $(pwd):/workdir \
2324
imagemagick:latest \
2425
cp /dist/magick "/workdir/dist/magick-${arch}"
25-
sha256sum ./dist/magick-${arch} | awk '{print $1}' > ./dist/magick-${arch}.sha256sum
26+
SHA="$(sha256sum ./dist/magick-${arch} | awk '{print $1}')"
27+
./metadata.sh --version "$(./dist/magick-${arch} | head -n1 | awk '{print $3}')" \
28+
--license "imagemagick" "https://imagemagick.org/script/license.php" \
29+
--source "https://github.com/ImageMagick/ImageMagick" \
30+
--sha "$SHA" > ./dist/magick-metadata.json
2631
done
2732
2833
- name: Set permissions for dist directory

.github/workflows/overlayfs.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ jobs:
1515

1616
- name: Compile and extract artifacts from docker container
1717
run: |
18+
sudo apt install jo jq
1819
mkdir -p dist
1920
for arch in x86_64; do
2021
docker build --platform "${arch}" -f overlayfs.dockerfile -t overlayfs:latest .
2122
docker run --rm --platform "${arch}" \
2223
-v $(pwd):/workdir \
2324
overlayfs:latest \
2425
cp /tools/overlayfs/fuse-overlayfs "/workdir/dist/overlayfs-${arch}"
25-
sha256sum ./dist/overlayfs-${arch} | awk '{print $1}' > ./dist/overlayfs-${arch}.sha256sum
26+
SHA="$(sha256sum ./dist/overlayfs-${arch} | awk '{print $1}')"
27+
./metadata.sh --version "$(./dist/overlayfs-${arch} --version | head -n1 | awk '{print $3}')" \
28+
--license GPL-2.0 "https://github.com/containers/fuse-overlayfs/blob/main/COPYING" \
29+
--source "https://github.com/containers/fuse-overlayfs" \
30+
--sha "$SHA" > ./dist/overlayfs-metadata.json
2631
done
2732
2833
- name: Set permissions for dist directory

.github/workflows/unionfs.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,19 @@ jobs:
1515

1616
- name: Compile and extract artifacts from docker container
1717
run: |
18+
sudo apt install jo jq
1819
mkdir -p dist
1920
for arch in x86_64; do
2021
docker build --platform "${arch}" -f unionfs.dockerfile -t unionfs:latest .
2122
docker run --rm --platform "${arch}" \
2223
-v $(pwd):/workdir \
2324
unionfs:latest \
2425
cp /dist/unionfs "/workdir/dist/unionfs-${arch}"
25-
sha256sum ./dist/unionfs-${arch} | awk '{print $1}' > ./dist/unionfs-${arch}.sha256sum
26+
SHA="$(sha256sum ./dist/unionfs-${arch} | awk '{print $1}')"
27+
./metadata.sh --version "$(./dist/unionfs-${arch} --version | head -n1 | awk '{print $3}')" \
28+
--license "BSD-3-clause" "https://github.com/rpodgorny/unionfs-fuse/blob/master/LICENSE" \
29+
--source "https://github.com/rpodgorny/unionfs-fuse" \
30+
--sha "$SHA" > ./dist/unionfs-metadata.json
2631
done
2732
2833
- name: Set permissions for dist directory

metadata.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
declare -A LICENSE_MAP
5+
VERSION=""
6+
SOURCE=""
7+
SHA=""
8+
9+
usage() {
10+
cat >&2 <<EOF
11+
Usage:
12+
$0 --version <v> --source <url> --sha <hash> [--license <type> <url>]...
13+
14+
Example:
15+
$0 --version v1.0 \\
16+
--source https://some-url \\
17+
--sha 0912783LHFKLSHJF \\
18+
--license gpl https://some-gpl-url \\
19+
--license mit https://some-mit-url
20+
EOF
21+
}
22+
23+
# Require jo
24+
command -v jo >/dev/null 2>&1 || { echo "Error: 'jo' is required." >&2; exit 1; }
25+
26+
while [[ $# -gt 0 ]]; do
27+
case "$1" in
28+
--license)
29+
if [[ $# -lt 3 ]]; then
30+
echo "Error: --license requires <type> and <url>." >&2
31+
exit 1
32+
fi
33+
LICENSE_MAP["$2"]="$3"
34+
shift 3
35+
;;
36+
--version)
37+
[[ $# -ge 2 ]] || { echo "Error: --version requires a value." >&2; exit 1; }
38+
VERSION="$2"
39+
shift 2
40+
;;
41+
--source)
42+
[[ $# -ge 2 ]] || { echo "Error: --source requires a value." >&2; exit 1; }
43+
SOURCE="$2"
44+
shift 2
45+
;;
46+
--sha)
47+
[[ $# -ge 2 ]] || { echo "Error: --sha requires a value." >&2; exit 1; }
48+
SHA="$2"
49+
shift 2
50+
;;
51+
-h|--help)
52+
usage
53+
exit 0
54+
;;
55+
*)
56+
echo "Invalid argument '$1'" >&2
57+
usage
58+
exit 1
59+
;;
60+
esac
61+
done
62+
63+
# Basic validation
64+
[[ -n "${VERSION}" ]] || { echo "Error: --version is required." >&2; exit 1; }
65+
[[ -n "${SOURCE}" ]] || { echo "Error: --source is required." >&2; exit 1; }
66+
[[ -n "${SHA}" ]] || { echo "Error: --sha is required." >&2; exit 1; }
67+
68+
# Build final JSON
69+
jo_args=( -s version="$VERSION" -s source="$SOURCE" -s sha="$SHA" )
70+
71+
# Sort types alphabetically
72+
mapfile -t _types < <(printf "%s\n" "${!LICENSE_MAP[@]}" | sort)
73+
74+
# Create a JSON object for each license and append to licenses[]
75+
if [[ ${#_types[@]} -eq 0 ]]; then
76+
echo "Error: --license is required." >&2
77+
exit 1
78+
fi
79+
for type in "${_types[@]}"; do
80+
jo_args+=( "licenses[]=$(jo type="$type" url="${LICENSE_MAP[$type]}")" )
81+
done
82+
83+
# Emit pretty JSON
84+
jo -p -- "${jo_args[@]}"

0 commit comments

Comments
 (0)