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.
 
 
 
 

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