blob: 0c11e06e2eac0ccc4a68cbb93d4f92ec604eb280 (
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#!/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}"
# I have to go over port 9586, copying manually ATM
#scp -P "${torrent_ssh_port}" "${archiso_dir}/${torrent_file}" "${torrent_user}@${torrent_server}:${hefur_dir}"
exit 0
|