2019-05-02 15:50:28 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2022-03-30 15:13:03 +01:00
|
|
|
URL=https://github.com/mastodon/mastodon.git
|
2019-05-02 15:50:28 +01:00
|
|
|
|
|
|
|
POSITIONAL=()
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
key="$1"
|
|
|
|
|
|
|
|
case $key in
|
|
|
|
--url)
|
|
|
|
URL="$2"
|
|
|
|
shift # past argument
|
|
|
|
shift # past value
|
|
|
|
;;
|
|
|
|
--ver)
|
|
|
|
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
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z "$VERSION" || -n "$POSITIONAL" ]]; then
|
|
|
|
echo "Usage: update.sh [--url URL] --ver VERSION [--rev REVISION] [--patches PATCHES]"
|
|
|
|
echo "URL may be any path acceptable to 'git clone' and VERSION the"
|
|
|
|
echo "semantic version number. If VERSION is not a revision acceptable to"
|
|
|
|
echo "'git checkout', you must provide one in REVISION. If URL is not"
|
2022-03-30 15:13:03 +01:00
|
|
|
echo "provided, it defaults to https://github.com/mastodon/mastodon.git."
|
2019-05-02 15:50:28 +01:00
|
|
|
echo "PATCHES, if provided, should be one or more Nix expressions"
|
|
|
|
echo "separated by spaces."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z "$REVISION" ]]; then
|
|
|
|
REVISION="$VERSION"
|
|
|
|
fi
|
|
|
|
|
2022-03-20 19:18:19 +00:00
|
|
|
rm -f gemset.nix version.nix source.nix
|
2019-05-02 15:50:28 +01:00
|
|
|
TARGET_DIR="$PWD"
|
|
|
|
|
|
|
|
|
|
|
|
WORK_DIR=$(mktemp -d)
|
|
|
|
|
|
|
|
# Check that working directory was created.
|
|
|
|
if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
|
|
|
|
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
|
|
|
|
|
|
|
|
echo "Fetching source code $REVISION from $URL"
|
|
|
|
JSON=$(nix-prefetch-git --url "$URL" --rev "$REVISION" 2> $WORK_DIR/nix-prefetch-git.out)
|
|
|
|
SHA=$(echo $JSON | jq -r .sha256)
|
|
|
|
FETCHED_SOURCE_DIR=$(grep '^path is' $WORK_DIR/nix-prefetch-git.out | sed 's/^path is //')
|
|
|
|
|
|
|
|
echo "Creating version.nix"
|
|
|
|
echo \"$VERSION\" | sed 's/^"v/"/' > version.nix
|
|
|
|
|
|
|
|
cat > source.nix << EOF
|
|
|
|
# This file was generated by pkgs.mastodon.updateScript.
|
|
|
|
{ fetchgit, applyPatches }: let
|
|
|
|
src = fetchgit {
|
|
|
|
url = "$URL";
|
|
|
|
rev = "$REVISION";
|
|
|
|
sha256 = "$SHA";
|
|
|
|
};
|
|
|
|
in applyPatches {
|
|
|
|
inherit src;
|
|
|
|
patches = [$PATCHES];
|
|
|
|
}
|
|
|
|
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"
|
|
|
|
echo "" >> $TARGET_DIR/gemset.nix # Create trailing newline to please EditorConfig checks
|