unos-repository

APK repository for unos
git clone git://git.finwo.net/misc/unos-repository
Log | Files | Refs | README

channels.inc (2641B)


      1 #!/bin/sh
      2 # mk/channels.inc - channel chain resolution and repo path layout.
      3 # Sourced, not executed. Expects ROOT to be set.
      4 
      5 CHANDIR="${ROOT}/channels"
      6 
      7 chan_die() { printf 'channels: error: %s\n' "$*" >&2; exit 1; }
      8 
      9 chan_exists() { [ -f "${CHANDIR}/$1/channel.conf" ]; }
     10 
     11 # chan_conf <channel> <key> -- empty when unset. Runs in a subshell, so it
     12 # cannot die; callers guard with chan_exists first.
     13 chan_conf() {
     14 	(
     15 		upstream=; publish=
     16 		# shellcheck disable=SC1090
     17 		. "${CHANDIR}/$1/channel.conf" >/dev/null 2>&1 || true
     18 		eval "printf '%s\n' \"\${$2}\""
     19 	)
     20 }
     21 
     22 # chan_layers <channel> -- composition order, root first
     23 chan_layers() {
     24 	chan_exists "$1" || chan_die "no such channel: $1"
     25 	_seen=" "
     26 	_stack=
     27 	_c="$1"
     28 	while [ -n "${_c}" ]; do
     29 		case "${_seen}" in
     30 			*" ${_c} "*) chan_die "upstream cycle at '${_c}'" ;;
     31 		esac
     32 		_seen="${_seen}${_c} "
     33 		_stack="${_c} ${_stack}"
     34 		_c=$(chan_conf "${_c}" upstream)
     35 		if [ -n "${_c}" ] && ! chan_exists "${_c}"; then
     36 			chan_die "'$1' names upstream '${_c}', which does not exist"
     37 		fi
     38 	done
     39 	printf '%s\n' "${_stack% }"
     40 }
     41 
     42 # chan_targets -- every channel CI builds, i.e. publish != no
     43 chan_targets() {
     44 	for _d in "${CHANDIR}"/*/; do
     45 		_n=$(basename "${_d}")
     46 		chan_exists "${_n}" || continue
     47 		[ "$(chan_conf "${_n}" publish)" = "no" ] && continue
     48 		printf '%s\n' "${_n}"
     49 	done
     50 }
     51 
     52 # chan_pkgdir <channel> -- assembled tree, written by channel-assemble.sh
     53 chan_pkgdir() { printf '%s/build/channels/%s/packages\n' "${ROOT}" "$1"; }
     54 
     55 chan_arch() {
     56 	case "$1" in
     57 		arm64) printf 'aarch64\n' ;;
     58 		*) printf '%s\n' "$1" ;;
     59 	esac
     60 }
     61 
     62 # chan_repodir <channel> <arch>
     63 chan_repodir() {
     64 	printf '%s/build/repo/%s/%s\n' "${ROOT}" "$1" "$(chan_arch "$2")"
     65 }
     66 
     67 # chan_sysroot <channel> <arch> -- per channel, or edge's kernel headers would
     68 # end up in an lts build
     69 chan_sysroot() {
     70 	printf '%s/build/sysroot/%s/%s\n' "${ROOT}" "$1" "$(chan_arch "$2")"
     71 }
     72 
     73 # chan_prefix <channel> <arch> -- bucket object key, relative to bucket root
     74 chan_prefix() { printf 'apk/%s/%s\n' "$1" "$(chan_arch "$2")"; }
     75 
     76 chan_squash() {
     77 	sed 's#://#___PROTO___#; s#//*#/#g; s#___PROTO___#://#'
     78 }
     79 
     80 # Repo URLs take the bare public base (https://repo.unos.finwo.net); the apk/
     81 # segment belongs to this builder, so another package format can sit beside it.
     82 
     83 # chan_url <base> <channel> <arch> [file]
     84 chan_url() {
     85 	_u="${1%/}/$(chan_prefix "$2" "$3")"
     86 	[ -n "${4:-}" ] && _u="${_u}/$4"
     87 	printf '%s' "${_u}" | chan_squash
     88 }
     89 
     90 # chan_repo_url <base> <channel> -- what apk wants in --repository: it appends
     91 # /<arch> itself, so this stops one segment short of chan_url
     92 chan_repo_url() {
     93 	printf '%s' "${1%/}/apk/$2" | chan_squash
     94 }