projects/aports·blob master · refs

93 lines · 1.8 KiB

1#!/bin/sh
2
3progname=$(basename $0)
4
5usage() {
6 echo "usage: $progname --checksums <checksums> --arch <arch> FILE..."
7}
8
9checksums="sha256 sha512"
10while [ $# -gt 0 ]; do
11 opt="$1"
12 shift
13 case "$opt" in
14 --checksums) checksums="$1"; shift ;;
15 --arch) arch="$1"; shift ;;
16 --branch) branch="$1"; shift;;
17 --release) release="$1"; shift;;
18 --flavor) flavor="$1"; shift;;
19 --title) title="$1"; shift;;
20 --desc) desc="$1"; shift;;
21 --) break ;;
22 -*) usage; exit 1;;
23 esac
24done
25
26set -- $opt "$@"
27
28if [ -z "$branch" ]; then
29 case "$release" in
30 *.*.*_alpha*|*.*.*_beta*) branch=edge;;
31 *.*.*) branch=${release%.*}; branch="v${branch#v}";;
32 *)
33 git_branch="$(git rev-parse --abbrev-ref HEAD)"
34 case "$git_branch" in
35 *-stable) branch=${git_branch%-stable};;
36 *) branch=edge;;
37 esac
38 ;;
39 esac
40fi
41releasedir="$branch/releases/$arch"
42
43[ -n "$arch" ] || arch=$(apk --print-arch)
44
45# size_and_sum [file] [prefix]
46size_and_sum() {
47 echo " ${2}size: $(stat -c "%s" "$1")"
48 for hash in ${checksums}; do
49 # generate checksums if missing
50 if ! [ -f "$1.$hash" ]; then
51 ${hash}sum "$1" | sed 's: .*/: :' > "$1.$hash"
52 fi
53 echo " $2$hash: $(cut -d' ' -f1 $1.$hash)"
54 done
55}
56
57for image; do
58 filepath="$releasedir/${image##*/}"
59 datetime="$(stat -c "%y" $image)"
60 size="$(stat -c "%s" $image)"
61 date=${datetime%% *}
62 time=${datetime#* }
63 time=${time%.*}
64 file=${filepath##*/}
65 flavor=${file%-${release}-${arch}.*}
66 desc=$(echo "$desc" | sed -E 's/^\s*/ /')
67
68 cat <<-EOF
69 -
70 title: "$title"
71 desc: |
72 $desc
73 branch: $branch
74 arch: $arch
75 version: $release
76 flavor: $flavor
77 file: $file
78 iso: $file
79 date: $date
80 time: $time
81EOF
82 size_and_sum "$image"
83
84 case "$file" in
85 *.img.gz)
86 extracted=${image%.gz}
87 if ! [ -f "$extracted" ]; then
88 zcat < "$image" > "$extracted"
89 fi
90 size_and_sum "$extracted" extracted_
91 ;;
92 esac
93done