[Rpm-maint] [rpm-software-management/rpm] The RPM_INSTALL_PREFIX environment variable is missing in lua %post scriptets (#1531)

Jude N notifications at github.com
Sun Feb 7 17:55:36 UTC 2021


When installing a relocatable rpm with the "--prefix" flag, the RPM_INSTALL_PREFIX variable is missing for lua-based %post scriptlets.  It is showing up in the scriptlet is lua isn't used. 

I'm seeing this on CentOS Linux release 8.3.2011 and rpm version  4.14.3.

Here's an example spec file, along with a workaround, which uses a non-lua-based %pre scriptlet to dump the RPM_INSTALL_PREFIX value to a file which the %post script then reads.

```
Name:           rpm-lua-bug
Version:        1.0.0 
Release:        1%{?dist}
Summary:        A spec file showing lua scriptlet aren't getting the RPM_INSTALL_PREFIX environment variable
License:        GPLv2+
URL:            http://bugtown.usa/bugid=1 

Prefix:         /opt/rpm-lua-bug 

%description
A spec file showing lua scripts aren't getting the RPM_INSTALL_PREFIX environment variable

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/opt/rpm-lua-bug
echo "sup" >  $RPM_BUILD_ROOT/opt/rpm-lua-bug/sup

%pre
echo "Dumping preinstall environment via /usr/bin/env"
/usr/bin/env
echo preinstall script
echo "RPM_INSTALL_PREFIX=$RPM_INSTALL_PREFIX"
echo "RPM_INSTALL_PREFIX0=$RPM_INSTALL_PREFIX0"

# Workaround based on https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_saving_state_between_scriptlets
if [ "$RPM_INSTALL_PREFIX" != "" ]; then
   echo "Creating %{_localstatedir}/lib/rpm-state/rpm_install_prefix with contents $RPM_INSTALL_PREFIX"
   echo $RPM_INSTALL_PREFIX > %{_localstatedir}/lib/rpm-state/rpm_install_prefix
fi
#%post
#echo "---------------------------"
#env

%post -p <lua>
print("-----------------")
print("postinstall <lua>")
print("Dump the available environment variables via posix.getenv()")
for i, s in pairs(posix.getenv()) do print(i,s,"") end
rpm_install_prefix=posix.getenv('RPM_INSTALL_PREFIX')
print('RPM_INSTALL_PREFIX (via posix.getenv())='..(rpm_install_prefix or "<undefined>")) 

-- WORKAROUND
print("WORKAROUND:  Pull RPM_INSTALL_PREFIX from %{_localstatedir}/lib/rpm-state/rpm_install_prefix")
if posix.access("%{_localstatedir}/lib/rpm-state/rpm_install_prefix", "r") then
   prefix_file = io.open("%{_localstatedir}/lib/rpm-state/rpm_install_prefix", "r")
   rpm_install_prefix = prefix_file:read("*a")
   rpm_install_prefix = string.gsub(rpm_install_prefix, "%s+", "")
   prefix_file:close()
   os.remove("%{_localstatedir}/lib/rpm-state/rpm_install_prefix")
end
print('RPM_INSTALL_PREFIX (WORKAROUND)='..(rpm_install_prefix or "<undefined>"))

%files
/opt/rpm-lua-bug/sup
#%license add-license-file-here
#%doc add-docs-here

%changelog
* Thu Feb  4 2021 Created spec file
- 
```

Here's the output from installing the rpm (I've removed the dumped env vars for readability)
```
[vagrant at localhost ~]$ sudo rpm -i --install --force --prefix=/opt/nope  rpmbuild/RPMS/x86_64/rpm-lua-bug-1.0.0-1.el8.x86_64.rpm 
Dumping preinstall environment via /usr/bin/env
<removed>
RPM_INSTALL_PREFIX=/opt/nope
RPM_INSTALL_PREFIX0=/opt/nope
Creating /var/lib/rpm-state/rpm_install_prefix with contents /opt/nope
-----------------
postinstall <lua>
Dump the available environment variables via posix.getenv()
<removed>
RPM_INSTALL_PREFIX (via posix.getenv())=<undefined>
WORKAROUND:  Pull RPM_INSTALL_PREFIX from /var/lib/rpm-state/rpm_install_prefix
RPM_INSTALL_PREFIX (WORKAROUND)=/opt/nope

```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/rpm-software-management/rpm/issues/1531
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rpm.org/pipermail/rpm-maint/attachments/20210207/fc8fb5b6/attachment.html>


More information about the Rpm-maint mailing list