From 28a3048aa76b21d9852738059ef64e8714a12dda 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 | 36 +++++++++++++++++++ parabolaiso/mkmetadata | 69 +++++++++++++++++++++++++++++++++++++ parabolaiso/mkparabolaiso | 8 ++--- 4 files changed, 111 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..4b385ef --- /dev/null +++ b/parabolaiso/TORRENT_METADATA.sample @@ -0,0 +1,36 @@ +# metadata requisites: 'mktorrent', 'rhash' +# if these are not installed, then no .torrent, magnet, or checksum files will be created +# to enable .torrent file generation, copy this file to ./TORRENT_METADATA + +# all of the constant values in this sample file are specific to parabola official releases +# for custom ISOs, all of these values should be changed in ./TORRENT_METADATA +# if a torrent file is not desired, then this file can be ignored + + +# 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 _RELEASE_ Release" + +# ISOS_URL (string) +# is used to make a URL to the master repo where the ISO will be hosted +# the torrent comment will indicate this as the location of the canonical GPG signature +readonly ISOS_URL=https://repo.parabola.nu/iso diff --git a/parabolaiso/mkmetadata b/parabolaiso/mkmetadata new file mode 100755 index 0000000..263f63b --- /dev/null +++ b/parabolaiso/mkmetadata @@ -0,0 +1,69 @@ +#!/bin/bash + +readonly OUT_DIR=$1 +readonly IMG_NAME=$2 +readonly PKGLIST="$(readlink -f $3 2> /dev/null)" +readonly THIS_DIR="$(readlink -f "$(dirname $0)")" + +# if an optional .torrent file is desired, see ./TORRENT_METADATA.sample +[[ -f "$THIS_DIR/TORRENT_METADATA" ]] && source "$THIS_DIR/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 PUBLIC_URL="${ISOS_URL}/$(basename ${OUT_DIR})" +[[ -n "${ISOS_URL}" ]] && readonly SIG_URL="${PUBLIC_URL}/${IMG_NAME}.sig" +[[ -n "${ISOS_URL}" ]] && readonly PUBLISH_MSG="The directory: '${OUT_DIR}' should be copied to the repo server entirely, preserving the directory name; such that it is accessible via the URL:\n\t${PUBLIC_URL}/\nThe GPG signature of the ISO should be added to that directory; such that it is accessible at the URL:\n\t${SIG_URL}" + +readonly ISO_HOST_PATH=$(echo "$(basename ${OUT_DIR})/${IMG_NAME}" | sed 's|\s|%20|') +readonly WEBSEEDS_CSV=$(echo ${TORRENT_WEBSEED_URLS} | sed -E "s|([^ ]+)|\1${ISO_HOST_PATH}|g" | tr ' ' ',') + +readonly PKGLIST_SUCCESS_MSG="\t=> copied $(basename ${PKGLIST} 2> /dev/null)" +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" +readonly RHASH_NOT_FOUND_MSG="[mkmetadata]: 'rhash' is not installed - metadata files will not be created" +readonly MAKE_METADATA_MSG="[mkmetadata]: preparing metadata" + + +MakeMetadata() +{ + # copy package lists and generate checksums and optional torrent file + (( ${SHOULD_MKTORRENT} )) && MakeTorrent && echo -e ${TORRENT_SUCCESS_MSG} + [[ -f "${PKGLIST}" ]] && 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} + + sort SHA512SUMS --key=2 --output=SHA512SUMS + sort WHIRLPOOLSUMS --key=2 --output=WHIRLPOOLSUMS +} + +MakeTorrent() +{ + local release=$( sed 's|[^-]*-\(.*\)-\(.*\)-\(.*\)-\(.*\)-\(.*\)\.iso|\u\1/\U\2 \L\3 \u\4 \5|' <<<${IMG_NAME}) + local sig="$( [[ -n "${ISOS_URL}" ]] && echo "GPG signature: '${SIG_URL}")" + local comment="$(sed 's|_RELEASE_|'"${release}"'|' <<<${TORRENT_COMMENT})\n${sig}" + + # generate torrent file + mktorrent --announce=${TORRENT_ANNOUNCE_URL} \ + --comment="${comment}" \ + $([[ -n "${WEBSEEDS_CSV}" ]] && echo "--web-seed=${WEBSEEDS_CSV}") \ + --piece-length=20 --no-date --verbose \ + "${IMG_NAME}" +} + +if ! (( ${HAS_RHASH} )) +then echo "$RHASH_NOT_FOUND_MSG" +elif [[ -d "${OUT_DIR}" ]] && [[ -f "${OUT_DIR}/${IMG_NAME}" ]] +then echo "$MAKE_METADATA_MSG" + + pushd ${OUT_DIR} > /dev/null + MakeMetadata + popd > /dev/null +fi + +[[ -n "${ISOS_URL}" ]] && echo -e "\n${PUBLISH_MSG}\n" 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