www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules

github_update_homepage.sh (1508B)


      1 #!/usr/bin/env bash
      2 
      3 set -euET -o pipefail
      4 
      5 echo "Hashing repository contents with IPFS..."
      6 
      7 h="$(ipfs cid base32 "$(ipfs add --recursive --progress --hidden --ignore-rules-path=.ipfsignore --quieter .)")"
      8 
      9 echo "After pinning, the new homepage URL will be: https://$h.ipfs.dweb.link/"
     10 
     11 # Wait for IPFS daemon to be ready
     12 echo 'Starting IPFS daemon...'
     13 tail -F /tmp/ipfs-daemon.logs -n +1 & pid=$!
     14 ipfs daemon >/tmp/ipfs-daemon.logs 2>&1 &
     15 while ! grep 'Daemon is ready' /tmp/ipfs-daemon.logs; do sleep 1; date; done
     16 echo 'IPFS daemon started, killing log tail...'
     17 kill "$pid"
     18 echo 'log tail killed'
     19 
     20 # Pin this hash
     21 echo "Adding remote pinning service..."
     22 (
     23   ipfs pin remote service add my-remote-pin "$IPFS_REMOTE_API_ENDPOINT" "$IPFS_REMOTE_TOKEN"
     24 ) > /dev/null 2>&1
     25 
     26 echo "Connecting to some IPFS node..."
     27 (
     28   ipfs swarm connect "$IPFS_SWARM_CONNECT_TO"
     29 ) > /dev/null 2>&1
     30 
     31 echo "Pinning $h on the remote service..."
     32 (
     33   ipfs pin remote add --service=my-remote-pin --name="site-suzanne.soy-$(TZ=UTC git log -1 --format=%cd --date=iso-strict-local HEAD)-$GITHUB_SHA" "$h"
     34 ) > /dev/null 2>&1
     35 echo "Finished pinning $h on the remote service"
     36 
     37 # Update Homepage URL on GitHub
     38 curl -L \
     39   -X PATCH \
     40   -H "Accept: application/vnd.github+json" \
     41   -H "Authorization: Bearer $API_TOKEN_FOR_UPDATE_HOMEPAGE"\
     42   -H "X-GitHub-Api-Version: 2022-11-28" \
     43   https://api.github.com/repos/SuzanneSoy/SuzanneSoy.github.io \
     44   -d '{"name":"SuzanneSoy.github.io", "homepage":"https://dweb.link/ipfs/'"$h"'"}' > /dev/null