1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash -p curl wget jq yq common-updater-scripts prefetch-yarn-deps yarn-lock-converter
6 TMPDIR
=/tmp
/pgadmin-update-script
8 ################################################################
9 # This script will update pgadmin4 in nixpkgs #
10 # Due to recent changes upstream, we will need to convert the #
11 # `yarn.lock` file back to version 1. #
12 # This isn't trivially done and relies on 3rd party tools #
13 # and a hand-written converter (in this script). #
14 # Also, the converter cannot check for `github` repos in the #
15 # `yarn.lock` file, which this script will add automatically #
16 ################################################################
19 if [ -e $TMPDIR/.
done ]
24 read -p "Script exited prematurely. Do you want to delete the temporary directory $TMPDIR ? " -n 1 -r
26 if [[ $REPLY =~ ^
[Yy
]$
]]
35 scriptDir
=$
(cd "${BASH_SOURCE[0]%/*}" && pwd)
36 nixpkgs
=$
(realpath
"$scriptDir"/..
/..
/..
/..
)
38 newest_version
="$(curl -s https://www.pgadmin.org/versions.json | jq -r .pgadmin4.version)"
39 old_version
=$
(nix-instantiate
--eval -E "(import \"$nixpkgs\" { config = {}; overlays = []; }).pgadmin4.version" |
tr -d '"')
40 url
="https://ftp.postgresql.org/pub/pgadmin/pgadmin4/v${newest_version}/source/pgadmin4-${newest_version}.tar.gz"
42 if [[ $newest_version == $old_version ]]; then
43 printf "Already at latest version $newest_version\n"
46 printf "New version: $newest_version \n"
48 # don't use mktemp, so if a network error happens, we can resume from there
52 tar -xzf "pgadmin4-$newest_version.tar.gz"
53 cd "pgadmin4-$newest_version/web"
55 printf "Will now convert the v2 lockfile. This will download the npm packages to get the metadata.\n"
56 printf "Please note: This will take some time! For details, see the logfile ${TMPDIR}/update.log\n"
57 yarn-lock-converter
-i yarn.lock
-o yarn_v1.lock
--cache .cache
> $TMPDIR/update.log
58 printf "Conversion done\n"
60 printf "Will now do some regex substitution post-processing\n"
61 sed -i -E "s|(.), |\1\", \"|g" yarn_v1.lock
62 sed -i -E "s|npm:||g" yarn_v1.lock
63 printf "Substituion done\n"
65 printf "Will now add missing github packages back to the v1 yarn.lock file\n"
67 tail +8 yarn.lock
> yarn_mod.lock
68 LENGTH
=$
(yq
'. | with_entries(select(.value.resolution | contains("github"))) | keys | length' yarn_mod.lock
)
69 for i
in $
(seq 0 $
(($LENGTH-1)));
71 ENTRY
=$
(yq
". | with_entries(select(.value.resolution | contains(\"github\"))) | keys | .[$i]" yarn_mod.lock
)
72 URL
=$
(echo $ENTRY | cut
-d "@" -f 2)
73 VERSION
=$
(yq
".$ENTRY.version" yarn_mod.lock
)
74 LENGTH_DEP
=$
(yq
".$ENTRY.dependencies | keys | length" yarn_mod.lock
)
75 echo "$ENTRY:" >> adendum.lock
76 echo " version $VERSION" >> adendum.lock
77 echo " resolved \"$URL" >> adendum.lock
78 echo " dependencies:" >> adendum.lock
80 for j
in $
(seq 0 $
(($LENGTH_DEP-1)));
82 DEPENDENCY_KEY
=$
(yq
".$ENTRY.dependencies | keys | .[$j]" yarn_mod.lock
)
83 DEPENDENCY_VALUE
=$
(yq
".$ENTRY.dependencies.$DEPENDENCY_KEY" yarn_mod.lock
)
85 DEPENDENCY_KEY
=${DEPENDENCY_KEY//\"}
86 echo " \"$DEPENDENCY_KEY\" $DEPENDENCY_VALUE" >> adendum.lock
90 echo "" >> yarn_v1.lock
91 cat adendum.lock
>> yarn_v1.lock
95 mv yarn_v1.lock yarn.lock
97 printf "Will now generate the hash. This will download the packages to the nix store and also take some time\n"
98 YARN_HASH
=$
(prefetch-yarn-deps yarn.lock
)
99 YARN_HASH
=$
(nix
hash to-sri
--type sha256
"$YARN_HASH")
102 printf "Copy files to nixpkgs\n"
103 cp yarn.lock
"$nixpkgs/pkgs/tools/admin/pgadmin/"
107 sed -i -E -e "s#yarnHash = \".*\"#yarnHash = \"$YARN_HASH\"#" ${scriptDir}/default.nix
109 update-source-version pgadmin4
"$newest_version" --print-changes