Skip to content

Instantly share code, notes, and snippets.

@stackdump
Created March 8, 2022 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stackdump/297cba4aa30fc41ae0ffd67ce2cb4d44 to your computer and use it in GitHub Desktop.
Save stackdump/297cba4aa30fc41ae0ffd67ce2cb4d44 to your computer and use it in GitHub Desktop.
snapshot Minetest world with IPFS
#!/usr/bin/env bash
# backup world in IPFS
cd "${BASH_SOURCE%/*}" || exit
ROOT='vevr.se'
WORLD="foo7"
TS=$(date +%s)
ARCHIVE="${WORLD}.${TS}.tgz"
NSKEY=k51qzi5uqu5dhe82f7mh0jc7exsq938ughiappzzdrlfh5y3mh28n593qwg71p
OLDPATH=$(ipfs resolve /ipns/${NSKEY})
tar -czf ${ARCHIVE} ${WORLD}
CID=$(ipfs add ${ARCHIVE} -q)
# echo "${WORLD} snapshot: /ipfs/${CID}"
ipfs files write --create --truncate "/${ROOT}/worlds/foo7.tgz" ${ARCHIVE}
# Change entry in Mutable file system
MFSROOT=$(ipfs files stat "/${ROOT}" --hash)
# update our IPNS key to point to latest Filesytem
ipfs name publish ${MFSROOT}
# check resolution
NEWPTH=$(ipfs resolve /ipns/${NSKEY})
echo "Updated ${OLDPATH} => ${NEWPTH}"
@stackdump
Copy link
Author

This changes the published IPFS directory

Published to k51qzi5uqu5dhe82f7mh0jc7exsq938ughiappzzdrlfh5y3mh28n593qwg71p: /ipfs/QmRNLcC7eMMpoBMwwvWqhcDgkfaEEdsKJKJvfhvmaDQ6NB
Updated /ipfs/QmP3ZGoWGBQLzPgXENMaqxwSToK4XLdh4G2h9XGDZk1ER6 => /ipfs/QmRNLcC7eMMpoBMwwvWqhcDgkfaEEdsKJKJvfhvmaDQ6NB

DNS is set to point to the primay key (starts with k51qz...)

host -t TXT _dnslink.example.com
_dnslink.example.com descriptive text "dnslink=/ipns/k51qzi5uqu5dhe82f7mh0jc7exsq938ughiappzzdrlfh5y3mh28n593qwg71p"

Part of the nginx config exposes the IPFS proxy using the subdomain to pass the IPNS name we want to use

        location /worlds/ {
            proxy_pass http://example.com.localhost:8080;
        }

When file is accessed via web - we get some goodies in the headers

ork@zim:~$ curl --head https://example.com/worlds/foo7.tgz
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Tue, 08 Mar 2022 16:15:01 GMT
Content-Type: application/x-compressed-tar
Content-Length: 77395006
Connection: keep-alive
Accept-Ranges: bytes
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Headers: Range
Access-Control-Allow-Headers: User-Agent
Access-Control-Allow-Headers: X-Requested-With
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Content-Range
Access-Control-Expose-Headers: X-Chunked-Output
Access-Control-Expose-Headers: X-Stream-Output
Etag: "QmYw1PpiPGAqZ3PSHaEZSWxvrxH9owdY1spyCpkV6ThciN"
Last-Modified: Tue, 08 Mar 2022 16:15:01 GMT
X-Ipfs-Path: /ipns/example.com/worlds/foo7.tgz

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