From c53758dff8d589207d68a34164e7b70f8fdb352e Mon Sep 17 00:00:00 2001 From: bill-auger Date: Tue, 29 May 2018 01:58:02 -0400 Subject: create torrent and magnet files --- .gitignore | 3 ++ parabolaiso/TORRENT_METADATA.sample | 27 ++++++++++++++++++ parabolaiso/mkmetadata | 56 +++++++++++++++++++++++++++++++++++++ parabolaiso/mkparabolaiso | 8 ++---- 4 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 parabolaiso/TORRENT_METADATA.sample create mode 100755 parabolaiso/mkmetadata diff --git a/.gitignore b/.gitignore index 59bd84b..0a6961c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ isorepo* # helpers continue.sh + +# local config +parabolaiso/TORRENT_METADATA diff --git a/parabolaiso/TORRENT_METADATA.sample b/parabolaiso/TORRENT_METADATA.sample new file mode 100644 index 0000000..ad4427a --- /dev/null +++ b/parabolaiso/TORRENT_METADATA.sample @@ -0,0 +1,27 @@ + +# TORRENT_ANNOUNCE_URL (string) +# will be embedded into the .torrent file +# if this is not defined, then no .torrent file will be created +readonly TORRENT_ANNOUNCE_URL="http://torrent.resonatingmedia.com:6969/announce" + +# TORRENT_WEBSEED_URLS (newline-separated list of strings) +# will be embedded into the .torrent file +readonly TORRENT_WEBSEED_URLS=" +http://mirror.grapentin.org/parabola/iso/ +http://jeweet.net/repo/parabola/iso/ +http://mirror.yandex.ru/mirrors/parabola/iso/ +http://mirror.fsf.org/parabola/iso/ +http://parabola.serverpit.com/iso/ +http://mirror.freedif.org/Parabola/iso/ +http://ftp.acc.umu.se/mirror/parabola.nu/iso/ +" + +# TORRENT_COMMENT (string) +# will be embedded into the .torrent file +# if ISOS_URL is defined below, a URL will be appended to this, pointing +# to where the GPG signature of the ISO will be expected to be hosted +readonly TORRENT_COMMENT="Parabola GNU/Linux-libre Official Release - GPG signature: " + +# ISOS_URL (string) +# is used to make a URL to where the ISO and GPG signature will be hosted +readonly ISOS_URL=https://repo.parabola.nu/iso diff --git a/parabolaiso/mkmetadata b/parabolaiso/mkmetadata new file mode 100755 index 0000000..c00b98c --- /dev/null +++ b/parabolaiso/mkmetadata @@ -0,0 +1,56 @@ +#!/bin/bash + +readonly OUT_DIR=$1 +readonly IMG_NAME=$2 +readonly PKGLIST=$(readlink -f $3) + +# if an optional .torrent file is desired, see ./TORRENT_METADATA.sample +[[ -f ./TORRENT_METADATA ]] && source ./TORRENT_METADATA + +which mktorrent &> /dev/null && readonly HAS_MKTORRENT=1 || readonly HAS_MKTORRENT=0 +which rhash &> /dev/null && readonly HAS_RHASH=1 || readonly HAS_RHASH=0 +[[ -n "${TORRENT_ANNOUNCE_URL}" ]] && readonly SHOULD_MKTORRENT=${HAS_MKTORRENT} || \ + readonly SHOULD_MKTORRENT=0 +[[ -n "${ISOS_URL}" ]] && readonly SIG_URL=${ISOS_URL}/$(basename ${OUT_DIR})/${IMG_NAME}.sig +[[ -n "${ISOS_URL}" ]] && readonly SIGURL_MSG="GPG signature is expected to be at: ${SIG_URL}" +readonly ISO_HOST_PATH=$(echo "$(basename ${OUT_DIR})/${IMG_NAME}" | sed 's|\s|%20|') +readonly WEBSEEDS_CSV=$(echo $urls | sed -E "s|([^ ]+)|\1${ISO_HOST_PATH}|g" | tr ' ' ',') + +readonly PKGLIST_SUCCESS_MSG="\t=> copied $(basename ${PKGLIST})" +readonly SHA512SUMS_SUCCESS_MSG="\t=> SHA512SUMS appended" +readonly WHIIRLPOOLSUMS_SUCCESS_MSG="\t=> WHIRLPOOLSUMS appended" +readonly MAGNET_SUCCESS_MSG="\t=> ${IMG_NAME}.magnet saved" +readonly TORRENT_SUCCESS_MSG="\t=> ${IMG_NAME}.torrent saved\n${SIGURL_MSG}" + + +MakeMetadata() +{ + # copy package lists and create checksums and optional torrent file + cp ${PKGLIST} . && echo -e ${PKGLIST_SUCCESS_MSG} + rhash --sha512 "${IMG_NAME}" >> SHA512SUMS && echo -e ${SHA512SUMS_SUCCESS_MSG} + rhash --whirlpool "${IMG_NAME}" >> WHIRLPOOLSUMS && echo -e ${WHIIRLPOOLSUMS_SUCCESS_MSG} + rhash --magnet "${IMG_NAME}" > "${IMG_NAME}.magnet" && echo -e ${MAGNET_SUCCESS_MSG} + (( ${SHOULD_MKTORRENT} )) && MakeTorrent && echo -e ${TORRENT_SUCCESS_MSG} + + sort SHA512SUMS --key=2 --output=SHA512SUMS + sort WHIRLPOOLSUMS --key=2 --output=WHIRLPOOLSUMS +} + +MakeTorrent() +{ + # create torrent file + mktorrent --announce=${TORRENT_ANNOUNCE_URL} \ + --comment="${TORRENT_COMMENT}${SIG_URL}" \ + $([[ -n "${WEBSEEDS_CSV}" ]] && echo "--web-seed=${WEBSEEDS_CSV}") \ + --piece-length=20 --no-date --verbose \ + "${IMG_NAME}" +} + + +if (( ${HAS_RHASH} )) && (( $# == 3 )) +then echo "[mkmetadata]: preparing metadata" + + pushd ${OUT_DIR} > /dev/null + MakeMetadata + popd > /dev/null +fi diff --git a/parabolaiso/mkparabolaiso b/parabolaiso/mkparabolaiso index 248879e..eb2366e 100755 --- a/parabolaiso/mkparabolaiso +++ b/parabolaiso/mkparabolaiso @@ -514,11 +514,9 @@ command_iso () { "${work_dir}/iso/" _msg_info "Done! | $(ls -sh "${out_dir}/${img_name}")" - cp "${work_dir}/iso/${install_dir}/pkglist.${arch}.txt" ${out_dir}/ - pushd ${out_dir} > /dev/null - sha512sum "${img_name}" >> SHA512SUMS 2> /dev/null || true - rhash --whirlpool "${img_name}" >> WHIRLPOOLSUMS 2> /dev/null || true - popd > /dev/null + # copy package lists and create checksums and optional torrent files + pkglist="${work_dir}/iso/${install_dir}/pkglist.${arch}.txt" + mkmetadata "${out_dir}" "${img_name}" "${pkglist}" || true fi } -- cgit v1.2.2