View Full Version : Unable to build a rpm
jagga13
11th April 2011, 07:55 PM
Hey Guys,
I am trying to build a rpm that basically changes the root password on a system. Here is what my spec file looks like:
--
Summary: Update the root password
Name: update_passwd
Version: 1.0
Release: 1
Group: Operations
License: GPL
Packager: Jagga <xxx@gmail.com>
%description
This rpm updates the root password.
%pre
/bin/cp /etc/passwd /etc/passwd.`date +%d%b%Y`
%install
/bin/echo 'root:$1$qBtm3NRO$SlwrZJL3fBgLZ7wQ/I8PO/' | /usr/sbin/chpasswd -e
--
However, when I run a "rpmbuild -ba specfile", I only get a *src.rpm under /usr/src/redhat/SRPMS, but no rpm file. I have never created a rpm and was wondering if there is something I am missing in my spec file?
Thanks,
-J
leigh123linux
11th April 2011, 08:18 PM
Try reading this guide
How to create an RPM package - FedoraProject (http://fedoraproject.org/wiki/How_to_create_an_RPM_package)
jagga13
11th April 2011, 08:33 PM
That is what I went through.. I am not really building/compiling any package and just need to run this simple command. Am I missing something in the document?
-J
jagga13
12th April 2011, 06:02 PM
Okay, so I added this file and it was able to generate the rpm. However, how do I make this rpm run this script when the user installs this rpm?
--
Summary: Update the root password
Name: update_passwd
Version: 1.0
Release: 1
License: GPL
Group: Development/Tools
URL: http://www.test.com/
BuildRoot: /root/rpmbuild/BUILDROOT
BuildArch: noarch
%description
This rpm updates the root password
%prep
%install
#rm -rf $RPM_BUILD_ROOT
%clean
#rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
/tmp/update_passwd.sh
--
Thanks for your help.
-J
leigh123linux
12th April 2011, 08:17 PM
Okay, so I added this file and it was able to generate the rpm. However, how do I make this rpm run this script when the user installs this rpm?
--
Summary: Update the root password
Name: update_passwd
Version: 1.0
Release: 1
License: GPL
Group: Development/Tools
URL: http://www.test.com/
BuildRoot: /root/rpmbuild/BUILDROOT
BuildArch: noarch
%description
This rpm updates the root password
%prep
%install
#rm -rf $RPM_BUILD_ROOT
%clean
#rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
/tmp/update_passwd.sh
--
Thanks for your help.
-J
run the script using a scriptlet
http://fedoraproject.org/wiki/How_to_create_an_RPM_package#Scriptlets
DBelton
12th April 2011, 08:23 PM
to be honest, I am hoping that it won't allow an rpm package to change the root password. That opens up all kinds of security issues if it does.
jagga13
12th April 2011, 10:06 PM
Thanks leigh123linux. I am now able to deliver the script and run it when the rpm installs. It looks like the chpasswd command belongs to the shadow-utils on redhat and pwdutils on sles. Is there some smarts that I can add to this rpm for the require's section to check for shadow-utils on redhat and pwdutils on sles before installing this rpm? If I list both, then this rpm would probably not install on rhel or sles.
-J
leigh123linux
12th April 2011, 10:13 PM
Try
%if 0%{?fedora} || 0%{?rhel}
Requires: shadow-utils
%else
Requires: pwdutils
%endif
jagga13
12th April 2011, 10:28 PM
Nope, it keeps defaulting to pwdutils even on rhel servers:
--
[root@testrhel tmp]# rpm -Uvh update_rootpw-1.0-1.noarch.rpm
error: Failed dependencies:
pwdutils is needed by update_rootpw-1.0-1.noarch
[root@testrhel tmp]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.6 (Tikanga)
[root@testrhel tmp]# rpm -qa | grep -i shadow-utils
shadow-utils-4.0.17-18.el5
--
..snip..
BuildRoot: /root/rpmbuild/BUILDROOT
BuildArch: noarch
%if 0%{?fedora} || 0%{?rhel}
Requires: shadow-utils
%else
Requires: pwdutils
%endif
..snip..
Where is it getting those fedora and rhel keywords from?
-J
leigh123linux
12th April 2011, 10:46 PM
Try installing redhat-rpm-config
jagga13
12th April 2011, 10:52 PM
I do have redhat-rpm-config-8.0.45-32.el5 installed on the system I am running rpmbuild on.
---------- Post added at 09:52 PM ---------- Previous post was at 09:52 PM ----------
# yum list installed | grep -i redhat-rpm-config
redhat-rpm-config.noarch 8.0.45-32.el5 installed
leigh123linux
12th April 2011, 11:05 PM
I think I made a syntax error
try
%if ! (0%{?fedora} > 1 || 0%{?rhel} > 4)
Requires: shadow-utils
%else
Requires: pwdutils
%endif
jagga13
12th April 2011, 11:09 PM
hrmm.. does that not mean if !(not) fedora or rhel then test if shadow-utils exists else if would be rhel or fedora.. maybe I am understanding this wrong, but it seems to work.. can you explain the syntax :) plz
-J
leigh123linux
12th April 2011, 11:36 PM
hrmm.. does that not mean if !(not) fedora or rhel then test if shadow-utils exists else if would be rhel or fedora.. maybe I am understanding this wrong, but it seems to work.. can you explain the syntax :) plz
-J
I borrowed it from here
https://fedoraproject.org/wiki/Packaging/Python#Macros
vBulletin® v3.8.7, Copyright ©2000-2013, vBulletin Solutions, Inc.