ebf972e671fcb4cb620d7dd98f4264675fd3f2c7
[workstation-ostree-config.git] / github-fetch.sh
1 #!/bin/sh
2 # Download built GitHub OSTree repository artifact and unpack it into a plain directory
3 set -eux
4
5 # download latest repo build
6 REPO_FINAL="$(dirname $0)/pitti-workstation"
7 REPO="${REPO_FINAL}.new"
8
9 CURL="curl -u token:$(cat ~/.config/github-token) --show-error --fail"
10 RESPONSE=$($CURL --silent https://api.github.com/repos/martinpitt/ostree-pitti-workstation/actions/artifacts)
11 ZIP=$(echo "$RESPONSE" | jq --raw-output '.artifacts | map(select(.name == "repository"))[0].archive_download_url')
12 echo "INFO: Downloading $ZIP ..."
13 [ -e /tmp/repository.zip ] || $CURL -L -o /tmp/repository.zip "$ZIP"
14 rm -rf "$REPO"
15 mkdir -p "$REPO"
16 unzip -p /tmp/repository.zip | tar -xzC "$REPO"
17 rm /tmp/repository.zip
18 [ ! -e "$REPO_FINAL" ] || mv "${REPO_FINAL}" "${REPO_FINAL}.old"
19 mv "$REPO" "$REPO_FINAL"
20 rm -rf "${REPO_FINAL}.old"