2023-07-06 14:01:34 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
2023-09-07 21:46:19 +00:00
|
|
|
#! nix-shell -i bash -p bundix coreutils diffutils nix-prefetch-github gnused jq prefetch-yarn-deps
|
2019-05-02 14:50:28 +00:00
|
|
|
set -e
|
|
|
|
|
2023-06-20 21:36:06 +00:00
|
|
|
OWNER=mastodon
|
|
|
|
REPO=mastodon
|
2019-05-02 14:50:28 +00:00
|
|
|
|
|
|
|
POSITIONAL=()
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
key="$1"
|
|
|
|
|
|
|
|
case $key in
|
2023-06-20 21:36:06 +00:00
|
|
|
--owner)
|
|
|
|
OWNER="$2"
|
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
--repo)
|
|
|
|
REPO="$2"
|
2022-04-09 00:05:44 +00:00
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
2019-05-02 14:50:28 +00:00
|
|
|
--ver)
|
2022-04-09 00:05:44 +00:00
|
|
|
VERSION="$2"
|
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
--rev)
|
|
|
|
REVISION="$2"
|
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
--patches)
|
|
|
|
PATCHES="$2"
|
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
*) # unknown option
|
|
|
|
POSITIONAL+=("$1")
|
|
|
|
shift # past argument
|
|
|
|
;;
|
2019-05-02 14:50:28 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2023-07-06 14:01:34 +00:00
|
|
|
if [[ -n "$POSITIONAL" ]]; then
|
|
|
|
echo "Usage: update.sh [--owner OWNER] [--repo REPO] [--ver VERSION] [--rev REVISION] [--patches PATCHES]"
|
|
|
|
echo "OWNER and REPO must be paths on github."
|
|
|
|
echo "If REVISION is not provided, the latest tag from github.com/mastodon/mastodon is fetched and VERSION is calculated from it."
|
2023-06-20 21:36:06 +00:00
|
|
|
echo "If OWNER and REPO are not provided, it defaults they default to mastodon and mastodon."
|
|
|
|
echo "PATCHES, if provided, should be one or more Nix expressions separated by spaces."
|
2019-05-02 14:50:28 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$REVISION" ]]; then
|
2023-07-06 14:01:34 +00:00
|
|
|
REVISION="$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} -s "https://api.github.com/repos/$OWNER/$REPO/releases" | jq -r 'map(select(.prerelease == false)) | .[0].tag_name')"
|
|
|
|
VERSION="$(echo "$REVISION" | cut -c2-)"
|
2019-05-02 14:50:28 +00:00
|
|
|
fi
|
|
|
|
|
2023-09-27 22:42:07 +00:00
|
|
|
rm -f gemset.nix source.nix
|
2023-07-06 14:01:34 +00:00
|
|
|
cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1
|
2019-05-02 14:50:28 +00:00
|
|
|
|
|
|
|
WORK_DIR=$(mktemp -d)
|
|
|
|
|
|
|
|
# Check that working directory was created.
|
2023-06-20 21:36:06 +00:00
|
|
|
if [[ -z "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
|
2019-05-02 14:50:28 +00:00
|
|
|
echo "Could not create temporary directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Delete the working directory on exit.
|
|
|
|
function cleanup {
|
|
|
|
# Report errors, if any, from nix-prefetch-git
|
|
|
|
grep "fatal" $WORK_DIR/nix-prefetch-git.out >/dev/stderr || true
|
|
|
|
rm -rf "$WORK_DIR"
|
|
|
|
}
|
|
|
|
trap cleanup EXIT
|
|
|
|
|
2023-06-20 21:36:06 +00:00
|
|
|
echo "Fetching source code $REVISION"
|
2023-07-21 23:46:47 +00:00
|
|
|
JSON=$(nix-prefetch-github "$OWNER" "$REPO" --rev "$REVISION" 2> $WORK_DIR/nix-prefetch-git.out)
|
2023-09-27 22:42:07 +00:00
|
|
|
HASH=$(echo "$JSON" | jq -r .hash)
|
2019-05-02 14:50:28 +00:00
|
|
|
|
|
|
|
cat > source.nix << EOF
|
|
|
|
# This file was generated by pkgs.mastodon.updateScript.
|
2023-09-27 22:42:07 +00:00
|
|
|
{ fetchFromGitHub, applyPatches }:
|
2023-09-28 20:29:04 +00:00
|
|
|
let
|
2023-09-27 22:42:07 +00:00
|
|
|
version = "$VERSION";
|
2023-09-28 20:29:04 +00:00
|
|
|
in
|
|
|
|
applyPatches {
|
|
|
|
inherit version;
|
2023-06-20 21:36:06 +00:00
|
|
|
src = fetchFromGitHub {
|
2023-07-06 14:01:34 +00:00
|
|
|
owner = "$OWNER";
|
|
|
|
repo = "$REPO";
|
2023-09-28 20:29:04 +00:00
|
|
|
rev = "\${version}";
|
2023-07-08 06:02:48 +00:00
|
|
|
hash = "$HASH";
|
2019-05-02 14:50:28 +00:00
|
|
|
};
|
|
|
|
patches = [$PATCHES];
|
2023-09-27 22:42:07 +00:00
|
|
|
yarnHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
|
2019-05-02 14:50:28 +00:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
SOURCE_DIR="$(nix-build --no-out-link -E '(import <nixpkgs> {}).callPackage ./source.nix {}')"
|
|
|
|
|
|
|
|
echo "Creating gemset.nix"
|
|
|
|
bundix --lockfile="$SOURCE_DIR/Gemfile.lock" --gemfile="$SOURCE_DIR/Gemfile"
|
2023-07-06 14:01:34 +00:00
|
|
|
echo "" >> gemset.nix # Create trailing newline to please EditorConfig checks
|
2023-09-07 21:46:19 +00:00
|
|
|
|
|
|
|
echo "Creating yarn-hash.nix"
|
|
|
|
YARN_HASH="$(prefetch-yarn-deps "$SOURCE_DIR/yarn.lock")"
|
|
|
|
YARN_HASH="$(nix hash to-sri --type sha256 "$YARN_HASH")"
|
2023-09-27 22:42:07 +00:00
|
|
|
sed -i "s/sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/$YARN_HASH/g" source.nix
|