The blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

173 lines
7.5 KiB

  1. ---
  2. title: Making FreeBSD magnet links
  3. description: >
  4. Making FreeBSD magnet links
  5. created: !!timestamp '2018-07-03'
  6. time: 4:49 PM
  7. updated: !!timestamp '2022-12-07'
  8. updated_time: 12:20 PM
  9. tags:
  10. - FreeBSD
  11. - magnet
  12. ---
  13. Note: This was originally posted
  14. <a href="/2018/07/making-freebsd-magnet-links.html#making-freebsd-magnet-links-title">here</a>,
  15. but things have been improved since then and so it has been updated.
  16. For the last few years, I've been producing torrents and publishing
  17. magnet links, but there is some special work that I do to make these.
  18. The first few releases, I inserted a bogus tracker into the torrent,
  19. because despite there being plenty of tools out there for producing
  20. trackerless (DHT) torrents, they were all GUI and I never found any that
  21. were command line based. The other was there was/is no tool for
  22. extracting the info hash and building the magnet link. There may be
  23. tools now, but I couldn't find any when I started 3 years ago.
  24. The following steps are based upon the recent release of FreeBSD 11.2&#x2011;R,
  25. adjust as necessary.
  26. <ol>
  27. <li>Fetch the FreeBSD release and release announcement into a directory
  28. (I create a per release directory).
  29. remove the <code>CHECKSUM.SHA256</code>, <code>CHECKSUM.SHA512</code> and <code>index.html*</code> files.
  30. <pre class="fullwidth"><code>
  31. $ REL=12.4-RELEASE
  32. $ RELABV=12.4R
  33. $ curl https://www.funkthat.com/~jmg/FreeBSD-snap/snapshot.idx.xz | xzcat | awk ' $2 == "'"$REL"'" { print $9 }' | xargs -L 1 -P 3 wget --no-verbose -c --limit-rate=7000k
  34. $ wget https://www.freebsd.org/releases/$RELABV/announce.asc
  35. </code></pre>
  36. This step depends upon
  37. <a href="https://funkthat.com/gitea/jmg/snapaid">snapaid</a> running.
  38. If it is no longer running for some reason, <code>addinfo.sh</code> could
  39. be run manually against the release email (not the downloaded
  40. <code>announce.asc</code> file as the message id is needed) to generate
  41. snapshot.idx.xz locally, and use that instead.
  42. <li>Verify the GPG key that signed the above files. This is usually Glen
  43. Barber's key, but not always. I have met and verified his fingerprint
  44. in person, If you have verified someone's key who has signed Glen's
  45. key, that is another good way.
  46. <li>Verify the release announcement:
  47. <pre class="fullwidth"><code>
  48. $ gpg --verify announce.asc
  49. Warning: using insecure memory!
  50. gpg: Signature made Mon Dec 5 17:34:59 2022 PST using RSA key ID 478FE293
  51. gpg: Good signature from "Glen Barber <gjb@FreeBSD.org>" [unknown]
  52. gpg: aka "Glen Barber <gjb@keybase.io>" [unknown]
  53. gpg: aka "Glen Barber <gjb@glenbarber.us>" [unknown]
  54. gpg: aka "Glen Barber <glen.j.barber@gmail.com>" [unknown]
  55. gpg: WARNING: This key is not certified with a trusted signature!
  56. gpg: There is no indication that the signature belongs to the owner.
  57. Primary key fingerprint: 78B3 42BA 26C7 B2AC 681E A7BE 524F 0C37 A0B9 46A3
  58. Subkey fingerprint: 8D12 403C 2E6C AB08 6CF6 4DA3 0314 58A5 478F E293
  59. </code></pre>
  60. <li>In the past I have used BitTornado for other things, so I ended up
  61. using it as the basis to make the tool for creating trackerless torrent
  62. files. The modifications were simple. It appears that the original
  63. BitTornado CVS tree is off-line (anyways, it was served insecurely),
  64. but it looks like
  65. <a href="https://github.com/effigies/BitTornado">effigies/BitTornado</a> is
  66. similar enough that it could be modified and used. I copied
  67. <code>btmakemetafile.py</code> to <code>btmaketrackerless.py</code> and applied the following
  68. patch:
  69. <pre class="fullwidth"><code>
  70. $ diff -u btmakemetafile.py btmaketrackerless.py
  71. --- btmakemetafile.py 2004-05-24 12:54:52.000000000 -0700
  72. +++ btmaketrackerless.py 2016-10-10 17:13:32.742081000 -0700
  73. @@ -23,9 +23,9 @@
  74. def prog(amount):
  75. print '%.1f%% complete\r' % (amount * 100),
  76. -if len(argv) &lt; 3:
  77. +if len(argv) &lt; 2:
  78. a,b = split(argv[0])
  79. - print 'Usage: ' + b + ' &lt;trackerurl&gt; &lt;file&gt; [file...] [params...]'
  80. + print 'Usage: ' + b + ' &lt;file&gt; [file...] [params...]'
  81. print
  82. print formatDefinitions(defaults, 80)
  83. print_announcelist_details()
  84. @@ -33,9 +33,9 @@
  85. exit(2)
  86. try:
  87. - config, args = parseargs(argv[1:], defaults, 2, None)
  88. - for file in args[1:]:
  89. - make_meta_file(file, args[0], config, progress = prog)
  90. + config, args = parseargs(argv[1:], defaults, 1, None)
  91. + for file in args[0:]:
  92. + make_meta_file(file, None, config, progress = prog)
  93. except ValueError, e:
  94. print 'error: ' + str(e)
  95. print 'run with no args for parameter explanations'
  96. </code></pre>
  97. If you notice, the only thing that is done is to drop the first argument,
  98. and instead of passing it into <code>make_meta_file</code>, a <code>None</code> is passed
  99. instead. This will simply not add trackers to the torrent file.
  100. <li>I then run the following script to verify the downloaded files, and
  101. generate the torrent files:
  102. <pre class="fullwidth"><code>
  103. $ cat cmp.sh
  104. #!/bin/sh -
  105. # REL=12.4-RELEASE
  106. # RELABV=12.4R
  107. # xzcat ~jmg/public_html/FreeBSD-snap/snapshot.idx.xz | awk ' $2 == "'"$REL"'" { print $9 }' | xargs -L 1 -P 3 wget --no-verbose -c --limit-rate=7000k
  108. # XXX - following command 404, manually saved from relase announcement
  109. # wget https://www.freebsd.org/releases/$RELABV/announce.asc
  110. # wget -c https://download.freebsd.org/ftp/releases/CI-IMAGES/$REL/amd64/Latest/FreeBSD-$REL-amd64-BASIC-CI.raw.xz
  111. # wget -c https://download.freebsd.org/ftp/releases/VM-IMAGES/$REL/riscv64/Latest/FreeBSD-$REL-riscv-riscv64.{qcow2,raw,vhd,vmdk}.xz
  112. grep -h '^ SHA512' announce.asc | sed -e 's/SHA512 (\(.*\)) = \(.*\)/\2 \1/' | sort -k 2 &gt; sha512.from.asc
  113. while read hash fname; do
  114. if [ -e "$fname" ]; then
  115. if [ -e "$fname".torrent ]; then
  116. echo skipping "$fname"...
  117. continue
  118. fi
  119. sigfile=$(grep -l -- "$fname" *.asc | head -n 1)
  120. echo checking "$fname", sig in: "$sigfile"
  121. #res=`sha512 -q "$fname"`
  122. #res=`shasum -a 512 "$fname" | awk '{ print $1 }'`
  123. res=$(openssl sha512 &lt; "$fname" | awk '{ print $2 }')
  124. echo "File is: $res"
  125. if [ x"$res" != x"$hash" ]; then
  126. echo missmatch! "$fname"
  127. exit 1
  128. fi
  129. btmaketrackerless.py "$fname" &
  130. else
  131. echo missing "$fname"
  132. exit 1
  133. fi
  134. done &lt; sha512.from.asc
  135. </code></pre>
  136. <li>Once all the torrents have been generated, I then make the magnet
  137. links:
  138. <pre class="fullwidth"><code>
  139. $ cat btmakemagnet.sh
  140. #!/bin/sh -
  141. # metainfo file.: FreeBSD-10.3-RELEASE-sparc64-bootonly.iso.torrent
  142. # info hash.....: 06091dabce1296d11d1758ffd071e7109a92934f
  143. # file name.....: FreeBSD-10.3-RELEASE-sparc64-bootonly.iso
  144. # file size.....: 203161600 (775 * 262144 + 0)
  145. # announce url..: udp://tracker.openbittorrent.com:80
  146. # btshowmetainfo 20030621 - decode BitTorrent metainfo files
  147. for i in *.torrent; do
  148. btshowmetainfo.py "$i" | awk '
  149. $0 ~ "^info hash" { info = $3 }
  150. $0 ~ "^file name" { name = $3 }
  151. END {
  152. print "magnet:?xt=urn:btih:" info "&dn=" name
  153. }'
  154. done
  155. </code></pre>
  156. <li>I then create the magnet links file, and update the
  157. <a href="https://wiki.freebsd.org/Torrents">Torrents</a> wiki page.
  158. </ol>