Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/build-torrent
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2022-02-05 14:13:52 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2022-02-05 14:13:52 +0100
commite82af0c4e73824dc5ec4b35d2342c154d9a4ccbc (patch)
treeb256bef2567930fc5f92507d605d1de2eeca5647 /build-torrent
parente6ee9e025462d26a8c5e4b98ae22191405848126 (diff)
build-torrent: completly rearanged code from al32-mktorrent.sh
Diffstat (limited to 'build-torrent')
-rwxr-xr-xbuild-torrent146
1 files changed, 146 insertions, 0 deletions
diff --git a/build-torrent b/build-torrent
new file mode 100755
index 0000000..b3a842d
--- /dev/null
+++ b/build-torrent
@@ -0,0 +1,146 @@
+#!/bin/bash
+
+# parameters and default values
+CONFIG="releng"
+ARCH="i686"
+DATE=$(date +%Y.%m.%d)
+MIRROR_DIR="/srv/http/mirror/mirror.archlinux32.org"
+TORRENT_SERVER="archlinux32.org"
+TORRENT_USER="hefur"
+HEFUR_DIR="/var/lib/hefurd"
+
+base_dir=$(
+ readlink -e "${0%/*}"
+)
+
+usage() {
+ >&2 echo ""
+ >&2 echo "build-torrent: seed torrents for Archlinux32 ISOs"
+ >&2 echo ""
+ >&2 echo "possible options:"
+ >&2 echo " -h|--help: show this help and exit."
+ >&2 echo " --arch architecture of the ISO, default is '$ARCH'."
+ >&2 echo " --date date of the ISO for, default is '$DATE'."
+ >&2 echo " --mirror-dir where are the ISOs stored on the mirror, default is '$MIRROR_DIR'."
+ >&2 echo " --torrent-server the name of the server hosting torrents with hefurd, default is '$TORRENT_SERVER'."
+ >&2 echo " --torrent-user the user hefurd is running as, default is '$TORRENT_USER'."
+ >&2 echo " --magnet-link retrieve magnet link of an already published torrent."
+ [ -z "$1" ] && exit 1 || exit "$1"
+}
+
+# fail on first error
+set -e
+
+# cleanup hook
+tmp_dir="$(mktemp -d)"
+cleanup() {
+ if [ "${no_cleanup}" = 0 ]; then
+ if mountpoint -q "${tmp_dir}"; then
+ sudo umount "${tmp_dir}"
+ fi
+ rm -rf --one-file-system "${tmp_dir}"
+ fi
+}
+trap cleanup EXIT
+
+eval set -- "$(
+ getopt -o h \
+ --long help \
+ --long arch: \
+ --long date: \
+ --long mirror-dir: \
+ --long torrent-server: \
+ --long torrent-user: \
+ --long magnet-link \
+ -n "$(basename "$0")" -- "$@" || \
+ echo usage
+)"
+
+arch="$ARCH"
+date="$DATE"
+mirror_dir="$MIRROR_DIR"
+iso="${iso}"
+torrent_server="$TORRENT_SERVER"
+torrent_user="$TORRENT_USER"
+hefur_dir="$HEFUR_DIR"
+magnet_link=0
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ '--arch')
+ shift
+ arch="$1"
+ ;;
+ '--date')
+ shift
+ date="$1"
+ ;;
+ '--mirror-dir')
+ shift
+ mirror_dir="$1"
+ ;;
+ '--torrent-server')
+ shift
+ torrent_server="$1"
+ ;;
+ '--torrent-user')
+ shift
+ torrent_user="$1"
+ ;;
+ '--magnet-link')
+ magnet_link=1
+ ;;
+ '--help'|'-h')
+ usage 0
+ ;;
+ '--')
+ shift
+ break
+ ;;
+ *)
+ >&2 printf 'Whoops, option "%s" is not yet implemented!\n' "$1" >&2
+ exit 42
+ ;;
+ esac
+ shift
+done
+
+if [ $# -gt 0 ]; then
+ >&2 echo 'Too many arguments.'
+ exit 2
+fi
+
+archiso_dir="$mirror_dir/archisos"
+iso="archlinux32-$date-$arch.iso"
+
+# retrieve the magnet link (for publishing on the webpage)
+if [ $magnet_link = 1 ]; then
+ magnet_link="$(transmission-show --magnet "$archiso_dir/${iso}.torrent")"
+ echo "$magnet_link"
+ exit 0
+fi
+
+declare -a available_mirrors
+mirrorlist="$(cat /etc/pacman.d/mirrorlist32 | grep Server | cut -d '=' -f 2 | sed -e 's/\s//g;s_$arch/$repo_archisos/_')"
+available_mirrors=($mirrorlist)
+
+if [ ! -f "$archiso_dir/${iso}" ] ; then
+ >&2 echo "'${iso}' not found."
+ exit 1
+fi
+
+# create web seed as the list of all mirrors and create the torrent
+# file, announce it on the torrent server
+function join_by { local IFS="$1"; shift; echo "$*"; }
+web_seed="$(join_by ',' "${available_mirrors[@]}")"
+torrent_file="${iso}.torrent"
+
+rm -f "${archiso_dir}/${torrent_file}"
+mktorrent --announce=http://${torrent_server}:6969/announce \
+ --web-seed="${web_seed}" \
+ --output="${archiso_dir}/${torrent_file}" \
+ "${archiso_dir}/${iso}"
+
+scp "${archiso_dir}/${torrent_file}" "${torrent_user}@${torrent_server}:${hefur_dir}"
+
+exit 0