Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/al32-mktorrent.sh
blob: 6843a9a6d6b636f102a85cbd293a5b054975868f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#! /bin/bash
set -euo pipefail

function join_by { local IFS="$1"; shift; echo "$*"; }

usage () {
	echo "Usage: $0 [-d date] [i686|dual]"
}

fg_green="\033[32m"
fg_red="\033[31m"
fg_blue="\033[34m"
fg_reset="\033[0m"
fg_bold="\033[1m"

MIRRORLIST_FILE="https://raw.githubusercontent.com/archlinux32/packages/master/core/pacman-mirrorlist/mirrorlist"

mirrorlist="$(curl "$MIRRORLIST_FILE" 2>/dev/null | grep Server | cut -d '=' -f 2 | sed -e 's/\s//g;s_$arch/$repo_archisos/_')"

declare -a available_mirrors
iso_date=''

while getopts "u:p:t:f:d:" o; do
    case "${o}" in
        d)
            iso_date=${OPTARG}
            ;;
        *)
            usage
            ;;
    esac
done
shift $((OPTIND-1))

[ -z "$iso_date" ] && read -r -p "Date of the ISO: " iso_date

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"
transmission-show --magnet "$iso_string.torrent"
# vim: set ts=4 sw=4: