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.
 
 
 
 

174 lines
7.6 KiB

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