diff --git a/install.sh b/install.sh index 00b78e41..75b9ad7c 100755 --- a/install.sh +++ b/install.sh @@ -269,8 +269,8 @@ install_exec syncthing/startstop-syncthing.sh "$DESTDIR$usr_sbindir/ install_data dbus-user-session/dbus.service "$DESTDIR$usr_libdir/systemd/user/dbus.service" install_data dbus-user-session/dbus.socket "$DESTDIR$usr_libdir/systemd/user/dbus.socket" install_symlink ../dbus.socket "$DESTDIR$usr_libdir/systemd/user/sockets.target.wants/dbus.socket" -for f in post-pdist/*; do - install_exec "$f" "$DESTDIR$usr_exec_prefix/libexec/post-pdist/$(basename "$f")" +for f in pdist/post-update.d/*; do + install_exec "$f" "$DESTDIR$usr_exec_prefix/libexec/pdist/post-update.d/$(basename "$f")" done postinstall diff --git a/pdist/pdist b/pdist/pdist index b82c6cfd..8aad04b1 100755 --- a/pdist/pdist +++ b/pdist/pdist @@ -170,6 +170,7 @@ BEGIN { use constant { DISTFILE => '/root/Distfile', # read FILES,HOSTS,EXCEPTS here + POST_UPDATE_DIR => '/usr/libexec/pdist/post-update.d', # run scripts from here after a successful update }; our $PID=$$; @@ -846,6 +847,27 @@ sub prog_update } } +sub run_post_update_scripts { + my $hostname = hostname; + + unless (opendir DIR, POST_UPDATE_DIR) { + $! == 2 and return; # ENOENT: no scripts installed + die POST_UPDATE_DIR . ": $!\n"; + } + my @scripts = sort grep /^[0-9][-.0-9A-Za-z_]*$/, readdir DIR; + closedir DIR; + + for my $script (@scripts) { + my $path = POST_UPDATE_DIR . '/' . $script; + -f $path or next; # ignore subdirectories + $quiet or warn "$hostname: executing $path\n"; + system $path; + $? == -1 and die "$path: $!\n"; + $? & 127 and die sprintf "%s: killed by signal %d\n", $path, $? & 127; + $? and die sprintf "%s: exit status %d\n", $path, $? >> 8; + } +} + sub prog_client { my ($master,$port)=@_; @@ -944,6 +966,8 @@ sub prog_client unlink ($master_index); unlink ($requestfile); + $fileop_noop or run_post_update_scripts(); + if ($post_command) { $verbose and warn "$hostname: executing $post_command\n"; $fileop_noop or system $post_command; @@ -1179,6 +1203,11 @@ usage: $0 cmd [options] update want-indexfile [tarfile] # update to want-indexfile using tar client master-name port [--msg-prefix] xxx # client server + # after a successful update the client runs all scripts in + # @{[POST_UPDATE_DIR]}/ whose name starts with a digit, in name + # order, and aborts on the first one which fails. --post-command, if + # given, runs afterwards. + # high level push [options] client ... # update client with our snapshot diff --git a/pdist/pdist-bootcheck b/pdist/pdist-bootcheck index 95531ae0..93f8236c 100755 --- a/pdist/pdist-bootcheck +++ b/pdist/pdist-bootcheck @@ -29,7 +29,7 @@ fi if [ "$need_async_pdist" ]; then systemd-run --unit pdist-async-update --service-type=simple --remain-after-exit \ - -- bash -c 'netcat $(distmaster) 237 ; make-automaps' + -- bash -c 'netcat $(distmaster) 237' echo triggered background update elif [ "$need_pdist_and_reboot" ]; then if [[ -e /var/cache/updatecheck.reboot-triggered ]]; then @@ -46,7 +46,6 @@ elif [ "$need_pdist_and_reboot" ]; then sync / while true; do sleep 5; echo "System update in progress. Please be patient..."; done & netcat $(distmaster) 237 - make-automaps mxgrub default systemctl start reboot.target --job-mode=replace-irreversibly fi diff --git a/pdist/pdistd@.service b/pdist/pdistd@.service index 186da67b..f246aa4c 100644 --- a/pdist/pdistd@.service +++ b/pdist/pdistd@.service @@ -3,4 +3,4 @@ CollectMode=inactive-or-failed [Service] StandardOutput=socket -ExecStart=bash -c "read ip host <<< $(getent hosts ${REMOTE_ADDR}) ; echo update in progess... ; pdist push $host --timeout 600 --set-pdist-status --post-command /usr/libexec/post-pdist/post-pdist" +ExecStart=bash -c "read ip host <<< $(getent hosts ${REMOTE_ADDR}) ; echo update in progess... ; pdist push $host --timeout 600 --set-pdist-status" diff --git a/post-pdist/0001-convert-default-target b/pdist/post-update.d/0001-convert-default-target similarity index 100% rename from post-pdist/0001-convert-default-target rename to pdist/post-update.d/0001-convert-default-target diff --git a/post-pdist/0002-reload-systemd-260.2 b/pdist/post-update.d/0002-reload-systemd-260.2 similarity index 100% rename from post-pdist/0002-reload-systemd-260.2 rename to pdist/post-update.d/0002-reload-systemd-260.2 diff --git a/pdist/post-update.d/0005-make-automaps b/pdist/post-update.d/0005-make-automaps new file mode 100755 index 00000000..f5a92ed9 --- /dev/null +++ b/pdist/post-update.d/0005-make-automaps @@ -0,0 +1,3 @@ +#!/bin/bash + +/usr/sbin/make-automaps diff --git a/post-pdist/post-pdist b/post-pdist/post-pdist deleted file mode 100755 index 439cfda3..00000000 --- a/post-pdist/post-pdist +++ /dev/null @@ -1,9 +0,0 @@ -#! /bin/bash - -# Call scripts after successfull distmaster pdist - -set -e - -for f in /usr/libexec/post-pdist/[0-9]*; do - "$f" -done