Skip to content

Instantly share code, notes, and snippets.

@grantdobbe
Last active February 1, 2022 18:15
Show Gist options
  • Save grantdobbe/e7cd3f45e9d85e3e61578be36359c313 to your computer and use it in GitHub Desktop.
Save grantdobbe/e7cd3f45e9d85e3e61578be36359c313 to your computer and use it in GitHub Desktop.
A script for block-filling a disk with Wikipedia (rather than zero-filling)
#!/bin/bash
#
# Copyright © 2022 Grant Dobbe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
# and associated documentation files (the “Software”), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute,
# sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or
# substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
# BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# =================================================================================================
# This is a script for filling a disk with Wikipedia (and software to read it)
# inspired by https://github.com/angea/pocorgtfo/blob/master/contents/articles/20-02.pdf
#
# I make the assumption that you've already downloaded dumps of wikipedia and Xowa; if not, just
# uncomment and update the relevant lines below.
#
# The loop below will just continue to cat the contents of wikipedia.tar into stdin, which is then
# piped into dd (dd takes data from stdin unless the `if` option is specified.) I took a guess, and
# 1000 iterations seems sufficient to fill most hard disks; that said, adjust as necessary
# the disk we're filling
DISK=$1
# the number of times to loop through wikipedia.tar
ITERATIONS=1000
# the xowa java source (may or may not be useful, who knows)
XOWA_LINK=https://github.com/gnosygnu/xowa/archive/refs/heads/master.zip
# the index and article multi-stream tarballs (obtained from
# https://en.wikipedia.org/wiki/Wikipedia:Database_download#English-language_Wikipedia)
INDEX_LINK=https://dumps.wikimedia.org/enwiki/20211020/enwiki-20211020-pages-articles-multistream-index.txt.bz2
ARTICLES_LINK=https://dumps.wikimedia.org/enwiki/20211020/enwiki-20211020-pages-articles-multistream.xml.bz2
# echo "Grabbing a copy of xowa..."
# wget -c $XOWA_LINK
# echo "Grabbing a copy of the Wikipedia multistream index..."
# wget -c $INDEX_LINK
# echo "Grabbing a copy of the Wikipedia multistream article archive..."
# wget -c $ARTICLES_LINK
echo "This disk has been block filled with a bzip2-compressed copy of the text from English-language Wikipedia, a reference website which is an aggregate of all human knowledge as of the year 2021. It also contains a copy of Xowa, which is a program that will run on any 32- or 64-bit computer running the Java programming language. Multiple disks have been filled this way, and multiple copies have been placed on each disk, in order to help ensure that at least one copy can be assembled in its entirety. This message is first, followed by the Xowa source code, then an index of the Wikipedia articles, and then the compressed article content. This has been done in the off-chance that if human civilization experiences another Dark Age, that this knowledge will ultimately not be lost forever. Godspeed." > intro.txt
echo "Unpacking Xowa..."
unzip -q -o master.zip
echo "Creating initial tarball..."
tar cf wikipedia.tar intro.txt
echo "Adding xowa..."
tar --append --file wikipedia.tar xowa-master
echo "Expanding the index file to make this easier to parse with a hex editor..."
bzip2 -d enwiki-20211020-pages-articles-multistream-index.txt.bz2
echo "Now appending the list to the tarball..."
tar --append --file wikipedia.tar enwiki-20211020-pages-articles-multistream-index.txt
echo "Appending the multistream file to the tarball..."
tar --append --file wikipedia.tar enwiki-20211020-pages-articles-multistream.xml.bz2
echo "Writing package to disk on the block level..."
for (( i = 0; i < $ITERATIONS; i++ )); do cat wikipedia.tar; done | dd of=$DISK bs=10M status=progress
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment