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.
 
 
 
 

172 lines
8.5 KiB

  1. ---
  2. title: Making FreeBSD magnet links
  3. description: >
  4. Making FreeBSD magnet links
  5. posted: !!timestamp '2018-07-03'
  6. created: !!timestamp '2018-07-03'
  7. time: 4:49 PM
  8. tags:
  9. - FreeBSD
  10. - magnet
  11. ---
  12. <blockquote><span style="font-size:2em">⚠</span>️ This post is old, the most up to date one is
  13. <a href="/2022/12/making-freebsd-magnet-links.html">here</a>.</blockquote>
  14. For the last few years, I've been producing torrents and publishing
  15. magnet links, but there is some special work that I do to make these.
  16. The first few releases, I inserted a bogus tracker into the torrent,
  17. because despite there being plenty of tools out there for producing
  18. trackerless (DHT) torrents, they were all GUI and I never found any that
  19. were command line based. The other was there was/is no tool for
  20. extracting the info hash and building the magnet link. There may be
  21. tools now, but I couldn't find any when I started 3 years ago.
  22. The following steps are based upon the recent release of FreeBSD 11.2&#x2011;R,
  23. adjust as necessary.
  24. <ol>
  25. <li>Fetch FreeBSD into a directory (I create a per release directory). There
  26. are a few directories that you have mirror, I use wget for this. The
  27. mirroring feature for wget isn't great. After each command I have to
  28. remove the <code>CHECKSUM.SHA256</code>, <code>CHECKSUM.SHA512</code> and <code>index.html*</code> files.
  29. <pre class="fullwidth"><code>
  30. $ wget -c -r -l 1 -nd --limit-rate=800k https://download.freebsd.org/ftp/releases/ISO-IMAGES/11.2/
  31. $ wget -c -r -l 1 -nd --limit-rate=800k https://download.freebsd.org/ftp/releases/VM-IMAGES/11.2-RELEASE/aarch64/Latest/
  32. $ wget -c -r -l 1 -nd --limit-rate=800k https://download.freebsd.org/ftp/releases/VM-IMAGES/11.2-RELEASE/amd64/Latest/
  33. $ wget -c -r -l 1 -nd --limit-rate=800k https://download.freebsd.org/ftp/releases/VM-IMAGES/11.2-RELEASE/i386/Latest/
  34. </code></pre>
  35. <li>Fetch the signature files:
  36. <pre class="fullwidth"><code>
  37. $ wget https://www.freebsd.org/releases/11.2R/CHECKSUM.SHA512-FreeBSD-11.2-RELEASE-{amd64,i386,powerpc,powerpc-powerpc64,sparc64,arm64-aarch64}.asc
  38. $ wget https://www.freebsd.org/releases/11.2R/CHECKSUM.SHA512-FreeBSD-11.2-RELEASE-{amd64,i386,arm64-aarch64}-vm.asc
  39. $ wget https://www.freebsd.org/releases/11.2R/CHECKSUM.SHA512-FreeBSD-11.2-RELEASE-arm-armv6-{BANANAPI,BEAGLEBONE,CUBIEBOARD,CUBIEBOARD2,CUBBOX-HUMMINGBOARD,GUMSTIX,PANDABOARD,RPI-B,RPI2,WANDBOARD}.asc
  40. </code></pre>
  41. <li>Verify the GPG key that signed the above files. This is usually Glen
  42. Barber's key, but not always. I have met and verified his fingerprint
  43. in person, If you have verified someone's key who has signed Glen's
  44. key, that is another good way.
  45. <li>Verify the checksum files:
  46. <pre class="fullwidth"><code>
  47. $ for i in *.asc; do gpg --verify $i; done
  48. You should see a bunch of lines like:
  49. Warning: using insecure memory!
  50. gpg: Signature made Fri Jun 22 09:33:50 2018 PDT
  51. gpg: using RSA key 0x031458A5478FE293
  52. gpg: Good signature from "Glen Barber &lt;gjb@FreeBSD.org&gt;" [full]
  53. gpg: aka "Glen Barber &lt;glen.j.barber@gmail.com&gt;" [full]
  54. gpg: aka "Glen Barber &lt;gjb@glenbarber.us&gt;" [full]
  55. gpg: aka "Glen Barber &lt;gjb@keybase.io&gt;" [unknown]
  56. gpg: WARNING: not a detached signature; file 'CHECKSUM.SHA512-FreeBSD-11.2-RELEASE-amd64-vm' was NOT verified!
  57. </code></pre>The last line can be ignored. The non-<code>.asc</code> files were d/l'd and will
  58. not be used. Make sure that all of the files report <code>Good&nbsp;signature</code>.
  59. <li>In the past I have used BitTornado for other things, so I ended up
  60. using it as the basis to make the tool for creating trackerless torrent
  61. files. The modifications were simple. It appears that the original
  62. BitTornado CVS tree is off-line (anyways, it was served insecurely),
  63. but it looks like
  64. <a href="https://github.com/effigies/BitTornado">effigies/BitTornado</a> is
  65. similar enough that it could be modified and used. I copied
  66. <code>btmakemetafile.py</code> to <code>btmaketrackerless.py</code> and applied the following
  67. patch:
  68. <pre class="fullwidth"><code>
  69. $ diff -u btmakemetafile.py btmaketrackerless.py
  70. --- btmakemetafile.py 2004-05-24 12:54:52.000000000 -0700
  71. +++ btmaketrackerless.py 2016-10-10 17:13:32.742081000 -0700
  72. @@ -23,9 +23,9 @@
  73. def prog(amount):
  74. print '%.1f%% complete\r' % (amount * 100),
  75. -if len(argv) &lt; 3:
  76. +if len(argv) &lt; 2:
  77. a,b = split(argv[0])
  78. - print 'Usage: ' + b + ' &lt;trackerurl&gt; &lt;file&gt; [file...] [params...]'
  79. + print 'Usage: ' + b + ' &lt;file&gt; [file...] [params...]'
  80. print
  81. print formatDefinitions(defaults, 80)
  82. print_announcelist_details()
  83. @@ -33,9 +33,9 @@
  84. exit(2)
  85. try:
  86. - config, args = parseargs(argv[1:], defaults, 2, None)
  87. - for file in args[1:]:
  88. - make_meta_file(file, args[0], config, progress = prog)
  89. + config, args = parseargs(argv[1:], defaults, 1, None)
  90. + for file in args[0:]:
  91. + make_meta_file(file, None, config, progress = prog)
  92. except ValueError, e:
  93. print 'error: ' + str(e)
  94. print 'run with no args for parameter explanations'
  95. </code></pre>
  96. If you notice, the only thing that is done is to drop the first argument,
  97. and instead of passing it into <code>make_meta_file</code>, a <code>None</code> is passed
  98. instead. This will simply not add trackers to the torrent file.
  99. <li>I then run the following script to verify the downloaded files, and
  100. generate the torrent files:
  101. <pre class="fullwidth"><code>
  102. $ cat cmp.sh
  103. #!/bin/sh -
  104. # wget -c -r -l 1 -nd --limit-rate=800k https://download.freebsd.org/ftp/releases/ISO-IMAGES/11.2/
  105. # wget -c -r -l 1 -nd --limit-rate=800k https://download.freebsd.org/ftp/releases/VM-IMAGES/11.2-RELEASE/aarch64/Latest/
  106. # wget -c -r -l 1 -nd --limit-rate=800k https://download.freebsd.org/ftp/releases/VM-IMAGES/11.2-RELEASE/amd64/Latest/
  107. # wget -c -r -l 1 -nd --limit-rate=800k https://download.freebsd.org/ftp/releases/VM-IMAGES/11.2-RELEASE/i386/Latest/
  108. # wget https://www.freebsd.org/releases/11.2R/CHECKSUM.SHA512-FreeBSD-11.2-RELEASE-{amd64,i386,powerpc,powerpc-powerpc64,sparc64,arm64-aarch64}.asc
  109. # wget https://www.freebsd.org/releases/11.2R/CHECKSUM.SHA512-FreeBSD-11.2-RELEASE-{amd64,i386,arm64-aarch64}-vm.asc
  110. # wget https://www.freebsd.org/releases/11.2R/CHECKSUM.SHA512-FreeBSD-11.2-RELEASE-arm-armv6-{BANANAPI,BEAGLEBONE,CUBIEBOARD,CUBIEBOARD2,CUBBOX-HUMMINGBOARD,GUMSTIX,PANDABOARD,RPI-B,RPI2,WANDBOARD}.asc
  111. grep -h '^SHA512' CHECK*.asc | sed -e 's/SHA512 (\(.*\)) = \(.*\)/\2 \1/' | sort -k 2 &gt; sha512.from.asc
  112. while read hash fname; do
  113. if [ -e "$fname" ]; then
  114. sigfile=`grep -l -- "$fname" *.asc | head -n 1`
  115. echo checking "$fname", sig in: "$sigfile"
  116. #res=`sha512 -q "$fname"`
  117. res=`shasum -a 512 "$fname" | awk '{ print $1 }'`
  118. echo "File is: $res"
  119. if [ x"$res" != x"$hash" ]; then
  120. echo missmatch! "$fname"
  121. exit 1
  122. fi
  123. if ! [ -e "$fname".torrent ]; then
  124. btmaketrackerless.py "$fname"
  125. fi
  126. else
  127. echo missing "$fname"
  128. exit 1
  129. fi
  130. done &lt; sha512.from.asc
  131. </code></pre>
  132. <li>Once all the torrents have been generated, I then make the magnet
  133. links:
  134. <pre class="fullwidth"><code>
  135. $ cat btmakemagnet.sh
  136. #!/bin/sh -
  137. # metainfo file.: FreeBSD-10.3-RELEASE-sparc64-bootonly.iso.torrent
  138. # info hash.....: 06091dabce1296d11d1758ffd071e7109a92934f
  139. # file name.....: FreeBSD-10.3-RELEASE-sparc64-bootonly.iso
  140. # file size.....: 203161600 (775 * 262144 + 0)
  141. # announce url..: udp://tracker.openbittorrent.com:80
  142. # btshowmetainfo 20030621 - decode BitTorrent metainfo files
  143. for i in *.torrent; do
  144. btshowmetainfo.py "$i" | awk '
  145. $0 ~ "^info hash" { info = $3 }
  146. $0 ~ "^file name" { name = $3 }
  147. END {
  148. print "magnet:?xt=urn:btih:" info "&dn=" name
  149. }'
  150. done
  151. </code></pre>
  152. <li>I then create the magnet links file, and update the
  153. <a href="https://wiki.freebsd.org/Torrents">Torrents</a> wiki page.
  154. </ol>
  155. <s>Sorry about the code formatting. I don't know how to make it look better
  156. in blogger.</s><label for="sn-blogger" class="margin-toggle
  157. sidenote-number"></label><input type="checkbox" id="sn-blogger"
  158. class="margin-toggle"/><span class="sidenote">This blog
  159. no longer uses blogger.</span>