mkimage-yaml.sh 1.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/bin/sh

progname=$(basename $0)

usage() {
	echo "usage: $progname --checksums <checksums> --arch <arch> FILE..."
}

checksums="sha256 sha512"
while [ $# -gt 0 ]; do
	opt="$1"
	shift
	case "$opt" in
	--checksums) checksums="$1"; shift ;;
	--arch) arch="$1"; shift ;;
	--branch) branch="$1"; shift;;
	--release) release="$1"; shift;;
	--flavor) flavor="$1"; shift;;
19 20
	--title) title="$1"; shift;;
	--desc) desc="$1"; shift;;
21 22 23 24 25 26 27 28
	--) break ;;
	-*) usage; exit 1;;
	esac
done

set -- $opt "$@"

if [ -z "$branch" ]; then
29 30 31 32 33 34 35 36 37 38
	case "$release" in
	*.*.*_alpha*|*.*.*_beta*) branch=edge;;
	*.*.*) branch=${release%.*}; branch="v${branch#v}";;
	*)
		git_branch="$(git rev-parse --abbrev-ref HEAD)"
		case "$git_branch" in
		*-stable) branch=${git_branch%-stable};;
		*) branch=edge;;
		esac
		;;
39 40
	esac
fi
41
releasedir="$branch/releases/$arch"
42 43 44 45 46 47 48 49 50 51

[ -n "$arch" ] || arch=$(apk --print-arch)


for image; do
	filepath="$releasedir/${image##*/}"
	datetime="$(stat -c "%y" $image)"
	size="$(stat -c "%s" $image)"
	date=${datetime%% *}
	time=${datetime#* }
52
	time=${time%.*}
53 54
	file=${filepath##*/}
	flavor=${file%-${release}-${arch}.*}
55
	desc=$(echo "$desc" | sed -E 's/^\s*/    /')
56 57 58

	cat <<-EOF
	-
59 60 61
	  title: "$title"
	  desc: |
	$desc
62 63 64 65 66 67 68 69 70 71 72 73 74
	  branch: $branch
	  arch: $arch
	  version: $release
	  flavor: $flavor
	  file: $file
	  iso: $file
	  date: $date
	  time: $time
	  size: $size
EOF
	# generate checksums if missing
	for hash in ${checksums}; do
		if ! [ -f "$image.$hash" ]; then
75
			${hash}sum $image | sed 's: .*/:  :' > $image.$hash
76 77 78 79 80 81
		fi
		echo "  $hash: $(cut -d' ' -f1 $image.$hash)"
	done


done