diff --git a/.gitignore b/.gitignore index d2331fbb60..ca5bcb5297 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ Gitinfo # Build residue: buildrpms.pl and builddebs.pl write these into the source # tree, so a "git add -A" after a build sweeps them into a commit. dist/ +/.xCAT-server-live-root.build-link +/.xCATsn-live-root.build-link perl-xCAT/pods perl-xCAT/share/doc perl-xCAT/share/man diff --git a/builddebs.pl b/builddebs.pl index 00bedf6c9c..b42308de32 100755 --- a/builddebs.pl +++ b/builddebs.pl @@ -171,6 +171,17 @@ my $DEB_DATE = strftime('%a, %d %b %Y %H:%M:%S +0000', gmtime($EPOCH)); sub with_prepared_tree { my ($pkg, $arch, $body) = @_; my $dir = "$ROOT/$pkg"; + my $live_root = "$dir/debian/xcat-live-root-functions"; + my $live_root_backup = "$ROOT/.$pkg-live-root.build-link"; + # Recover the source link before a later build can consume an interrupted copy. + if (-l $live_root_backup) { + rename($live_root_backup, $live_root) + or die "Cannot recover link $live_root: $!\n"; + } + if ($pkg ne 'perl-xCAT' && -f $live_root && !-l $live_root && + read_text($live_root) ne read_text("$ROOT/perl-xCAT/debian/xcat-live-root-functions")) { + die "Cannot build $pkg with a stale live-root helper; restore $live_root from source\n"; + } my @restore; my @remove; @@ -235,12 +246,31 @@ sub with_prepared_tree { write_text($control, pin_control_version(read_text($per_arch), $PKGVER)); } - my $rc = eval { $body->($dir); 1 } ? 0 : 1; + my $rc = eval { + # Source packages cannot depend on another package's source directory. + if (-l $live_root) { + my $text = read_text($live_root); + die "Cannot overwrite $live_root_backup\n" + if -e $live_root_backup || -l $live_root_backup; + rename($live_root, $live_root_backup) + or die "Cannot save link $live_root: $!\n"; + write_text($live_root, $text); + } + $body->($dir); + 1; + } ? 0 : 1; my $err = $@; + my $restore_error; + if (-l $live_root_backup) { + rename($live_root_backup, $live_root) + or $restore_error = "Cannot restore link $live_root: $!\n"; + } unlink @added, @remove; restore_file($_) for reverse @restore; + warn $restore_error if $restore_error && $rc; die $err if $rc; + die $restore_error if $restore_error; return; } diff --git a/perl-xCAT/debian/postrm b/perl-xCAT/debian/postrm index b5617e6d6a..f8902ddfba 100644 --- a/perl-xCAT/debian/postrm +++ b/perl-xCAT/debian/postrm @@ -21,8 +21,7 @@ set -e case "$1" in upgrade) - if [ -x /opt/xcat/sbin/restartxcatd ] && [ -f /proc/cmdline ] && - [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ]; then + if [ -x /opt/xcat/sbin/restartxcatd ] && xcat_is_live_root; then . /etc/profile.d/xcat.sh XCATROOT=/opt/xcat /opt/xcat/sbin/restartxcatd -r fi diff --git a/perl-xCAT/debian/rules b/perl-xCAT/debian/rules index 7a0450ef48..46fb19ddbf 100755 --- a/perl-xCAT/debian/rules +++ b/perl-xCAT/debian/rules @@ -63,6 +63,12 @@ binary-arch: build install dh_perl dh_makeshlibs dh_installdeb + set -e; scriptfile=debian/perl-xcat/DEBIAN/postrm; \ + { head -n 1 "$$scriptfile"; \ + cat debian/xcat-live-root-functions; \ + tail -n +2 "$$scriptfile"; } > "$$scriptfile.tmp"; \ + chmod 755 "$$scriptfile.tmp"; \ + mv "$$scriptfile.tmp" "$$scriptfile" dh_shlibdeps dh_gencontrol dh_md5sums diff --git a/perl-xCAT/debian/xcat-live-root-functions b/perl-xCAT/debian/xcat-live-root-functions new file mode 100644 index 0000000000..2081f9f49a --- /dev/null +++ b/perl-xCAT/debian/xcat-live-root-functions @@ -0,0 +1,5 @@ +xcat_is_live_root() +{ + [ -f /proc/cmdline ] && + [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ] +} diff --git a/xCAT-server/debian/prerm b/xCAT-server/debian/prerm index 9228fcc2f6..c85c167ab0 100644 --- a/xCAT-server/debian/prerm +++ b/xCAT-server/debian/prerm @@ -21,8 +21,7 @@ xcatd_init_compat=/opt/xcat/share/xcat/scripts/xcatd-init-compat case "$1" in remove) - if [ -f /proc/cmdline ] && - [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ]; then + if xcat_is_live_root; then if "$xcatd_init_compat" can-use-systemctl; then systemctl stop xcatd.service systemctl disable --now xcat-uftp-listener.service >/dev/null 2>&1 || true diff --git a/xCAT-server/debian/rules b/xCAT-server/debian/rules index 42e73c583f..bf24333f9a 100755 --- a/xCAT-server/debian/rules +++ b/xCAT-server/debian/rules @@ -101,6 +101,12 @@ binary-arch: chmod 755 "$$scriptfile.tmp"; \ mv "$$scriptfile.tmp" "$$scriptfile"; \ done + set -e; scriptfile=$(buildroot)/DEBIAN/prerm; \ + { head -n 1 "$$scriptfile"; \ + cat debian/xcat-live-root-functions; \ + tail -n +2 "$$scriptfile"; } > "$$scriptfile.tmp"; \ + chmod 755 "$$scriptfile.tmp"; \ + mv "$$scriptfile.tmp" "$$scriptfile" dh_shlibdeps dh_gencontrol -- -Vperl:Depends=perl dh_md5sums diff --git a/xCAT-server/debian/xcat-live-root-functions b/xCAT-server/debian/xcat-live-root-functions new file mode 120000 index 0000000000..c56cc08f0f --- /dev/null +++ b/xCAT-server/debian/xcat-live-root-functions @@ -0,0 +1 @@ +../../perl-xCAT/debian/xcat-live-root-functions \ No newline at end of file diff --git a/xCATsn/debian/postinst b/xCATsn/debian/postinst index 7621b07495..df41ce6e7e 100644 --- a/xCATsn/debian/postinst +++ b/xCATsn/debian/postinst @@ -64,8 +64,7 @@ case "$1" in a2enmod -q headers >/dev/null 2>&1 || : fi - if [ -f /proc/cmdline ] && - [ "$(stat -c '%d:%i' /)" = "$(stat -c '%d:%i' /proc/1/root/. 2>/dev/null)" ]; then + if xcat_is_live_root; then if [ -d /run/systemd/system ] && command -v systemctl >/dev/null 2>&1; then systemctl start xcatd.service elif [ -x /etc/init.d/xcatd ]; then diff --git a/xCATsn/debian/rules b/xCATsn/debian/rules index 38689173dc..032cb47cb1 100755 --- a/xCATsn/debian/rules +++ b/xCATsn/debian/rules @@ -56,6 +56,12 @@ binary-arch: dh_perl dh_makeshlibs dh_installdeb + set -e; scriptfile=debian/xcatsn/DEBIAN/postinst; \ + { head -n 1 "$$scriptfile"; \ + cat debian/xcat-live-root-functions; \ + tail -n +2 "$$scriptfile"; } > "$$scriptfile.tmp"; \ + chmod 755 "$$scriptfile.tmp"; \ + mv "$$scriptfile.tmp" "$$scriptfile" dh_shlibdeps dh_gencontrol dh_md5sums diff --git a/xCATsn/debian/xcat-live-root-functions b/xCATsn/debian/xcat-live-root-functions new file mode 120000 index 0000000000..c56cc08f0f --- /dev/null +++ b/xCATsn/debian/xcat-live-root-functions @@ -0,0 +1 @@ +../../perl-xCAT/debian/xcat-live-root-functions \ No newline at end of file