There are many methods for creating packages available on the web, but many of them are obsolete and often don't allow for simple implementation. That's why I'll show you a technique to build a package in 5 minutes.
Installation
We'll install the necessary tools for package creation:
Let's say I want to package a Ruby library that I installed via gems. Everything is installed in specific directories, so I'll create an archive containing what I need:
For this script, I'm using a script that I found on this site, which automatically creates a .spec file with the main information. Adapt the beginning with your desired information:
#!/bin/bash# This script creates an RPM from a tar file.# $1 : tar fileNAME=$(echo${1%%-*}|sed's/^.*\///')VERSION=$(echo${1##*-}|sed's/[^0-9]*$//')RELEASE=0VENDOR="Deimos"EMAIL="<xxx@mycompany.com>"SUMMARY="Summary"LICENSE="GPL"GROUP="System"ARCH="noarch"DESCRIPTION="My description"####################################################### users should not change the script below this line.######################################################## This function prints the usage help and exits the program.usage(){/bin/cat<< USAGEThis script has been released under BSD license. Copyright (C) 2010 Reiner Rottmann <rei..rATrottmann.it>$0 creates a simple RPM spec file from the contents of a tarball. The output may be used as starting point to create more complex RPM spec files.The contents of the tarball should reflect the final directory structure where you want your files to be deployed. As the name and version get parsedfrom the tarball filename, it has to follow the naming convention "<name>-<ver.si.on>.tar.gz". The name may only contain characters from the range[A-Z] and [a-z]. The version string may only include numbers seperated by dots.Usage: $0 [TARBALL]Example: $ $0 sample-1.0.0.tar.gz $ /usr/bin/rpmbuild -ba /tmp/sample-1.0.0.specUSAGEexit1}ifecho"${1##*/}"|sed's/[^0-9]*$//'|/bin/grep-q'^[a-zA-Z]\+-[0-9.]\+$';thenif/usr/bin/file-ib"$1"|/bin/grep-q"application/x-gzip";thenecho"INFO: Valid input file '$1' detected."elseusage
fielseusage
fiOUTPUT=/tmp/${NAME}-${VERSION}.spec
FILES=$(/bin/tar-tzf$1|/bin/grep-v'^.*/$'|sed's/^/\//')/bin/cat>$OUTPUT<< EOFName: $NAMEVersion: $VERSIONRelease: $RELEASEVendor: $VENDORSummary: $SUMMARYLicense: $LICENSEGroup: $GROUPSource0: %{name}-%{version}.tar.gzBuildRoot: /var/tmp/%{name}-buildrootBuildArch: $ARCH%description$DESCRIPTION%prep%setup -c -n %{name}-%{version}%build%install[ -d \${RPM_BUILD_ROOT} ] && rm -rf \${RPM_BUILD_ROOT}/bin/mkdir -p \${RPM_BUILD_ROOT}/bin/cp -axv \${RPM_BUILD_DIR}/%{name}-%{version}/* \${RPM_BUILD_ROOT}/%post%postun%clean%files%defattr(-,root,root)$FILES%define date %(echo \`LC_ALL="C" date +"% a % b % d % Y"\`)%changelog* %{date} User $EMAIL- first VersionEOFecho"INFO: Spec file has been saved as '$OUTPUT':"echo"---------%<----------------------------------------------------------------------"/bin/cat$OUTPUTecho"---------%<----------------------------------------------------------------------"