|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +_usage(){ |
| 4 | + cat << EOF |
| 5 | +
|
| 6 | +A simple script to pull topic repositories for use as Ciel local repositories. |
| 7 | +
|
| 8 | +Usage: |
| 9 | +
|
| 10 | + $0 [TOPIC_NAME_A] [TOPIC_NAME_B] ... [TOPIC_NAME_Z] |
| 11 | +EOF |
| 12 | +} |
| 13 | + |
| 14 | +_check_arch() { |
| 15 | + local arch |
| 16 | + arch="$(ciel run -- dpkg-architecture -qDEB_BUILD_ARCH)" |
| 17 | + if [ "$?" -eq 0 ]; then |
| 18 | + echo "$arch" |
| 19 | + return 0 |
| 20 | + fi |
| 21 | + # fallback to uname if dpkg-architecture fails |
| 22 | + arch="$(uname -m)" |
| 23 | + case $arch in |
| 24 | + aarch64) arch="arm64" ;; |
| 25 | + x86_64) arch="amd64" ;; |
| 26 | + mips64) arch="loongson3" ;; |
| 27 | + ppc64le) arch="ppc64el" ;; |
| 28 | + loongarch64) arch="loongarch64" ;; |
| 29 | + riscv64) arch="riscv64" ;; |
| 30 | + *) echo "Unsupported architecture: $arch"; exit 1 ;; |
| 31 | + esac |
| 32 | +} |
| 33 | + |
| 34 | +# $1: topic name |
| 35 | +# $2: architecture name |
| 36 | +_fetch_one_topic() { |
| 37 | + local output_dir="OUTPUT-$1" |
| 38 | + if [ -e "${output_dir}" ]; then |
| 39 | + while true; do |
| 40 | + read -rp "Detected an existing local repository for $1, overwrite? " yn |
| 41 | + case $yn in |
| 42 | + [Yy]* ) |
| 43 | + rm -r "${output_dir}"; break ;; |
| 44 | + [Nn]* ) |
| 45 | + echo "Aborting, please move your local repository directory OUTPUT-$1 aside."; exit 1 ;; |
| 46 | + * ) |
| 47 | + echo "Please input Y[y] or N[n]." ;; |
| 48 | + esac |
| 49 | + done |
| 50 | + fi |
| 51 | + |
| 52 | + echo "Pulling topic repository: $1 ..." |
| 53 | + rsync \ |
| 54 | + -avSHPR \ |
| 55 | + --include='*/' \ |
| 56 | + "rsync://mirror.anthonos.org/anthon/debs/pool/$1/main/**/*"_{"$2",noarch}.deb \ |
| 57 | + "${output_dir}" |
| 58 | + |
| 59 | + echo "Adjusting topic repository for Ciel: $i ..." |
| 60 | + mv -v "${output_dir}"/*/*/*/main \ |
| 61 | + "${output_dir}"/ |
| 62 | + rm -rv "${output_dir}"/debs |
| 63 | + mv -v "${output_dir}"/main \ |
| 64 | + "${output_dir}"/debs |
| 65 | +} |
| 66 | + |
| 67 | +if [ -z "$1" ]; then |
| 68 | + _usage |
| 69 | + exit 1 |
| 70 | +fi |
| 71 | + |
| 72 | +arch="$(_check_arch)" |
| 73 | +for i in "$@"; do |
| 74 | + _fetch_one_topic "$i" "$arch" |
| 75 | +done |
0 commit comments