1)rpmbuild
1@@@@
@@@install the rpmbuild program from the iso.
@@@create the directory
[root@station117 rpmbuild]# pwd
/root/rpmbuild
[root@station117 rpmbuild]# ls -ld *
drwxr-xr-x. 3 root root 4096 Apr 18 11:53 BUILD
drwxr-xr-x. 2 root root 4096 Apr 18 11:53 BUILDROOT
drwxr-xr-x. 3 root root 4096 Apr 18 11:53 RPMS
drwxr-xr-x. 3 root root 4096 Apr 18 11:47 SOURCES
drwxr-xr-x. 2 root root 4096 Apr 18 11:53 SPECS
drwxr-xr-x. 2 root root 4096 Apr 18 11:53 SRPMS

@@@
@@@create a little program to test your rpm package.
[root@station117 bin]# ls /root/rpmbuild/SOURCES/majesty-1/usr/bin
program01.sh
[root@station117 bin]# cat program01.sh
#!/bin/sh
echo $RANDOM

@@@
@@@make a tar package , before you make the rpm package
@@@as the below:
[root@station117 bin]# cd /root/rpmbuild/SOURCES
[root@station117 SOURCES]# tar -zcvf majesty2012-04-18.tgz majesty-1
majesty-1/
majesty-1/usr/
majesty-1/usr/bin/
majesty-1/usr/bin/program01.sh
[root@station117 SOURCES]# ls /root/rpmbuild/SOURCES/majesty-2012-04-18.tgz
/root/rpmbuild/SOURCES/majesty-2012-04-18.tgz

@@@
@@@create the xxx.spec file. play attention to the filename.
@@@it must match the "Source0"
[root@station117 SOURCES]# cd /root/rpmbuild/SPECS
[root@station117 SOURCES]# vim majesty-2012-04-18.spec
####begin###############################################
[root@station117 SPECS]# cat /root/rpmbuild/SPECS/majesty-2012-04-18.spec
Name:           majesty
Version:        1
Release:        2.3.4
Summary:        this is a good program.
Group:          Base
License:        GPLv2
URL:            http://www.baidu.com
Source0:        majesty-2012-04-18.tgz
#BuildRoot:   %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}.x86_64)

%description
a new rpm packages here.

%prep
%setup -q

%build
echo "OK"

%install
mkdir -p /root/rpmbuild/BUILDROOT/majesty-1-2.3.4.x86_64
tar -C /root/rpmbuild/BUILDROOT/majesty-1-2.3.4.x86_64 -zxvf /root/rpmbuild/SOURCES/majesty-2012-04-18.tgz
mv /root/rpmbuild/BUILDROOT/majesty-1-2.3.4.x86_64/majesty-1/* /root/rpmbuild/BUILDROOT/majesty-1-2.3.4.x86_64/

%clean
rm -rf $RPM_BUILD_ROOT

%files
/*

%changelog
* Mon Mar 29 2010 Dennis Gregorovic <dgregor@redhat.com> - 6-6.0.0.24
- Version 1.0
######end######################################################
@@@Note:
@@@it is a easy sample, it is different from xxx.tar.gz.
@@@rpm could trace all file which you install use this rpm package.
@@@there is a rpm database, as the below:
[root@station78 ~]# rpm -qc rpm-4.8.0-19.el6.x86_64
....................
/var/lib/rpm/__db.001
/var/lib/rpm/__db.002
/var/lib/rpm/__db.003
/var/lib/rpm/__db.004
/var/lib/rpm/__db.005
/var/lib/rpm/__db.006
/var/lib/rpm/__db.007
/var/lib/rpm/__db.008
/var/lib/rpm/__db.009

@@@
@@@prepare all files, then create the rpm packages
@@@as the below:
[root@station117 SPECS]# rpmbuild -ba majesty-2012-04-18.spec
mktemp: too few X's in template `/var/tmp/majesty-1-2.3.4-xxxx'
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.cli05c
+..........
.............
..................
+ cd /root/rpmbuild/BUILD
+ cd majesty-1
+ rm -rf /root/rpmbuild/BUILDROOT/majesty-1-2.3.4.x86_64
+ exit 0

@@@
@@@rpm package was generated in the directory "/root/rpmbuild/RPMS/x86_64"
@@@different platform has different name which like "x86_64/i686/i386".
[root@station117 x86_64]# ls /root/rpmbuild/RPMS/x86_64/majesty-1-2.3.4.x86_64.rpm
/root/rpmbuild/RPMS/x86_64/majesty-1-2.3.4.x86_64.rpm

@@@
@@@install the rpm packages.
[root@station117 x86_64]# rpm -ivh majesty-1-2.3.4.x86_64.rpm
Preparing...                ########################################### [100%]
   1:majesty                ########################################### [100%]


2@@@@install the yum for this rpm package
@@@install the "createrepo" to create xml relative files automatically.
[root@station117 MyPackages]# yum list createrepo*
Installed Packages
createrepo.noarch                      0.9.8-4.el6    
[root@station117 x86_64]# cp majesty-1-2.3.4.x86_64.rpm /var/ftp/pub/MyPackages/
[root@station117 MyPackages]# createrepo -v /var/ftp/pub/MyPackages/
1/1 - majesty-1-2.3.4.x86_64.rpm

Saving Primary metadata
Saving file lists metadata
Saving other metadata

@@@
@@@write a yum file point to that directory, as the below:
[root@station117 MyPackages]# cat /etc/yum.repos.d/base.repo
[mypackage]
name=mypackage
baseurl=file:/var/ftp/pub/MyPackages
gpgcheck=0


@@@
[root@station117 MyPackages]# yum -y install majesty*
.......
....
Running Transaction
  Installing : majesty-1-2.3.4.x86_64                                       1/1
Installed products updated.

Installed:
  majesty.x86_64 0:1-2.3.4                                                     
Complete!

@@@
[root@station117 MyPackages]# yum list majesty
Installed Packages
majesty.x86_64                         1-2.3.4 


3@@@@check
[root@station117 MyPackages]# which program01.sh
/usr/bin/program01.sh
[root@station117 MyPackages]# rpm -qi majesty
Name        : majesty                      Relocations: (not relocatable)
Version     : 1                                 Vendor: (none)
Release     : 2.3.4                         Build Date: Wed 18 Apr 2012 12:15:35 PM GMT
Install Date: Wed 18 Apr 2012 12:27:51 PM GMT      Build Host: station117.example.com
Group       : Base                          Source RPM: majesty-1-2.3.4.src.rpm
Size        : 23                               License: GPLv2
Signature   : (none)
URL         : http://www.baidu.com
Summary     : this is a good program.
Description :
a new rpm packages here.

@@@
[root@station117 MyPackages]# rpm -ql majesty-1-2.3.4.x86_64
/majesty-1
/usr
/usr/bin
/usr/bin/program01.sh
[root@station117 MyPackages]# rpm -qa | grep majesty
majesty-1-2.3.4.x86_64
[root@station117 MyPackages]# rpm -e majesty
[root@station117 MyPackages]# whereis program01.sh
program01:

 

2)gpg for rpm
1@@@@generate the key for encrypt
[root@station117 rpm-gpg]# gpg --gen-key
gpg (GnuPG) 2.0.14; Copyright (C) 2009 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Please select what kind of key you want:
   (1) RSA and RSA (default)
   (2) DSA and Elgamal
   (3) DSA (sign only)
   (4) RSA (sign only)
Your selection? 3
DSA keys may be between 1024 and 3072 bits long.
What keysize do you want? (2048) 1024
Requested keysize is 1024 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0)
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: sky
Name must be at least 5 characters long
Real name: bluesky
Email address: xxx@qq.com
Comment: passwd is bulesky
You selected this USER-ID:
    "bluesky (passwd is bulesky) <xxx@qq.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
You need a Passphrase to protect your secret key.

can't connect to `/root/.gnupg/S.gpg-agent': Connection refused
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.

 

2@@@@sign the packages
[root@station117 Desktop]# gpg --list-keys
/root/.gnupg/pubring.gpg
------------------------
pub   1024D/0F510DBB 2012-04-16
uid                  pander (pander is here.) <xxx@pander.com>
sub   1024g/36FAF638 2012-04-16

@@@
[root@station117 ~]# cat .rpmmacros
%_gpg_name 0F510DBB

@@@
[root@station117 MyPackages]# rpm --resign majesty-1-2.3.4.x86_64.rpm
Enter pass phrase:
Pass phrase is good.
majesty-1-2.3.4.x86_64.rpm:

@@@
@@@generate the PRM-GPG-KEY using the public-key and import your rpm db.
[root@station117 rpm-gpg]# gpg -a -o /etc/pki/rpm-gpg/RPM-GPG-KEY-mypackages --export 0F510DBB
[root@station117 rpm-gpg]# ls /etc/pki/rpm-gpg/RPM-GPG-KEY-mypackages
/etc/pki/rpm-gpg/RPM-GPG-KEY-mypackages
[root@station117 rpm-gpg]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-mypackages

@@@
[root@station117 MyPackages]# yum clean all
[root@station117 MyPackages]# yum -y install majesty*
Installed:
  majesty.x86_64 0:1-2.3.4                                             
Complete!


@@@Note: without your  RPM-GPG-KEY-mypackages key, the rpm package is disabled.!!!!