Skip to content

Commit fbca8aa

Browse files
committed
[LW-10649] Add progress, update from the portable variant, incl. restarting cardano-launcher
1 parent 4b5094d commit fbca8aa

File tree

2 files changed

+67
-23
lines changed

2 files changed

+67
-23
lines changed

nix/internal/linux-self-extracting-archive.sh

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,25 @@ set -eu
77

88
skip_bytes=$(( 1010101010 - 1000000000 ))
99

10-
echo "Verifying SHA-256 checksum..."
11-
our_checksum=$(tail -c+$((skip_bytes+1)) "$0" | sha256sum | cut -d' ' -f1)
12-
if [ "$our_checksum" != 0000000000000000000000000000000000000000000000000000000000000000 ] ; then
13-
echo "Checksum verification failure. Please, download the installer again."
14-
exit 1
15-
fi
16-
1710
# We could be running as an auto-update from Daedalus ≤5.4.0 using `nix-chroot`,
1811
# then our behavior should be different:
1912
in_chroot=
13+
num_steps=5
2014
if [ "${1-}" = "--extract" ] && [ -e /nix/var/nix/profiles/profile-@CLUSTER@ ] ; then
2115
in_chroot=1
16+
num_steps=6 # let’s have 6, so that we never reach 100% in UI, and the old update-runner also uses 6
2217
fi
2318

19+
echo STATUS "Verifying SHA-256 checksum..."
20+
echo PROG 1/$num_steps
21+
our_checksum=$(tail -c+$((skip_bytes+1)) "$0" | sha256sum | cut -d' ' -f1)
22+
if [ "$our_checksum" != 0000000000000000000000000000000000000000000000000000000000000000 ] ; then
23+
echo "Checksum verification failure. Please, download the installer again."
24+
exit 1
25+
fi
26+
27+
echo STATUS "Cleaning up the older version..."
28+
echo PROG 2/$num_steps
2429
target="$HOME"/.daedalus/@CLUSTER@
2530
if [ -e "$target" ] ; then
2631
echo "Found an older version of Daedalus "@CLUSTER@", removing it..."
@@ -41,7 +46,8 @@ else
4146
echo "Note: you don't have \`pv' installed, so we can't show progress"
4247
fi
4348

44-
echo "Unpacking..."
49+
echo STATUS "Unpacking..."
50+
echo PROG 3/$num_steps
4551
tail -c+$((skip_bytes+1)) "$0" | $progress_cmd | tar -C "$target" -xJ
4652

4753
# Move a faux `satisfyOldUpdateRunner` to $PWD so that the old `update-runner` doesn’t error out:
@@ -54,7 +60,8 @@ else
5460
fi
5561
chmod -w "$target"
5662

57-
echo "Setting up a .desktop entry..."
63+
echo STATUS "Setting up a .desktop entry..."
64+
echo PROG 4/$num_steps
5865
mkdir -p "$HOME"/.local/share/applications
5966
chmod -R +w "$target"/share/applications
6067
sed -r "s+INSERT_PATH_HERE+$(echo "$target"/bin/*)+g" -i "$target"/share/applications/*.desktop
@@ -68,7 +75,18 @@ DAEDALUS_DIR="${XDG_DATA_HOME}/Daedalus"
6875
mkdir -p "$DAEDALUS_DIR"/@CLUSTER@/
6976
ln -sf "$target"/bin/daedalus "$DAEDALUS_DIR"/@CLUSTER@/namespaceHelper
7077

78+
# If this is an auto-update, let's move the old lockfile out of the way, as we’ll restart cardano-launcher,
79+
# while the previous one is still running for a second (either in `satisfyOldUpdateRunner` or in the new
80+
# `daedalus-frontend`):
81+
if [ -e "$DAEDALUS_DIR"/@CLUSTER@/daedalus_lockfile ] ; then
82+
mv "$DAEDALUS_DIR"/@CLUSTER@/daedalus_lockfile \
83+
"$DAEDALUS_DIR"/@CLUSTER@/daedalus_lockfile.pre-auto-update || true
84+
fi
85+
86+
echo STATUS "Done"
87+
echo PROG 5/$num_steps
7188
if [ -z "$in_chroot" ] ; then
89+
echo
7290
echo "Installed successfully!"
7391
echo
7492
echo "Now, either:"

nix/internal/x86_64-linux.nix

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,27 @@ in rec {
184184
];
185185
});
186186

187-
relocatableElectron = (import (pkgs.runCommandNoCC "nix-bundle-exe-patched" {} ''
187+
relocatableElectron = let
188+
additionalLibs = ''
189+
additionalLibs=(
190+
${pkgs.xorg.libX11}/lib/libX11-xcb.so.1
191+
${pkgs.xorg.libxcb}/lib/*.so.?
192+
${pkgs.systemd /* patched */}/lib/{libudev.so.1,libsystemd.so.0,libnss_*.so.2}
193+
${pkgs.nss}/lib/*.so
194+
${pkgs.libusb}/lib/*.so.0
195+
${pkgs.nssmdns}/lib/*.so.2
196+
${pkgs.numactl}/lib/libnuma.so.1
197+
${pkgs.pciutils}/lib/libpci.so.3
198+
${pkgs.libva.out}/lib/*.so.2
199+
${pkgs.atk}/lib/libatk-bridge-2.0.so
200+
$(find ${pkgs.glibc}/lib -type l)
201+
)
202+
'';
203+
in (import (pkgs.runCommandNoCC "nix-bundle-exe-patched" {} ''
188204
cp -r ${inputs.nix-bundle-exe} $out
189205
chmod -R +w $out
190-
for additionalLib in \
191-
${pkgs.xorg.libX11}/lib/libX11-xcb.so.1 \
192-
${pkgs.systemd /* patched */}/lib/{libudev.so.1,libsystemd.so.0,libnss_*.so.2} \
193-
${pkgs.nss}/lib/*.so \
194-
; do
206+
${additionalLibs}
207+
for additionalLib in "''${additionalLibs[@]}" ; do
195208
sed -r '/bundleExe "\$binary"/a\ bundleLib "'"$additionalLib"'" "lib"' -i $out/bundle-linux.sh
196209
done
197210
'') {
@@ -200,7 +213,7 @@ in rec {
200213
#bin_dir = "electron-bin";
201214
inherit pkgs;
202215
} electronBin).overrideAttrs (drv: {
203-
buildCommand = (builtins.replaceStrings ["find '"] ["find -L '"] drv.buildCommand) + ''
216+
buildCommand = additionalLibs + (builtins.replaceStrings ["find '"] ["find -L '"] drv.buildCommand) + ''
204217
chmod -R +w $out
205218
206219
mkdir -p $out/lib
@@ -212,6 +225,8 @@ in rec {
212225
rm $out/lib/electron/lib/ld-linux-x86-64.so.2
213226
( cd $out/lib/electron && rm libffmpeg.so && ln -s lib/libffmpeg.so libffmpeg.so ; )
214227
228+
( cd $out/lib/electron/lib && ln -s libatk-bridge-2.0.so libatk-bridge.so ; )
229+
215230
patchelf --set-rpath '$ORIGIN/lib:$ORIGIN' $out/lib/electron/electron
216231
217232
cp ${pkgs.writeScript "electron" ''
@@ -291,8 +306,8 @@ in rec {
291306
mkdir -p "''${DAEDALUS_DIR}/${cluster}"/Secrets
292307
cd "''${DAEDALUS_DIR}/${cluster}/"
293308
294-
if [ -e "''${DAEDALUS_DIR}/${cluster}"/daedalus_lockfile.old-nix-chroot ] ; then
295-
rm "''${DAEDALUS_DIR}/${cluster}"/daedalus_lockfile.old-nix-chroot || true
309+
if [ -e "''${DAEDALUS_DIR}/${cluster}"/daedalus_lockfile.pre-auto-update ] ; then
310+
rm "''${DAEDALUS_DIR}/${cluster}"/daedalus_lockfile.pre-auto-update || true
296311
fi
297312
298313
exec cardano-launcher --config "$ENTRYPOINT_DIR/config/launcher-config.yaml"
@@ -301,10 +316,25 @@ in rec {
301316
cp ${pkgs.writeText "daedalus-frontend" ''
302317
#!/bin/sh
303318
set -xe
319+
320+
# `daedalus-frontend` is what `cardano-launcher` restarts during auto-update; let’s detect
321+
# this case here, and restart the `cardano-launcher` itself, in case we need it to
322+
# be updated as well:
323+
if [ -e "''${DAEDALUS_DIR}/${cluster}"/daedalus_lockfile.pre-auto-update ] ; then
324+
nohup setsid ~/.daedalus/${cluster}/bin/daedalus </dev/null >/dev/null 2>/dev/null &
325+
exit 0
326+
fi
327+
304328
exec electron --disable-setuid-sandbox --no-sandbox "$ENTRYPOINT_DIR"/libexec/daedalus-js "$@"
305329
''} $out/libexec/daedalus-frontend
306330
307-
chmod +x $out/bin/* $out/libexec/daedalus-frontend
331+
cp ${pkgs.writeText "update-runner" ''
332+
#!/bin/sh
333+
set -xe
334+
exec "$1"
335+
''} $out/libexec/update-runner
336+
337+
chmod +x $out/bin/* $out/libexec/{daedalus-frontend,update-runner}
308338
309339
mkdir -p $out/share/applications
310340
cp ${common.launcherConfigs.${cluster}.installerConfig.iconPath.large} $out/share/icon_large.png
@@ -422,10 +452,6 @@ in rec {
422452
echo -n "$HOME/.daedalus${pkgs.writeScript "escape-and-scrap-chroot" ''
423453
#!/bin/sh
424454
set -eu
425-
XDG_DATA_HOME="''${XDG_DATA_HOME:-''${HOME}/.local/share}"
426-
DAEDALUS_DIR="''${XDG_DATA_HOME}/Daedalus"
427-
mv "$DAEDALUS_DIR"/${cluster}/daedalus_lockfile \
428-
"$DAEDALUS_DIR"/${cluster}/daedalus_lockfile.old-nix-chroot || true
429455
nohup setsid ~/.daedalus/${cluster}/bin/daedalus </dev/null >/dev/null 2>/dev/null &
430456
sleep 5
431457
${removeOldNixChroot.${cluster}}

0 commit comments

Comments
 (0)