From f43000503280370733138fdd311b18936a92d452 Mon Sep 17 00:00:00 2001 From: Simon Doppler Date: Mon, 7 Aug 2017 17:06:13 +0200 Subject: Build both architectures at the same time --- README.md | 7 ++- al32-mktorrent.sh | 125 +++++++++++++++++++++++++++++------------------------- 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 427daca..24c8fa7 100644 --- a/README.md +++ b/README.md @@ -4,20 +4,19 @@ Torrent creation script for [ArchLinux32](https://archlinux32.org) ## Usage - al32-mktorrent.sh [ -d date ] [ i686 | dual ] + al32-mktorrent.sh [ -d date ] -If no architecture is specified, the script will default to `i686`. If no date is specified, the script will prompt for a date during the process. ## Features -* [ ] Torrent creation +* [x] Torrent creation * [x] Create a torrent file per architecture * [x] Obtain the latest mirrorlist * [x] Check mirrors for ISO availability * [x] Download ISO * [x] Check ISO - * [ ] Create both torrent files at once + * [x] Create both torrent files at once * [x] Create a magnet link per architecture * [ ] Torrent upload * [ ] Upload the torrent file to a server via SSH (for sharing) diff --git a/al32-mktorrent.sh b/al32-mktorrent.sh index 3fdb196..3c1090a 100644 --- a/al32-mktorrent.sh +++ b/al32-mktorrent.sh @@ -17,7 +17,7 @@ set -euo pipefail function join_by { local IFS="$1"; shift; echo "$*"; } usage () { - echo "Usage: $0 [-d date] [i686|dual]" + echo "Usage: $0 [-d date]" } fg_green="\033[32m" @@ -28,6 +28,70 @@ fg_bold="\033[1m" MIRRORLIST_FILE="https://raw.githubusercontent.com/archlinux32/packages/master/core/pacman-mirrorlist/mirrorlist" +function create_torrent_for_arch () { + mirrorlist="$(curl "$MIRRORLIST_FILE" 2>/dev/null | grep Server | cut -d '=' -f 2 | sed -e 's/\s//g;s_$arch/$repo_archisos/_')" + + if [ "$#" -eq 0 ] ; then + echo "No architecture specified, selecting 'i686'" + arch="i686" + elif [ "$#" -eq 1 ] ; then + echo "Selecting architecture '$1'" + arch="$1" + else + usage + echo "Too many arguments, exiting" >&2 + exit 1 + fi + + iso_string="archlinux-$iso_date-$arch.iso" + + for i in $mirrorlist ; do + echo -n -e "$fg_reset${fg_bold}Checking $fg_reset$fg_blue$i$fg_reset " + curl -g "$i" 2>/dev/null | grep -q "$iso_string" && ( + echo -e "$fg_reset${fg_green}OK$fg_reset" + ) || ( echo -e "$fg_reset${fg_red}Failed$fg_reset" ; false ) || continue + available_mirrors=(${available_mirrors[@]} "$i") + done + + echo "${#available_mirrors[@]} mirrors available" + + + if [ ! -f "$iso_string" ] ; then + echo -e "$fg_reset${fg_bold}Downloading iso...$fg_reset" + curl -O "${available_mirrors[0]}$iso_string" + else + echo -e "$fg_reset${fg_bold}Reusing already downloaded iso...$fg_reset" + fi + + + echo -e "$fg_reset${fg_bold}Downloading verification files...$fg_reset" + curl -O "${available_mirrors[0]}$iso_string.sig" + curl -O "${available_mirrors[0]}sha512sums" + + echo -n -e "$fg_reset${fg_bold}Checking PGP signature...$fg_reset " + gpg --verify "$iso_string.sig" "$iso_string" || exit 100 + echo -e "$fg_reset${fg_green}OK" + + echo -e "$fg_reset${fg_bold}Checking SHA512 sums...$fg_reset" + sha512sum --ignore-missing --check sha512sums || exit 101 + + echo -e "$fg_reset${fg_bold}Create torrent file...$fg_reset" + if [ -f "$iso_string.torrent" ] ; then + rm "$iso_string.torrent" + fi + mktorrent --announce=http://dopsi.ch:6969/announce --web-seed="$(join_by ',' "${available_mirrors[@]}")" "$iso_string" + + echo -e "$fg_reset${fg_bold}Create magnet link...$fg_reset" + magnet_link="$(transmission-show --magnet "$iso_string.torrent")" + echo "$magnet_link" + + echo -e "$fg_reset${fg_bold}Create RSS feed files...$fg_reset" + python magnet2feed.py "$magnet_link" "$iso_date" +} + +### Actual program + +declare -a architectures=("i686" "dual") declare -a available_mirrors iso_date='' @@ -50,63 +114,8 @@ shift $((OPTIND-1)) [ -z "$iso_date" ] && read -r -p "Date of the ISO: " iso_date -mirrorlist="$(curl "$MIRRORLIST_FILE" 2>/dev/null | grep Server | cut -d '=' -f 2 | sed -e 's/\s//g;s_$arch/$repo_archisos/_')" - -if [ "$#" -eq 0 ] ; then - echo "No architecture specified, selecting 'i686'" - arch="i686" -elif [ "$#" -eq 1 ] ; then - echo "Selecting architecture '$1'" - arch="$1" -else - usage - echo "Too many arguments, exiting" >&2 - exit 1 -fi - -iso_string="archlinux-$iso_date-$arch.iso" - -for i in $mirrorlist ; do - echo -n -e "$fg_reset${fg_bold}Checking $fg_reset$fg_blue$i$fg_reset " - curl -g "$i" 2>/dev/null | grep -q "$iso_string" && ( - echo -e "$fg_reset${fg_green}OK$fg_reset" - ) || ( echo -e "$fg_reset${fg_red}Failed$fg_reset" ; false ) || continue - available_mirrors=(${available_mirrors[@]} "$i") +for a in "${architectures[@]}" ; do + create_torrent_for_arch "$a" done -echo "${#available_mirrors[@]} mirrors available" - - -if [ ! -f "$iso_string" ] ; then - echo -e "$fg_reset${fg_bold}Downloading iso...$fg_reset" - curl -O "${available_mirrors[0]}$iso_string" -else - echo -e "$fg_reset${fg_bold}Reusing already downloaded iso...$fg_reset" -fi - - -echo -e "$fg_reset${fg_bold}Downloading verification files...$fg_reset" -curl -O "${available_mirrors[0]}$iso_string.sig" -curl -O "${available_mirrors[0]}sha512sums" - -echo -n -e "$fg_reset${fg_bold}Checking PGP signature...$fg_reset " -gpg --verify "$iso_string.sig" "$iso_string" || exit 100 -echo -e "$fg_reset${fg_green}OK" - -echo -e "$fg_reset${fg_bold}Checking SHA512 sums...$fg_reset" -sha512sum --ignore-missing --check sha512sums || exit 101 - -echo -e "$fg_reset${fg_bold}Create torrent file...$fg_reset" -if [ -f "$iso_string.torrent" ] ; then - rm "$iso_string.torrent" -fi -mktorrent --announce=http://dopsi.ch:6969/announce --web-seed="$(join_by ',' "${available_mirrors[@]}")" "$iso_string" - -echo -e "$fg_reset${fg_bold}Create magnet link...$fg_reset" -magnet_link="$(transmission-show --magnet "$iso_string.torrent")" -echo "$magnet_link" - -echo -e "$fg_reset${fg_bold}Create RSS feed files...$fg_reset" -python magnet2feed.py "$magnet_link" "$iso_date" - # vim: set ts=4 sw=4: -- cgit v1.2.3