unos-repository

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

repo-pull.sh (2000B)


      1 #!/bin/sh
      2 # mk/repo-pull.sh - download every published .apk for a channel.
      3 #
      4 #   ./mk/repo-pull.sh --channel lts --arch x86_64 --repo https://repo.unos.finwo.net
      5 #
      6 # Names come from the templates, not from APKINDEX, so this works before a
      7 # valid index exists. Unpublished packages are simply absent.
      8 set -eu
      9 
     10 HERE=$(cd "$(dirname "$0")" && pwd)
     11 ROOT=$(cd "${HERE}/.." && pwd)
     12 
     13 # shellcheck disable=SC1091
     14 . "${HERE}/channels.inc"
     15 
     16 ARCH="${ARCH:-x86_64}"
     17 BASE=""
     18 CHANNEL="${UNOS_CHANNEL:-lts}"
     19 
     20 while [ $# -gt 0 ]; do
     21   case "$1" in
     22     --arch) ARCH="$2"; shift 2 ;;
     23     --arch=*) ARCH="${1#--arch=}"; shift ;;
     24     --repo) BASE="$2"; shift 2 ;;
     25     --repo=*) BASE="${1#--repo=}"; shift ;;
     26     --channel) CHANNEL="$2"; shift 2 ;;
     27     --channel=*) CHANNEL="${1#--channel=}"; shift ;;
     28     -h|--help) sed -n '2,9p' "$0"; exit 0 ;;
     29     *) echo "repo-pull.sh: unknown argument: $1" >&2; exit 1 ;;
     30   esac
     31 done
     32 
     33 ARCH=$(chan_arch "${ARCH}")
     34 case "${ARCH}" in x86_64|aarch64) ;; *) echo "repo-pull.sh: unsupported ARCH ${ARCH}" >&2; exit 1 ;; esac
     35 
     36 [ -n "${BASE}" ] || { echo "repo-pull.sh: --repo is required" >&2; exit 1; }
     37 command -v curl >/dev/null 2>&1 || { echo "repo-pull.sh: curl is required" >&2; exit 1; }
     38 
     39 export UNOS_CHANNEL="${CHANNEL}"
     40 OUT=$(chan_repodir "${CHANNEL}" "${ARCH}")
     41 mkdir -p "${OUT}"
     42 
     43 echo "==> pulling ${CHANNEL} packages from ${BASE} (${ARCH})"
     44 
     45 found=0
     46 for p in $("${ROOT}/mk/deps.sh" list); do
     47   for n in "${p}" $("${ROOT}/mk/deps.sh" subpkgs "${p}" 2>/dev/null || true); do
     48     pv=$("${ROOT}/mk/deps.sh" pkgver "${n}" 2>/dev/null) || continue
     49     apk_name="${n}-${pv}.apk"
     50 
     51     if [ -f "${OUT}/${apk_name}" ]; then
     52       found=$((found + 1))
     53       continue
     54     fi
     55 
     56     url=$(chan_url "${BASE}" "${CHANNEL}" "${ARCH}" "${apk_name}")
     57     if curl -fsSL -o "${OUT}/${apk_name}" "${url}" 2>/dev/null; then
     58       printf '    %s\n' "${apk_name}"
     59       found=$((found + 1))
     60     else
     61       rm -f "${OUT}/${apk_name}"
     62     fi
     63   done
     64 done
     65 
     66 echo "==> pulled ${found} package(s) into ${OUT}"