From 5836229baef191ab1d176d8723d2232b54f4f0cf Mon Sep 17 00:00:00 2001 From: Anton Farygin Date: Tue, 23 Dec 2025 10:45:41 +0300 Subject: [PATCH] fix: Escape percent signs in plaintext scripts for RPM spec Scripts (preinst, postinst, prerm, postrm) may contain literal '%' characters (e.g., in printf format strings). When these scripts are written directly into the RPM spec file, rpmbuild interprets '%' as the start of a macro, causing build failures. --- Alien/Package/Rpm.pm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Alien/Package/Rpm.pm b/Alien/Package/Rpm.pm index 2c9c8a4..18cc0de 100644 --- a/Alien/Package/Rpm.pm +++ b/Alien/Package/Rpm.pm @@ -483,22 +483,22 @@ sub prep { if ($this->usescripts) { if ($this->preinst) { print OUT "\%pre\n"; - print OUT $this->preinst."\n"; + print OUT escape_percents($this->preinst)."\n"; print OUT "\n"; } if ($this->postinst) { print OUT "\%post\n"; - print OUT $this->postinst."\n"; + print OUT escape_percents($this->postinst)."\n"; print OUT "\n"; } if ($this->prerm) { print OUT "\%preun\n"; - print OUT $this->prerm."\n"; + print OUT escape_percents($this->prerm)."\n"; print OUT "\n"; } if ($this->postrm) { print OUT "\%postun\n"; - print OUT $this->postrm."\n"; + print OUT escape_percents($this->postrm)."\n"; print OUT "\n"; } } @@ -659,6 +659,7 @@ sub _script_helper { $this->{$script} = $value; } $this->{$script} = shift if @_; + return $this->{$script}; # get return unless defined wantarray; # optimization @@ -694,6 +695,11 @@ sub prerm { my $this=shift; $this->_script_helper('prerm', @_); } +sub escape_percents { + my $s=shift; + $s =~ s/\%/\%\%/g; + return $s; +} =item arch