Heres modifying the the process. I was able to build the rpm however not sure if whatever i have followed is correct or not.(Will read the rpm build process in detail)
How can i modify it to include more than one script files.
Here is the process .
I want to create rpm that is not built by compiling from source code.However they contains a bunch of files.
I just need to package them in order to be able to install them on multiple machines.
1st i have created a normal user as rpmbuild should be done by normal user and not the root.
Code:
# adduser rpmuser
# passwd rpmuser
Changing password for user rpmuser.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
Then created below folders under home directory.
Code:
$ mkdir mybuild
$ mkdir rpmbuild/BUILD
$ mkdir rpmbuild/RPMS
$ mkdir rpmbuild/RPMS/i386
$ mkdir rpmbuild/SOURCES
$ mkdir rpmbuild/SPECS
$ mkdir rpmbuild/SRPMS
Code:
Created .rpmmacros file in home directory to include below lines.
touch ~/.rpmmacros
%_topdir /home/rpmuser/rpmbuild
Created directory
Code:
mkdir -p /home/rpmuser/rpmbuild/SOURCES/myrpm
Edited spec file as below.
Code:
$ cat ~/rpmbuild/SPECS/myrpm.spec
Summary: my script
Name: myrpm
Version: 1
Release: 0
License: none
Source: %{name}.tar.gz
BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-build
Group: System/Base
Vendor: Your name here
%description
This package contains my script
%prep
%setup -n %{name}
%build
%install
mkdir -p $RPM_BUILD_ROOT/usr/local/bin
install -m 700 myscript.sh $RPM_BUILD_ROOT/usr/local/bin/
%clean
rm -rf $RPM_BUILD_ROOT
rm -rf %{_tmppath}/%{name}
rm -rf %{_topdir}/BUILD/%{name}
%files
%defattr(-,root,root)
/usr/local/bin/myscript.sh
%post
/usr/local/bin/myscript.sh
%changelog
Copy the script files to below location.
Code:
$ ls -ltr /home/rpmuser/rpmbuild/SOURCES/myrpm/
total 0
-rw-rw-r-- 1 rpmuser rpmuser 0 Mar 9 09:37 myscript.sh
Created buildrpm file(with little modification) @ below location.
Code:
$ ls -ltr /home/rpmuser/rpmbuild
total 24
-rw-rw-r-- 1 rpmuser rpmuser 805 Mar 9 09:57 buildrpm
drwxrwxr-x 2 rpmuser rpmuser 4096 Mar 9 10:02 SPECS
drwxrwxr-x 2 rpmuser rpmuser 4096 Mar 9 10:02 SRPMS
drwxrwxr-x 3 rpmuser rpmuser 4096 Mar 9 10:02 SOURCES
drwxrwxr-x 4 rpmuser rpmuser 4096 Mar 9 10:02 RPMS
drwxrwxr-x 2 rpmuser rpmuser 4096 Mar 9 10:02 BUILD
content of the file.
Code:
$ cat buildrpm
#!/bin/bash
if [ -z "$1" ];then
echo "You didn't specify anything to build";
exit 1;
fi
cd ~/rpmbuild/SOURCES
# delete older versions of the rpm since there's no point having old
# versions in there when we still have the src.rpms in the SRPMS dir
find ~/rpmbuild/RPMS -name ${1}-[0-9]\* -exec rm -f {} \;
#find /usr/src/packages/RPMS -name ${1}-[0-9]\* -exec rm -f {} \;
# if there's a directory containing the source, as there will be
# for all our own packages, then delete any .tar.gz file that may exist
# for the package and create a new one.
if [ -d ${1} ] ;then
rm -f ${1}.tar.gz;
tar zcf${h_or_not} ${1}.tar.gz ${1};
fi
# build the package
rpmbuild -ba ../SPECS/${1}.spec
# if there is a directory, then delete the .tar.gz again
if [ -d ${1} ] ;then
rm -f ${1}.tar.gz;
fi
Finally.
Code:
$ sh buildrpm myrpm
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.70406
+ umask 022
+ cd /home/rpmuser/rpmbuild/BUILD
+ LANG=C
+ export LANG
+ unset DISPLAY
+ cd /home/rpmuser/rpmbuild/BUILD
+ rm -rf myrpm
+ /bin/gzip -dc /home/rpmuser/rpmbuild/SOURCES/myrpm.tar.gz
+ tar -xvvf -
drwxrwxr-x rpmuser/rpmuser 0 2012-03-09 09:37:30 myrpm/
-rw-rw-r-- rpmuser/rpmuser 0 2012-03-09 09:37:30 myrpm/myscript.sh
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd myrpm
++ /usr/bin/id -u
+ '[' 503 = 0 ']'
++ /usr/bin/id -u
+ '[' 503 = 0 ']'
+ /bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.70406
+ umask 022
+ cd /home/rpmuser/rpmbuild/BUILD
+ cd myrpm
+ LANG=C
+ export LANG
+ unset DISPLAY
+ exit 0
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.70406
+ umask 022
+ cd /home/rpmuser/rpmbuild/BUILD
+ cd myrpm
+ LANG=C
+ export LANG
+ unset DISPLAY
+ mkdir -p /var/tmp/myrpm-build/usr/local/bin
+ install -m 700 myscript.sh /var/tmp/myrpm-build/usr/local/bin/
+ /usr/lib/rpm/find-debuginfo.sh /home/rpmuser/rpmbuild/BUILD/myrpm
0 blocks
find: /var/tmp/myrpm-build/usr/lib: No such file or directory
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
+ /usr/lib/rpm/brp-python-bytecompile
+ /usr/lib/rpm/redhat/brp-java-repack-jars
Processing files: myrpm-1-0
Requires(interp): /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(post): /bin/sh
Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/myrpm-build
Wrote: /home/rpmuser/rpmbuild/SRPMS/myrpm-1-0.src.rpm
Wrote: /home/rpmuser/rpmbuild/RPMS/noarch/myrpm-1-0.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.30105
+ umask 022
+ cd /home/rpmuser/rpmbuild/BUILD
+ cd myrpm
+ rm -rf /var/tmp/myrpm-build
+ rm -rf /var/tmp/myrpm
+ rm -rf /home/rpmuser/rpmbuild/BUILD/myrpm
+ exit 0