1#!/usr/bin/env nix-shell
2#!nix-shell -i bash -p curl wget jq common-updater-scripts yarn-berry_4 yarn-berry_4.yarn-berry-fetcher
3
4set -eu -o pipefail
5
6TMPDIR=/tmp/pgadmin-update-script
7
8cleanup() {
9 if [ -e $TMPDIR/.done ]
10 then
11 rm -rf "$TMPDIR"
12 else
13 echo
14 read -p "Script exited prematurely. Do you want to delete the temporary directory $TMPDIR ? " -n 1 -r
15 echo
16 if [[ $REPLY =~ ^[Yy]$ ]]
17 then
18 rm -rf "$TMPDIR"
19 fi
20 fi
21}
22
23trap cleanup EXIT
24
25scriptDir=$(cd "${BASH_SOURCE[0]%/*}" && pwd)
26nixpkgs=$(realpath "$scriptDir"/../../../..)
27
28newest_version="$(curl -s https://www.pgadmin.org/versions.json | jq -r .pgadmin4.version)"
29old_version=$(nix-instantiate --eval -E "(import \"$nixpkgs\" { config = {}; overlays = []; }).pgadmin4.version" | tr -d '"')
30url="https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v${newest_version}/source/pgadmin4-${newest_version}.tar.gz"
31
32if [[ $newest_version == $old_version ]]; then
33 printf "Already at latest version $newest_version\n"
34 exit 0
35fi
36printf "New version: $newest_version \n"
37
38# don't use mktemp, so if a network error happens, we can resume from there
39mkdir -p $TMPDIR
40pushd $TMPDIR
41wget -c $url
42tar -xzf "pgadmin4-$newest_version.tar.gz"
43cd "pgadmin4-$newest_version/web"
44patch -u yarn.lock ${scriptDir}/mozjpeg.patch
45
46printf "Will now generate the hash. This will download the packages to the nix store and also take some time\n"
47yarn-berry-fetcher missing-hashes yarn.lock
48if [[ -f missing-hashes.json ]]; then
49 YARN_HASH=$(yarn-berry-fetcher prefetch yarn.lock missing-hashes.json)
50else
51 YARN_HASH=$(yarn-berry-fetcher prefetch yarn.lock)
52fi
53printf "Done\n"
54
55if [[ -f missing-hashes.json ]]; then
56 if [[ ! -f "$nixpkgs/pkgs/tools/admin/pgadmin/missing-hashes.json" ]]; then
57 printf "PLEASE NOTE: FIRST TIME OF FINDING MISSING HASHES!"
58 printf "Please add \"missingHashes = ./missing-hashes.json\" to pgadmin derivation"
59 fi
60 printf "Copy files to nixpkgs\n"
61 cp missing-hashes.json "$nixpkgs/pkgs/tools/admin/pgadmin/"
62fi
63
64printf "Done\n"
65popd
66
67sed -i -E -e "s#yarnHash = \".*\"#yarnHash = \"$YARN_HASH\"#" ${scriptDir}/default.nix
68
69update-source-version pgadmin4 "$newest_version" --print-changes
70touch $TMPDIR/.done