about summary refs log tree commit diff
path: root/pkgs/servers/mastodon/update.sh
diff options
context:
space:
mode:
authorSandro Jäckel <sandro.jaeckel@gmail.com>2023-06-20 23:36:06 +0200
committerSandro Jäckel <sandro.jaeckel@gmail.com>2023-06-20 23:36:06 +0200
commit0000005ec61c166d27aedc3195b189886a0118c3 (patch)
tree722a5ce2633104083474dc721359879206385f3e /pkgs/servers/mastodon/update.sh
parente9e3f2e7362aba3ef709173d1777f0b893fc0ebf (diff)
downloadnixlib-0000005ec61c166d27aedc3195b189886a0118c3.tar
nixlib-0000005ec61c166d27aedc3195b189886a0118c3.tar.gz
nixlib-0000005ec61c166d27aedc3195b189886a0118c3.tar.bz2
nixlib-0000005ec61c166d27aedc3195b189886a0118c3.tar.lz
nixlib-0000005ec61c166d27aedc3195b189886a0118c3.tar.xz
nixlib-0000005ec61c166d27aedc3195b189886a0118c3.tar.zst
nixlib-0000005ec61c166d27aedc3195b189886a0118c3.zip
mastodon: use fetchFromGitHub, fix shellcheck hints
Diffstat (limited to 'pkgs/servers/mastodon/update.sh')
-rwxr-xr-xpkgs/servers/mastodon/update.sh44
1 files changed, 24 insertions, 20 deletions
diff --git a/pkgs/servers/mastodon/update.sh b/pkgs/servers/mastodon/update.sh
index 3a0686a72158..7b4d97fd1397 100755
--- a/pkgs/servers/mastodon/update.sh
+++ b/pkgs/servers/mastodon/update.sh
@@ -1,15 +1,21 @@
 #!/usr/bin/env bash
 set -e
 
-URL=https://github.com/mastodon/mastodon.git
+OWNER=mastodon
+REPO=mastodon
 
 POSITIONAL=()
 while [[ $# -gt 0 ]]; do
     key="$1"
 
     case $key in
-        --url)
-            URL="$2"
+        --owner)
+            OWNER="$2"
+            shift # past argument
+            shift # past value
+            ;;
+        --repo)
+            REPO="$2"
             shift # past argument
             shift # past value
             ;;
@@ -36,13 +42,11 @@ while [[ $# -gt 0 ]]; do
 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"
-    echo "provided, it defaults to https://github.com/mastodon/mastodon.git."
-    echo "PATCHES, if provided, should be one or more Nix expressions"
-    echo "separated by spaces."
+    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 VERSION is not a revision acceptable to 'git checkout', you must provide one in REVISION."
+    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."
     exit 1
 fi
 
@@ -57,7 +61,7 @@ TARGET_DIR="$PWD"
 WORK_DIR=$(mktemp -d)
 
 # Check that working directory was created.
-if [[ ! "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
+if [[ -z "$WORK_DIR" || ! -d "$WORK_DIR" ]]; then
     echo "Could not create temporary directory"
     exit 1
 fi
@@ -70,19 +74,19 @@ function cleanup {
 }
 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 "Fetching source code $REVISION"
+JSON=$(nix-prefetch-github "$OWNER" "$REPO" --rev "$REVISION"  2> $WORK_DIR/nix-prefetch-git.out)
+SHA=$(echo "$JSON" | jq -r .sha256)
 
 echo "Creating version.nix"
-echo \"$VERSION\" | sed 's/^"v/"/' > 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";
+{ fetchFromGitHub, applyPatches }: let
+  src = fetchFromGitHub {
+    owner = "mastodon";
+    repo = "mastodon";
     rev = "$REVISION";
     sha256 = "$SHA";
   };
@@ -95,4 +99,4 @@ SOURCE_DIR="$(nix-build --no-out-link -E '(import <nixpkgs> {}).callPackage ./so
 
 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
+echo "" >> "$TARGET_DIR/gemset.nix"  # Create trailing newline to please EditorConfig checks