I want to add an init script to my RPM in order to run the program from a terminal just by typing its name, there's one more thing which I am confused about and that is:-
where are these files located: pre, post, preun, postun, are they written directly into the spec file after adding a line %pre etc.
I've been through the following links however I couldn't find a solution: -
https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd
https://fedoraproject.org/wiki/Packaging:Systemd?#Filesystem_locations
Updated===============================================================
I am doing it on CentOS 6.8 and here's the spec file I created so far:-
# RPM package for xyz.
%define __spec_install_post %{nil}
%define debug_package %{nil}
%define __os_install_post %{_dbpath}/brp-compress
Summary: XYZ program.
Name: xyz
Version: 1.0
Release: 1
License: GPL+
Group: Development/Tools
SOURCE0 : %{name}-%{version}.tar.gz
URL: https://wwwDOTxyzDOTcom/
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
%description
%{summary}
%prep
%setup -q
%build
# Empty section.
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
# in builddir
cp -a * %{buildroot}
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%{_bindir}/*
%changelog
* Mon Mar 6 2017 xyz <noemail#noemail.com> 1.0-1
- First Build
EOF
but still confused as to how do I start the program from a terminal just by typing its name.
You mean SYSV init files? Or systemD unit files? Different logic, but ok - at the end they are both files. In different location, but just files.
You have to do:
%{?systemd_requires}
BuildRequires: systemd
%install
cp -a path/in/your/targz/SOMESERVICE.service %{buildroot}%{_unitdir}/
%post
%systemd_post SOMESERVICE.service
%preun
%systemd_preun SOMESERVICE.service
%postun
%systemd_postun_with_restart SOMESERVICE.service
%files
%{_unitdir}/SOMESERVICE.service
For SYSV there would be little bit different paths and different snippets in %post* and %preun.
Related
I want to build a rpm package from a spec file(hello-world.spec).The command and error output are given below
Command1:
rpmbuild -ba hello-world.spec
ErrorOutput1:
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.z4GoQn
+ umask 022
+ cd /root/rpmbuild/BUILD
+
: not foundm-tmp.z4GoQn: 28: /var/tmp/rpm-tmp.z4GoQn:
error: Bad exit status from /var/tmp/rpm-tmp.z4GoQn (%prep)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.z4GoQn (%prep)
Content of my spec file is
Name: hello-world
Version: 1
Release: 1
Summary: Most simple RPM package
License: FIXME
%description
This is my first RPM package, which does nothing.
%prep
# we have no source, so nothing here
%build
cat > hello-world.sh <<EOF
#!/usr/bin/bash
echo Hello world
EOF
%install
mkdir -p %{buildroot}/usr/bin/
install -m 755 hello-world.sh %{buildroot}/usr/bin/hello-world.sh
%files
/usr/bin/hello-world.sh
%changelog
# let's skip this for now
My System/software details are
OS: Ubuntu 16.04
RPM version:4.12.0.1
The list of contents in rpmbuild folder is
Command2:
:~/rpmbuild# ls
Output2:
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
Can anybody help on this issue?
Check how your files is being generated. If you are passing files from windows to Linux, usually, there are different EOL for the files. We had a similar issue, I recommend you to change all the files to Unix format. I'm sharing with you how to reproduce your issue, if you edit that file in a Linux environment, like "nano", the problem disappears.
I'm new to the rpmbuild, googled and copy one spec file paramenters and created rpm successfully when i ran it the rpm nothing is creating
var.tar.gz -- this is my tar file. it has
var/
var/www/
var/www/html/index.html
My spec file
[root#kaka1 SPECS]# vi var.spec
Name: var
Version: 1
Release: 0
Summary: Xiph Streaming media server that supports multiple formats.
Group: Applications/Multimedia
License: GPL
URL: http################
Source: var-1.0.tar.gz
Prefix: %{_prefix}
Packager: Sukama
BuildRoot: %{_tmppath}/%{name}-root
%description
easily and supports open standards for commuincation and interaction.
%prep
rm -rf /root/rpmbuild/BUILD/*
%setup -n var
gzip -dc /root/rpmbuild/SOURCES/var-1.0.tar.gz| tar -xvvf -
if [ $? -ne 0 ]; then
exit $?
fi
could you help me where can i should mention my files to create under root?
First, don't use name like var, usr as package name, use that's more relevant to what the package may represent. Here is a simple spec file that should install index.html into the /var/www directory.
%define debug_package %{nil}
Summary: Simple SPEC
Name: simple
Version: 0
Release: 1
License: NONE # Use your suitable license
Group: NONE
URL: NONE
Source0: %{name}-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
## Following lines are commented out, but that's the way to go
#BuildRequires: httpd # This needs https RPM during your build
#Requires: httpd # This would require httpd to be installed for this RPM
%description
%prep
%setup -q # This untars the source
%build # currently empty
%install # This moves into the source directory "simple-0" (see below)
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/var/www
install -m 0644 index.html %{buildroot}/var/www/index.html
%clean
rm -rf $RPM_BUILD_ROOT
%post
%files
%defattr(-,root,root,-)
%doc
/var/www/index.html # Your packages owns the file, but not the directories
%changelog
* Web Feb 14 2018 <user#localhost> - 0.0
- Initial build.
For the above .spec file, one would need a tarball named simple-0.tar.gz. This maps to the Source0 name that is used inside the .spec. The content in this case would be a directory and a file: simple-0/index.html.
My rpmbuild is supposed to happen in /include, /lib, and /share, I have specified this in the spec file. But when in the BUILDROOT directory, it is creating in /usr/local/include, /usr/local/lib, /usr/local/share instead. And then is throwing an error (obviously) because I am looking for the files in the previous location.
Why would this happen? Nowhere am I specifying /usr/local, then why does it take this location?
This is my .spec file:-
%define __spec_install_post %{nil}
%define debug_package %{nil}
%define __os_install_post %{_dbpath}/brp-compress
Summary: test
Name: TEST
Version: 1.0
Release: 1
License: MYORG
Group: Development/Tools
SOURCE0 : %{name}.tar.gz
%define pbs_prefix /opt/dir1/TEST
BuildRoot: %{_topdir}/%{name}
%description
%{summary}
%prep
%setup -q
%build
./configure --with-prefix=/opt/dir1/TEST --with-drms-dir=/opt/dir1
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
%make_install
%clean
rm -rf %{buildroot}
%files
/opt/dir1/TEST/include/*
/opt/dir1/TEST/lib/*
/opt/dir1/TEST/share/*
My ~/.rpmmacros file is:-
%_topdir %(echo $HOME)/rpmbuild
%_tmppath %{_topdir}/tmp
I want to build so that my TEST-1.0-1x86_64/ has /include, /lib and /share not /usr/local/...
The --prefix option sets your path. Not --with-prefix.
Following all the random guides on the net and even on here:
What is the minimum I have to do to create an RPM file?
Nothing seems to work with Centos 7 (surprise!)
It seems if you leave %prep in your spec file, rpmbuild will try its hardest to ./configure and make something. what I'm not sure.
here is a super basic .spec file I'm trying to make an rpm to just copy in a file.
$more newpackage.spec
Name: hello
Version: 1.2
Release: 1%{?dist}
Summary: Testing testing 1 2 3
License: Beer
URL: No
#so apparently now you have to have version numbers everywhere, even the tar files, uhg
Source0: hello-1.2.tar.gz
#and the breaking begins :-( why everything broke with you centos 7?
# BuildRoot: %{_tmppath}/%{name}-%{version}-root
# BuildRequires:
# Requires:
%description
nothing to see here folks
#well here is some of the confusion
#%prep
%setup -q
# ./configure missing? um yeahhhh
# %build
# %configure
# make %{?_smp_mflags}
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
%files
#/usr/bin/hello.sh
%{_bindir}/hello.sh
# %doc
# %changelog
in side the tar file is /usr/bin/hello.sh
which is shell script that just runs echo "hello world"
if i comment %prep rpmbuild complains about ./configure not being found.
rpmbuild -v -bb newpackage.spec
Looks like commenting out %build dosen't actully stop rpmbuild from trying to build the sources...
so if i DELETE out %build and %configure and that make line. things work
I need advice about the following
I build simple spec file and build rpm
I transfer the new rpm to other Linux machine in order to install the new rpm
according to the spec file the new rpm -> test.sh-6.2-2.i386.rpm should create the
/tmp/MY_RPM_TESTS directory , but this rpm not create the MY_RPM_TESTS and sub directories
please advice why , what I need to fix in the spec file?
RPM installation:
[root#linux1 rpm -Uvh /root/rpmbuild/RPMS/i386/test.sh-6.2-2.i386.rpm
Preparing... ########################################### [100%]
This is preinstall script
Linux linux 2.6.18-164.2.1.el5PAE #1 SMP Mon Sep 21 04:45:05 EDT 2009 i686 i686 i386 GNU/Linux
1:test.sh ########################################### [100%]
Linux linux 2.6.18-164.2.1.el5PAE #1 SMP Mon Sep 21 04:45:05 EDT 2009 i686 i686 i386 GNU/Linux
Now we wait for sleep
100
[root#linux1 ls /tmp
preinstall_dir
my SPEC file:
root#linux /usr/src/redhat/SPECS]# more my_spec.spec
Summary: An example tool. To show a simple rpm build of the tool.
Name: test.sh
Version: 6.2
Release: 2
Source0: /root/test.sh
Source1: /root/urim.sh
Group: Development/Debuggers
BuildRoot:/tmp/MY_RPM_TESTS
License: OtherLicense
%description
%pre -p /bin/ksh
print "This is preinstall script"
uname -a
rm -rf /tmp/preinstall_dir
mkdir /tmp/preinstall_dir
%install
rm -rf %{buildroot}
mkdir -p %{buildroot}
mkdir -p %{buildroot}/home
mkdir -p %{buildroot}/home/home1
cp %SOURCE0 %{buildroot}/home
cp %SOURCE0 %{buildroot}/home/home1
cp %SOURCE1 %{buildroot}/home
%files
/home/test.sh
/home/home1/test.sh
/home/urim.sh
%post -p /bin/ksh
uname -a
print "Now we wait for sleep" ; sleep 1
NUM=100
print $NUM
Build the rpm:
[root#linux /usr/src/redhat/SPECS]# rpm -ba /usr/src/redhat/SPECS/my_spec.spec
Executing(%install): /bin/sh -e /root/rpmbuild/tmp/rpm-tmp.83360
+ umask 022
+ cd /root/rpmbuild/BUILD
+ rm -rf /tmp/MY_RPM_TESTS
+ mkdir -p /tmp/MY_RPM_TESTS
+ mkdir -p /tmp/MY_RPM_TESTS/home
+ mkdir -p /tmp/MY_RPM_TESTS/home/home1
+ cp /root/rpmbuild/SOURCES/test.sh /tmp/MY_RPM_TESTS/home
+ cp /root/rpmbuild/SOURCES/test.sh /tmp/MY_RPM_TESTS/home/home1
+ cp /root/rpmbuild/SOURCES/urim.sh /tmp/MY_RPM_TESTS/home
+ /usr/lib/rpm/brp-compress
+ /usr/lib/rpm/brp-strip
+ /usr/lib/rpm/brp-strip-static-archive
+ /usr/lib/rpm/brp-strip-comment-note
Processing files: test.sh-6.2-2
Requires(interp): /bin/ksh /bin/ksh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib (PayloadFilesHavePrefix) <= 4.0-1
Requires(pre): /bin/ksh
Requires(post): /bin/ksh
Checking for unpackaged file(s): /usr/lib/rpm/check-files /tmp/MY_RPM_TESTS
Wrote: /root/rpmbuild/SRPMS/test.sh-6.2-2.src.rpm
Wrote: /root/rpmbuild/RPMS/i386/test.sh-6.2-2.i386.rpm
You misunderstand. /tmp/MY_RPM_TESTS is the build root, which is created, but is only used temporarily and internally by rpmbuild. It is not meant to be part of the rpm file, and you should never try to install anything in /tmp anyway! /tmp is for temporary files only.