Link to home
Start Free TrialLog in
Avatar of Rohit Bajaj
Rohit BajajFlag for India

asked on

understanding an rpm spec file

HI,
I have a following spec file . Please help me understand its different components :
Version: 0.4.3
Release: 1
License: Commercial
Group: System Environment/Daemons
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
BuildArch: x86_64
BuildRequires: libevent-devel
Requires: libevent
Requires(pre): shadow-utils
Requires(post): chkconfig, initscripts
Requires(preun): chkconfig, initscripts


%description

%prep
%setup -q

%build
make

%install
rm -rf $RPM_BUILD_ROOT
make DESTDIR=$RPM_BUILD_ROOT install

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%doc README.md
/usr/local/bin/uecho
/etc/init.d/uecho
/etc/logrotate.d/uecho

%define groupname %{name}
%define username %{name}

%pre
getent group %{groupname} >/dev/null || groupadd -r %{groupname}
getent passwd %{username} >/dev/null || useradd -r -g %{groupname} -s /sbin/nologin %{username}
install -d /var/log/%{name} -o %{username} -g %{groupname} -m 750
exit 0

%post
/sbin/chkconfig --add uecho

%preun
if [ "$1" -eq "0" ] ; then
    /sbin/service uecho stop >/dev/null 2>&1
    /sbin/chkconfig --del uecho
fi


%changelog
- Create log path with appropriate permissions during installation.
- Add logrotate script.

- Initial build.

Open in new window


Any pointers to some of the above thing would be great. Also please share any tutorial or link for the same.
Some particular things i want to understand is the code part :
%pre
getent group %{groupname} >/dev/null || groupadd -r %{groupname}
getent passwd %{username} >/dev/null || useradd -r -g %{groupname} -s /sbin/nologin %{username}
install -d /var/log/%{name} -o %{username} -g %{groupname} -m 750
exit 0

Open in new window


I think this is what is performed prior to installation of the rpm.
what is this doing. i dont understand the getent part.
why a group is added and user is added ?
Thanks
SOLUTION
Avatar of Julian Parker
Julian Parker
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Rohit Bajaj

ASKER

when does %files and %post gets executed.
I wrote a spec file and it looks like the file i have specified in the %files is copied after the %post gets executed.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I guess some problem with my scrip file only.

I am using the following post script :
#!/bin/bash
PATH="$PATH:/bin"
ps -ef | grep '[j]etty' >/dev/null
if [ $? -ne 0 ]; then
  nohup service jetty start &
else
  service jetty stop &;
  nohup service jetty start &
fi

Open in new window

Do you see any problem with it seems like the two statements  (else )are not getting executed...
The second statement needs to run only after the first statement has finished
probably thats what is causing the issue.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial