2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-12-04 08:07:04 +00:00

refactor(packaging): share Debian live-root detection

This commit is contained in:
Vinícius Ferrão
2026-11-25 14:22:24 -03:00
parent cc69a26075
commit 1cbae2c955
11 changed files with 61 additions and 7 deletions
+2
View File
@@ -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
+31 -1
View File
@@ -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;
}
+1 -2
View File
@@ -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
+6
View File
@@ -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
@@ -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)" ]
}
+1 -2
View File
@@ -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
+6
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
../../perl-xCAT/debian/xcat-live-root-functions
+1 -2
View File
@@ -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
+6
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
../../perl-xCAT/debian/xcat-live-root-functions