Skip to content

Instantly share code, notes, and snippets.

@philipcmonk
Last active August 23, 2023 04:16
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipcmonk/8e3d095b9545069237c759cd9aad32c2 to your computer and use it in GitHub Desktop.
Save philipcmonk/8e3d095b9545069237c759cd9aad32c2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Run this by clicking "raw" in the upper right and copying that url to
# the command:
#
# curl URL >flagday.sh; chmod 755 ./flagday.sh; ./flagday.sh PIER_DIRECTORY
#
# Don't worry, your pier will be backed up. This script should end with
# a running urbit, which you can use at the command line or log into
# landscape. To interact with other ships on the testnet, shut down the
# pier and start it up again with:
#
# ./tmp-flagday/urbit PIER_DIRECTORY
#
# It is safe to run both this on the testnet and your original pier on the
# mainnet (using your regular mainnet binaries). Your original pier will
# backed up, and the directory name will be printed during the script.
#
# TODO test with spaces in filenames
# TODO test with various key arrangements
PREP_BINARY="v0.10.9-rc1"
POST_BINARY="v0.10.9-main-post"
BASE_HASH="0v1f.lbtqc.5o909.qqja6.17dgp.m8gde.bmiqc.fa97p.8jer8.msu43.5rf36"
usage() {
echo "usage: flagday.sh [-b <urbit_binary_directory>] [-k <key_file> | -G <key_string>] pier_directory"
exit
}
showhelp() {
cat <<HEREDOC
Usage: ./flagday.sh [options...] pier_directory
-b dir Directory to save the new binary (default: ./tmp-flagday)
-k file Manual key file (default: extract from pier)
-G file Manual key string (default: extract from pier)
-t Backup by creating a tarball. The tarball is smaller but
takes longer and requires enough disk space for both the
pier and the tarball.
-h Show this help text
HEREDOC
exit
}
URBIT=./tmp-flagday
if [ ! -d "${URBIT}" ]; then
mkdir "${URBIT}"
fi
MOVE="true"
while getopts "htb:k:G:" arg; do
case "${arg}" in
h)
showhelp
exit ;;
b) URBIT="${OPTARG}" ;;
k) KEYFILE="${OPTARG}" ;;
G) KEYSTRING="${OPTARG}" ;;
t) MOVE="false" ;;
*) usage ;;
esac
done
RAWPIER="${@:$OPTIND:1}"
PIER="${RAWPIER%/}"
if [ -z "${PIER}" ]; then
usage
fi
if [ -z "${URBIT}" ]; then
URBIT=./tmp-flagday
fi
if [ ! -d "${URBIT}" ]; then
mkdir "${URBIT}"
fi
if [ -n "${KEYFILE}" ]; then
KEYSTRING=$(cat "${KEYFILE}")
fi
UNAME_S=$(uname -s)
if [ $UNAME_S = "Darwin" ]; then
MACHINE="darwin"
elif [ $UNAME_S = "Linux" ]; then
MACHINE="linux64"
else
echo "Platform (${UNAME_S}) not supported"
exit
fi;
TIME=$(date +"%Y%m%d-%H%M%S")
if [ "true" = "${MOVE}" ]; then
BACKUP_FILENAME="${PIER}-backup-${TIME}"
else
BACKUP_FILENAME="${PIER}-backup-${TIME}.tar.gz"
fi
cat <<HEREDOC
This script will verify your ship is up-todate, export much of your
data, recreate your ship in the new continuity era, and re-import your
data. A backup of your pier will be saved in:
${BACKUP_FILENAME}
If this process finishes successfully, your new ship will be running in
-L mode; that is, Ames will be turned off. While in this mode, you can
enter commands, log in to the web interface, and see your data, but you
will not be able to communicate with any other ship. If something
doesn't look right, you may delete the new pier, extract your original
pier from the backup, and restart the process.
Once you're satisfied with it, shut down your pier and start it up again
without the -L flag and it'll begin to reconnect to any other ships
which have already entered the new continuity era. The new binary will
be in ${URBIT}/urbit; make sure to use it.
You can get help on Github (https://github.com/urbit/urbit), Discord
(https://discord.gg/Mae2bk7), or at support@tlon.io.
HEREDOC
read -n 1 -p "Continue? [y|n] " CONTINUE
if [ "${CONTINUE}" != "y" ] && [ "${CONTINUE}" != "Y" ]; then
exit
fi
echo
# Kill old pier
if [ -f "${PIER}/.vere.lock" ]; then
echo "FLAGDAY: pier running, shutting it down"
kill -9 $(cat "${PIER}/.vere.lock") || true
fi
# Backup old pier
if [ "true" != $MOVE ]; then
echo "FLAGDAY: backing up pier to ${BACKUP_FILENAME}"
tar czf "${BACKUP_FILENAME}" "${PIER}" || exit
fi
# Fetch an up-to-date pre-breach binary
# Timestamp is for busting the cache
echo "FLAGDAY: updating pre-breach binary to ${PREP_BINARY}"
PREP_URL="https://bootstrap.urbit.org/urbit-${PREP_BINARY}-${MACHINE}.tgz?$(date +\"%s\")"
wget -qO- $PREP_URL | tar xvz -C "$URBIT" --strip=1
# Get ship name
eval "${URBIT}/urbit" -X /gx/hood/kiln/our/noun -Y /our -Z p "${PIER}"
if [ -z "${SHIP}" ]; then
SHIP=$(cat "${PIER}/.urb/put/our.txt")
fi
echo "FLAGDAY: Identifying ship... ${SHIP}"
# Check base hash
eval "${URBIT}/urbit" -X /gx/hood/kiln/base-hash/noun -Y /base-hash -Z uv "${PIER}"
GOT_HASH=$(cat "${PIER}/.urb/put/base-hash.txt")
if [ "${BASE_HASH}" != "${GOT_HASH}" ]; then
echo "FLAGDAY: WARNING, your base hash is: ${GOT_HASH}"
echo "FLAGDAY: Expected: ${BASE_HASH}"
echo "FLAGDAY: You need to receive the most recent OTA before migrating"
echo "FLAGDAY: It is possible to override this warning"
read -n 1 -p "FLAGDAY: Continue anyway? [y|n] " CONTINUE
if [ "${CONTINUE}" != "y" ] && [ "${CONTINUE}" != "Y" ]; then
exit
fi
echo
fi
# Run export on existing urbit
if [ -z "${KEYFILE}" ] && [ -z "${KEYSTRING}" ]; then
echo "FLAGDAY: extracting key from pier"
eval "${URBIT}/urbit" -X /j/vile -Y /keyfile -Z uw "${PIER}"
KEYSTRING=$(cat "${PIER}/.urb/put/keyfile.txt")
fi
echo "FLAGDAY: exporting data from pier"
eval "${URBIT}/urbit" -X /gx/lens/export-all/noun -Y /archive "${PIER}"
mv "${PIER}/.urb/put/archive.jam" "${URBIT}/archive.jam"
# Download latest binary
echo
echo "FLAGDAY: updating to post-breach binary, ${POST_BINARY}"
POST_URL="https://bootstrap.urbit.org/urbit-${POST_BINARY}-${MACHINE}.tgz?$(date +\"%s\")"
wget -qO- $POST_URL | tar xvz -C "$URBIT" --strip=1
if [ "true" = $MOVE ]; then
echo "FLAGDAY: backing up pier to ${BACKUP_FILENAME}"
mv "${PIER}" "${BACKUP_FILENAME}" || exit
else
echo "FLAGDAY: removing old pier"
rm -r "${PIER}"
fi
echo "FLAGDAY: key: ${KEYSTRING}"
# Boot ship and run import
echo "FLAGDAY: booting ${SHIP} in the new era and importing data"
# eval "${URBIT}/urbit" -L -w $SHIP -G $KEYSTRING -i "${URBIT}/archive.jam" -H test.urbit.org -e http://35.247.55.112:8545 -c "${PIER}"
eval "${URBIT}/urbit" -L -w $SHIP -G $KEYSTRING -i "${URBIT}/archive.jam" -H test.urbit.org -c "${PIER}"
@afknapping
Copy link

awesome urbit badge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment