Unverified Commit 635be603 authored by Arne Keller's avatar Arne Keller Committed by GitHub
Browse files

element-{desktop,web-unwrapped}: {fix,modernize} update script (#407741)

parents 312fbc61 31d520ee
Loading
Loading
Loading
Loading
+28 −33
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix wget prefetch-yarn-deps nix-prefetch-github jq
#!nix-shell -i bash -p nix coreutils prefetch-yarn-deps jq curl

if [ "$#" -gt 1 ] || [[ "$1" == -* ]]; then
  echo "Regenerates packaging data for the element packages."
@@ -12,54 +12,49 @@ version="$1"
set -euo pipefail

if [ -z "$version" ]; then
  version="$(wget -q -O- "https://api.github.com/repos/element-hq/element-desktop/releases?per_page=1" | jq -r '.[0].tag_name')"
  version="$(curl -fsSL "https://api.github.com/repos/element-hq/element-desktop/releases/latest" | jq -r '.tag_name')"
fi

# strip leading "v"
version="${version#v}"

# Element Web
web_src="https://raw.githubusercontent.com/element-hq/element-web/v$version"
web_src_hash=$(nix-prefetch-github element-hq element-web --rev v${version} | jq -r .hash)

cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1

web_tmpdir=$(mktemp -d)
trap 'rm -rf "$web_tmpdir"' EXIT
nixflags=(
  --extra-experimental-features
  "nix-command flakes"
)

pushd $web_tmpdir
wget -q "$web_src/yarn.lock"
web_yarn_hash=$(prefetch-yarn-deps yarn.lock)
popd
# HACK: prefetch-yarn-deps hashes may output extra clutter on stdout (!) so
# we'll need to get the last line, last word
fixupHash() {
  local sorta_yarn_hash="$(tail -n1 <<< "$1")"
  local almost_yarn_hash="${sorta_yarn_hash##* }"
  local yarn_hash="$(nix "${nixflags[@]}" hash convert --hash-algo sha256 "$almost_yarn_hash")"

# Element Desktop
desktop_src="https://raw.githubusercontent.com/element-hq/element-desktop/v$version"
desktop_src_hash=$(nix-prefetch-github element-hq element-desktop --rev v${version} | jq -r .hash)
  printf "%s" "$yarn_hash"
}

desktop_tmpdir=$(mktemp -d)
trap 'rm -rf "$desktop_tmpdir"' EXIT
getHashes() {
  variant="$1"
  output="$2"

pushd $desktop_tmpdir
wget -q "$desktop_src/yarn.lock"
desktop_yarn_hash=$(prefetch-yarn-deps yarn.lock)
popd
  local url="github:element-hq/element-$variant/v$version"
  local src="$(nix "${nixflags[@]}" flake prefetch --json "$url")"
  local src_hash="$(jq -r ".hash" <<< "$src")"
  local src_path="$(jq -r ".storePath" <<< "$src")"
  local yarn_hash="$(fixupHash "$(prefetch-yarn-deps "$src_path/yarn.lock")")"

cat > ../element-web-unwrapped/element-web-pin.nix << EOF
  cat > "$output" << EOF
{
  "version" = "$version";
  "hashes" = {
    "webSrcHash" = "$web_src_hash";
    "webYarnHash" = "$web_yarn_hash";
    "${variant}SrcHash" = "$src_hash";
    "${variant}YarnHash" = "$yarn_hash";
  };
}
EOF

cat > element-desktop-pin.nix << EOF
{
  "version" = "$version";
  "hashes" = {
    "desktopSrcHash" = "$desktop_src_hash";
    "desktopYarnHash" = "$desktop_yarn_hash";
  };
}
EOF

getHashes web ../element-web-unwrapped/element-web-pin.nix
getHashes desktop element-desktop-pin.nix