自己制作Linux RPM套件实验
按鸟哥私房菜中的教程制作,很小的一过程,搞来搞去,花费了近一个上午的时间……
最后,还是没有完全成功!自己学还真是很难搞~~
1,生成showvbird.sh,在目录/usr/src/redhat/SOURCES下
[root@localhost ~]# cd /usr/src
[root@localhost src]# ll
total 0
[root@localhost src]# vi showvbird.sh
#!/bin/bash
# This file is just used to demo the RPM packaging.
# the only thing is showing the hostname.
HOST=`/bin/hostname`
/bin/echo $HOST
[root@localhost src]# mv showvbird.sh /usr/src/redhat/SOURCES
mv: cannot move `showvbird.sh' to `/usr/src/redhat/SOURCES': No such file or directory
[root@localhost src]# mkdir -p /usr/src/redhat/SOURCES
[root@localhost src]# mv showvbird.sh /usr/src/redhat/SOURCES
[root@localhost src]# cd redhat/SOURCES/
[root@localhost SOURCES]# ll
total 8
-rw-r--r-- 1 root root 150 Apr 26 18:37 showvbird.sh
[root@localhost SOURCES]# chmod 755 showvbird.sh
[root@localhost SOURCES]# ll
total 8
-rwxr-xr-x 1 root root 150 Apr 26 18:37 showvbird.sh
[root@localhost SOURCES]# tar -zcvf showvbird.tar.gz showvbird.sh
showvbird.sh
[root@localhost SOURCES]# ll
total 16
-rwxr-xr-x 1 root root 150 Apr 26 18:37 showvbird.sh
-rw-r--r-- 1 root root 236 Apr 26 18:40 showvbird.tar.gz
2,生成showvbird.spec,在目录/usr/src/redhat/SPECS下
[root@localhost SOURCES]# cd /usr/src/redhat/SPECS
bash: cd: /usr/src/redhat/SPECS: No such file or directory
[root@localhost SOURCES]# mkdir -p /usr/src/redhat/SPECS
[root@localhost SOURCES]# cd /usr/src/redhat/SPECS
[root@localhost SPECS]# vi showvbird.spec
Summary: This is a demo RPM package.
Name: showvbird
Version: 1.0
Release: 1
Copyright: GPL
Group: VBird's Home
Source: showvbird.tar.gz <==这个就是刚刚建立起来的Tarball档案!
Url:
Packager: VBird
%description
This package is just a demo RPM.
%prep
%setup –c
%install
install -m 755 showvbird.sh /usr/local/bin/showvbird.sh
%files
/usr/local/bin/showvbird.sh
[root@localhost SPECS]# ll
total 8
-rw-r--r-- 1 root root 447 Apr 26 18:43 showvbird.spec
3,编译并打包成为RPM档案啦
[root@localhost SPECS]# rpmbuild -bb showvbird.spec
bash: rpmbuild: command not found
-->出问题了,找不到rpmbuild命令file……
--查询得知:这个命令要安装rpm-build*.rpm包……而此rpm包在安装盘里可以找到。
--又是rpm包……安装吧,这一安装又出麻烦了……
--还好最后万幸,成功了,详细见:
RPM套件rpm-build安装出错一例:NOKEY、elfutils is needed
--重新编译……
[root@localhost SPECS]# rpmbuild -bb showvbird.spec
error: Legacy syntax is unsupported: copyright
error: line 5: Unknown tag: Copyright: GPL
--又报错
--删除第5行:Copyright: GPL 重新编译
[root@localhost SPECS]# rpmbuild -bb showvbird.spec
error: License field must be present in package: (main package)
--终于找到一篇文档:
((終於找到"Unknown tag: Copyright: GPL"解決的方法了!!
在redhat官網看到一篇討論,
-----------------------------------------------------------------------------
The tag is deprecated for a long time already. You could have used
the "License:" tag much (!) earlier already.
-----------------------------------------------------------------------------
需要將"Copyright:"該改成新的Tag"License:"
後來測試卡到的Error就Pass過了~~
))
--修改文件,将“Copyright:”改为“License:”,重新编译
[root@localhost SPECS]# rpmbuild -bs showvbird.spec
Wrote: /usr/src/redhat/SRPMS/showvbird-1.0-1.src.rpm
--OK,大功告成……
[root@localhost SPECS]# cd /usr/src/redhat
[root@localhost redhat]# ll
total 40
drwxr-xr-x 2 root root 4096 Jan 4 2007 BUILD
drwxr-xr-x 8 root root 4096 Apr 26 19:55 RPMS
drwxr-xr-x 2 root root 4096 Jan 4 2007 SOURCES
drwxr-xr-x 2 root root 4096 Apr 26 21:13 SPECS
drwxr-xr-x 2 root root 4096 Apr 26 21:13 SRPMS
[root@localhost redhat]# ll ./BUILD/
total 0
[root@localhost redhat]# ll ./SRPMS/
total 8
-rw-r--r-- 1 root root 2083 Apr 26 21:13 showvbird-1.0-1.src.rpm
[root@localhost redhat]# rpm -ivh /usr/src/redhat/SRPMS/showvbird-1.0-1.src.rpm
1:showvbird ########################################### [100%]
[root@localhost redhat]# rpm -qi showvbird
package showvbird is not installed
[root@localhost redhat]# rpm -qi showvbird
package showvbird is not installed
[root@localhost redhat]# rpm --rebuilddb
[root@localhost redhat]# rpm -qi showvbird
package showvbird is not installed
--很奇怪,竟然说没有安装……
--进入到rpm包目录中安装
[root@localhost redhat]# cd /usr/src/redhat/SRPMS
[root@localhost SRPMS]# ll
total 8
-rw-r--r-- 1 root root 2083 Apr 26 21:13 showvbird-1.0-1.src.rpm
[root@localhost SRPMS]# rpm -ivh showvbird-1.0-1.src.rpm
1:showvbird ########################################### [100%]
[root@localhost SRPMS]# rpm -ql showvbird
package showvbird is not installed
[root@localhost SRPMS]#
--还是没有安装……
13:08 2010-04-27
求助:
PS:终于找到问题了。
--原来我上面安装的都是srpm包,当然没有安装成功了……但找rpm包时,竟然没有。
--终于发现,原来问题出来在我编译的那句:rpmbuild -bs showvbird.spec
就是那个-bs参数,这个是我自作聪明改的……
-bb build binary package only from
-bs build source package only from
可以看出,这个只生成srpm……真是失败……
--找到问题就好说了,重新编译一下
[root@localhost SPECS]# rpmbuild -bb showvbird.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.49023
+ umask 022
+ cd /usr/src/redhat/BUILD
+ cd /usr/src/redhat/BUILD
+ rm -rf showvbird-1.0
+ tar -xvvf -
+ /bin/gzip -dc /usr/src/redhat/SOURCES/showvbird.tar.gz
-rwxr-xr-x root/root 150 2010-04-26 18:37:09 showvbird.sh
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ cd showvbird-1.0
/var/tmp/rpm-tmp.49023: line 28: cd: showvbird-1.0: No such file or directory
error: Bad exit status from /var/tmp/rpm-tmp.49023 (%prep)
RPM build errors:
Bad exit status from /var/tmp/rpm-tmp.49023 (%prep)
[root@localhost SPECS]#
--查看错误文件 /var/tmp/rpm-tmp.49023
[root@localhost SPECS]# ll /var/tmp/rpm-tmp.49023
-rw-r--r-- 1 root root 839 Apr 26 22:34 /var/tmp/rpm-tmp.49023
[root@localhost SPECS]# vi /var/tmp/rpm-tmp.49023
--内容如下:
(((
#!/bin/sh
RPM_SOURCE_DIR="/usr/src/redhat/SOURCES"
RPM_BUILD_DIR="/usr/src/redhat/BUILD"
RPM_OPT_FLAGS="-O2 -g -march=i386 -mcpu=i686"
RPM_ARCH="i386"
RPM_OS="linux"
export RPM_SOURCE_DIR RPM_BUILD_DIR RPM_OPT_FLAGS RPM_ARCH RPM_OS
RPM_DOC_DIR="/usr/share/doc"
export RPM_DOC_DIR
RPM_PACKAGE_NAME="showvbird"
RPM_PACKAGE_VERSION="1.0"
RPM_PACKAGE_RELEASE="1"
export RPM_PACKAGE_NAME RPM_PACKAGE_VERSION RPM_PACKAGE_RELEASE
set -x
umask 022
cd /usr/src/redhat/BUILD
cd /usr/src/redhat/BUILD
rm -rf showvbird-1.0
/bin/gzip -dc /usr/src/redhat/SOURCES/showvbird.tar.gz | tar -xvvf -
STATUS=$?
if [ $STATUS -ne 0 ]; then
exit $STATUS
fi
cd showvbird-1.0
[ `/usr/bin/id -u` = '0' ] && /bin/chown -Rhf root .
[ `/usr/bin/id -u` = '0' ] && /bin/chgrp -Rhf root .
/bin/chmod -Rf a+rX,u+w,g-w,o-w .
exit 0
)))
由于shell部分还未修炼,这部分还看不懂,待解决……
13:51 2010-04-27