Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux_wiki:rpm_building [2015/10/22 22:15] billdozor [Spec Example: Custom Scripts] |
linux_wiki:rpm_building [2019/05/25 23:50] (current) |
||
---|---|---|---|
Line 4: | Line 4: | ||
How to create RPM packages from source files. | How to create RPM packages from source files. | ||
+ | |||
+ | Resources: | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
**Checklist** | **Checklist** | ||
- | * Distro: Enterprise Linux 6.x | + | * Distro(s): Enterprise Linux 6 |
---- | ---- | ||
Line 12: | Line 16: | ||
====== Setup Build Environment ====== | ====== Setup Build Environment ====== | ||
- | * Add the [[linux_wiki: | + | * Add the [[linux_wiki: |
* Install packages | * Install packages | ||
Line 21: | Line 25: | ||
* Create a user that will build rpms (regular user) | * Create a user that will build rpms (regular user) | ||
<code bash> | <code bash> | ||
- | useradd | + | useradd |
- | passwd | + | passwd |
</ | </ | ||
* Login as user, create rpm build tree | * Login as user, create rpm build tree | ||
<code bash> | <code bash> | ||
- | su - rpmbuild | + | su - builder |
rpmdev-setuptree | rpmdev-setuptree | ||
</ | </ | ||
- | * This creates a tree structure like: / | + | * This creates a tree structure like: ~/rpmbuild/ |
* BUILD | * BUILD | ||
* RPMS | * RPMS | ||
Line 44: | Line 48: | ||
===== Source Example: Custom Scripts ===== | ===== Source Example: Custom Scripts ===== | ||
+ | |||
+ | Follow the " | ||
Create your directory structure: | Create your directory structure: | ||
Line 49: | Line 55: | ||
mkdir -p ~/ | mkdir -p ~/ | ||
</ | </ | ||
+ | * Note: Everything under " | ||
Copy scripts into the directory | Copy scripts into the directory | ||
Line 68: | Line 75: | ||
===== Source Example: Xymon ===== | ===== Source Example: Xymon ===== | ||
+ | |||
+ | Follow the " | ||
Download source files, place a copy in rpmbuild' | Download source files, place a copy in rpmbuild' | ||
- | * Download the Xymon tar file | + | * Download the Xymon tar file< |
- | * <code bash> | + | * Extract< |
- | * Extract | + | * Copy the original tar file into rpmbuild' |
- | * <code bash>tar -zxvf xymon-4.3.21.tar.gz</ | + | * Copy all files but " |
- | * Copy the original tar file into rpmbuild' | + | |
- | * <code bash>cp ~/ | + | |
- | * Copy all files but " | + | |
- | * <code bash>cp ~/ | + | |
cp ~/ | cp ~/ | ||
cp ~/ | cp ~/ | ||
Line 114: | Line 119: | ||
Create spec file: vim ~/ | Create spec file: vim ~/ | ||
<code bash> | <code bash> | ||
- | # Don't create debug package | + | # Package information |
- | %define | + | |
Name: myscripts | Name: myscripts | ||
Version: 1.0.0 | Version: 1.0.0 | ||
Release: 1%{?dist} | Release: 1%{?dist} | ||
Summary: My Custom Scripts | Summary: My Custom Scripts | ||
- | + | License: GPL+ | |
- | License: GPL | + | Source0: %{name}-%{version}.tar.gz |
- | URL: www.mysite.com | + | |
- | SOURCE0: %{name}-%{version}.tar.gz | + | |
%description | %description | ||
These are my custom scripts used for fun things. | These are my custom scripts used for fun things. | ||
+ | # Don't create debug package | ||
+ | %define | ||
+ | |||
+ | # prep => remove previous build and extract source file (.tar.gz) to the builddir | ||
%prep | %prep | ||
%setup -q | %setup -q | ||
+ | # build => ./configure && make files in builddir; No building for shell scripts required | ||
%build | %build | ||
- | # No building for scripts required. | ||
+ | # install => make install ; read files from builddir, write to buildrootdir. | ||
+ | # Nothing to make install, so do a manual clean, mkdir, and copy. | ||
%install | %install | ||
- | rm -rf $RPM_BUILD_ROOT | + | rm -rf %{buildroot} |
- | mkdir -p $RPM_BUILD_ROOT | + | mkdir -p %{buildroot} |
- | + | cp -a * %{buildroot} | |
- | # From Build Dir | + | |
- | cp -a * $RPM_BUILD_ROOT | + | |
+ | # clean => remove files from buildrootdir; | ||
%clean | %clean | ||
- | rm -rf $RPM_BUILD_ROOT | + | rm -rf %{buildroot} |
- | # Set directory and file attributes on same line as which files to include | + | # files => set file permissions, |
%files | %files | ||
- | %attr(755, root, users) %dir / | + | %attr(755, root, root) / |
- | %attr(750, root, users) / | + | |
- | # Changelog notes => Format of date and summary lines important. | + | # changelog |
%changelog | %changelog | ||
* Thu Oct 22 2015 Robert Jones < | * Thu Oct 22 2015 Robert Jones < | ||
- | - Initial custom scripts | + | - Initial custom scripts |
</ | </ | ||
Line 365: | Line 369: | ||
RPM Build Command | RPM Build Command | ||
<code bash> | <code bash> | ||
- | rpmbuild -ba / | + | rpmbuild -ba ~/ |
</ | </ | ||
Line 413: | Line 417: | ||
====== Mock to Test Dependencies ====== | ====== Mock to Test Dependencies ====== | ||
+ | * **More Details**: [[https:// | ||
+ | |||
+ | \\ | ||
Mock is used to rebuild binary RPMs from source RPMs in a clean environment to ensure you are not missing any dependencies in your SPEC file. | Mock is used to rebuild binary RPMs from source RPMs in a clean environment to ensure you are not missing any dependencies in your SPEC file. | ||
+ | \\ | ||
Install mock | Install mock | ||
- | <code bash>yum install mock</ | + | <code bash> |
+ | yum install mock | ||
+ | </ | ||
+ | \\ | ||
Add user to the mock group | Add user to the mock group | ||
- | <code bash> | + | <code bash> |
+ | usermod -a -G mock builder | ||
+ | </ | ||
- | **TODO** | + | \\ |
+ | Set default mock config of the type of repos you are building for (ie EPEL 6, Fedora 23, etc) | ||
+ | |||
+ | Example: Set default config to EPEL 6 x86_64 | ||
+ | <code bash> | ||
+ | cd /etc/mock | ||
+ | ln -sf epel-6-x86_64.cfg default.cfg | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | Go to where your source RPMs were built and run mock against that package | ||
+ | <code bash> | ||
+ | cd ~/ | ||
+ | mock --rebuild myscripts-1.0.0-1.el6.src.rpm | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | Results location is displayed (/ | ||
+ | <code bash> | ||
+ | ls -l / | ||
+ | total 172 | ||
+ | -rw-rw-r-- 1 builder mock 4500 Oct 16 07:32 build.log | ||
+ | -rw-rw-r-- 1 builder mock 2740 Oct 16 07:32 myscripts-1.0.0-1.el6.src.rpm | ||
+ | -rw-rw-r-- 1 builder mock 2524 Oct 16 07:32 myscripts-1.0.0-1.el6.x86_64.rpm | ||
+ | -rw-rw-r-- 1 builder mock 153606 Oct 16 07:32 root.log | ||
+ | -rw-rw-r-- 1 builder mock 782 Oct 16 07:32 state.log | ||
+ | </ | ||
---- | ---- |