20160803 소프트웨어 관리
4 | Create an RPM |
rpm 패키지 생성 절차
(ㄱ) 소스 프로그램 개발
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트
① 간단한 프로그램 개발
rpm 패키지 생성 절차
(ㄱ) 소스 프로그램 개발
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트
# mkdir -p /test/hello-1.0
# cd /test
# vi hello-1.0/hello.sh
#!/bin/bash
echo 'This is a test.' echo
echo ' ________________________' echo '/ \' echo '| |' echo '| 야 !! 공부좀 해라!!! |' echo '| |' echo '\________________________/' echo ' \' echo ' \' echo ' (__)' echo ' (oo)______' echo ' (__) )\' echo ' ||---|| *' echo ' || ||' echo
|
② tar.gz 파일 생성
rpm 패키지 생성 절차
(ㄱ) 소스 프로그램 개발
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트
(필요하면 명령어 수행)
# ls /usr/src/redhat
ls: /usr/src/redhat: No such file or directory
# yum -y install rpm-build
# ls /usr/src/redhat
BUILD/ RPMS/ SOURCES/ SPECS/ SRPMS/ |
# tar cvzf /usr/src/redhat/SOURCES/hello-1.0-1.tar.gz hello-1.0
# tar tvzf /usr/src/redhat/SOURCES/hello-1.0-1.tar.gz
drwxr-xr-x root/root 0 2014-01-23 16:16:24 hello-1.0/ -rwxr-xr-x root/root 394 2014-01-23 16:16:24 hello-1.0/hello.sh |
③ SPEC 파일 생성
rpm 패키지 생성 절차
(ㄱ) 소스 프로그램 개발
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트
# vi /usr/src/redhat/SPECS/hello.spec
%define name hello %define version 1.0 %define release 1
Name: hello Version: 1.0 Release: 1 Summary: Hello Group: CentOS License: GPL URL: http://www.example.com Source0: %{name}-%{version}-%{release}.tar.gz BuildRoot: /var/tmp/%{name}-buildroot
%description Installs /root/bin/hello.sh
%prep %setup -q -n %{name}-%{version}
%build
%install rm -rf $RPM_BUILD_ROOT mkdir -p $RPM_BUILD_ROOT/root/bin install -m 755 hello.sh $RPM_BUILD_ROOT/root/bin/hello.sh
%clean rm -rf $RPM_BUILD_ROOT
%files %defattr(-,root,root,-) /root/bin/hello.sh
%changelog |
④ rpm build
rpm 패키지 생성 절차
(ㄱ) 소스 프로그램 개발
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트
# yum -y install rpm-build
-> rpm-build 패키지 설치
# rpmbuild -ba /usr/src/redhat/SPECS/hello.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.38857 + umask 022 + cd /usr/src/redhat/BUILD + cd /usr/src/redhat/BUILD + rm -rf hello-1.0 + /bin/gzip -dc /usr/src/redhat/SOURCES/hello-1.0-1.tar.gz + tar -xf - + STATUS=0 + '[' 0 -ne 0 ']' + cd hello-1.0 ++ /usr/bin/id -u + '[' 0 = 0 ']' + /bin/chown -Rhf root . ++ /usr/bin/id -u + '[' 0 = 0 ']' + /bin/chgrp -Rhf root . + /bin/chmod -Rf a+rX,u+w,g-w,o-w . + exit 0 Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.38857 + umask 022 + cd /usr/src/redhat/BUILD + cd hello-1.0 + exit 0 Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.38857 + umask 022 + cd /usr/src/redhat/BUILD + cd hello-1.0 + rm -rf /var/tmp/hello-buildroot + mkdir -p /var/tmp/hello-buildroot/root/bin + install -m 755 hello.sh /var/tmp/hello-buildroot/root/bin/hello.sh + /usr/lib/rpm/brp-compress + /usr/lib/rpm/brp-strip + /usr/lib/rpm/brp-strip-static-archive + /usr/lib/rpm/brp-strip-comment-note Processing files: hello-1.0-1 Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1 Requires: /bin/bash Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/hello-buildroot Wrote: /usr/src/redhat/SRPMS/hello-1.0-1.src.rpm Wrote: /usr/src/redhat/RPMS/i386/hello-1.0-1.i386.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.38857 + umask 022 + cd /usr/src/redhat/BUILD + cd hello-1.0 + rm -rf /var/tmp/hello-buildroot + exit 0 |
# find /usr/src/redhat
/usr/src/redhat /usr/src/redhat/RPMS /usr/src/redhat/RPMS/geode /usr/src/redhat/RPMS/noarch /usr/src/redhat/RPMS/i386 /usr/src/redhat/RPMS/i386/hello-1.0-1.i386.rpm /usr/src/redhat/RPMS/i686 /usr/src/redhat/RPMS/athlon /usr/src/redhat/RPMS/i486 /usr/src/redhat/RPMS/i586 /usr/src/redhat/SOURCES /usr/src/redhat/SOURCES/hello-1.0-1.tar.gz /usr/src/redhat/SPECS /usr/src/redhat/SPECS/hello.spec /usr/src/redhat/SRPMS /usr/src/redhat/SRPMS/hello-1.0-1.src.rpm /usr/src/redhat/BUILD /usr/src/redhat/BUILD/hello-1.0 /usr/src/redhat/BUILD/hello-1.0/hello.sh |
⑤ 생성된 패키지 설치 및 삭제(테스트용)
# cd /usr/src/redhat/RPMS/i386
# rpm -Uvh hello-1.0-1.i386.rpm
Preparing... ########################################### [100%] 1:hello ########################################### [100%] |
# rpm -e hello
# rpm -qa | grep hello
#
⑥ GPG Key 생성과 패키지 sign
rpm 패키지 생성 절차
(ㄱ) 소스 프로그램 개발
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트
# cd
# gpg --gen-key
gpg (GnuPG) 1.4.5; Copyright (C) 2006 Free Software Foundation, Inc. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the file COPYING for details.
gpg: directory `/root/.gnupg' created gpg: new configuration file `/root/.gnupg/gpg.conf' created gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run gpg: keyring `/root/.gnupg/secring.gpg' created gpg: keyring `/root/.gnupg/pubring.gpg' created Please select what kind of key you want: (1) DSA and Elgamal (default) (2) DSA (sign only) (5) RSA (sign only) Your selection? <ENTER> DSA keypair will have 1024 bits. ELG-E keys may be between 1024 and 4096 bits long. What keysize do you want? (2048) <ENTER> 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) <ENTER> Key does not expire at all Is this correct? (y/N) y
You need a user ID to identify your key; the software constructs the user ID from the Real Name, Comment and Email Address in this form: "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
Real name: Baik, SeoungChan Email address: jang4sc@hanmail.net Comment: <ENTER> You selected this USER-ID: "Baik, SeoungChan <jang4sc@hanmail.net>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o You need a Passphrase to protect your secret key.
Passphrase: testing123 Repeat passphrase: testing123 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. ++++++++++..++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.++++++++++++++++++++.+++++++++++++++.+++++.+++++..++++++++++..>+++++.....................................................+++++
Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 283 more bytes) 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. .+++++++++++++++++++++++++.++++++++++.+++++.++++++++++......+++++++++++++++..+++++++++++++++..+++++.+++++++++++++++.+++++++++++++++++++++++++.+++++.++++++++++.+++++>.+++++.+++++...>+++++..................................................................................+++++^^^ gpg: /root/.gnupg/trustdb.gpg: trustdb created gpg: key ACD89B3E marked as ultimately trusted public and secret key created and signed.
gpg: checking the trustdb gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u pub 1024D/ACD89B3E 2014-01-23 Key fingerprint = 98A1 E2A6 AE47 FE97 BFE8 6DC4 BCAB 0ADE ACD8 9B3E uid Baik, SeoungChan <jang4sc@hanmail.net> sub 2048g/CA2DE316 2014-01-23 |
-> Key ID 확인: ACD89B3E
⑦ ~/RPM-GPG-KEY-test 파일 생성
rpm 패키지 생성 절차
(ㄱ) 소스 프로그램 개발
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트
# gpg -a -o ~/RPM-GPG-KEY-test --export ACD89B3E
# ls RPM*
RPM-GPG-KEY-test |
# cat RPM-GPG-KEY-test
-----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v1.4.5 (GNU/Linux)
mQGiBFLgyxARBACCnrOlR6uregf1SuoqqHxtBXGVq5QKyJVBsb4cXufe0ur5jzk8 Bmc9aKFMnfrp22GZ+CjfBr0BBYCB2A7ANsKtdwNzB2PHl7C9BNQafS8xrpyTo/2C oc0j21uLJz5TOpcaQ/1qS/jpUNumvDuoD9RXO6fgPhBNaj808cncp6uQ8wCg3gxc J4bqvc+QjdTXbrcIuMwDIT0D/A++D26YIp0TpzVDmv7Di2GTc4mn6fpKKSLu7vV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HB+DhFRPgR6U9l gFGVQuI6UP4G+3MSNoMEJIuVq0R1r9unytL+ojdyfLisgC2Xja3Z6lZZ67I0RiLr ZpFuAcROxgtcNsCHmle0DI3Bv9pBCJ8nudeSHahQsohJBBgRAgAJBQJS4MsUAhsM AAoJELyrCt6s2Js+oLoAoLVRgzLFoBmYiZXKIexIHhbrlRRIAKCaOHPRd4+88L1J WVbsdJED3F7cAQ== =lq3h -----END PGP PUBLIC KEY BLOCK----- |
⑧ ~/.rpmmacros 파일 생성
# vi ~/.rpmmacros
%_gpg_name ACD89B3E |
⑨ 패키지 sign
# rpm --resign /usr/src/redhat/RPMS/i386/hello-1.0-1.i386.rpm
Enter pass phrase: testing123 Pass phrase is good. /usr/src/redhat/RPMS/i386/hello-1.0-1.i386.rpm: gpg: WARNING: standard input reopened gpg: WARNING: standard input reopened |
⑩ 배포 서버 구성(YUM Repository)
rpm 패키지 생성 절차
(ㄱ) 소스 프로그램 개발
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트
# mkdir /var/www/html/packages
# cp /usr/src/redhat/RPMS/i386/hello*.rpm /var/www/html/packages
# cp RPM-GPG-KEY-test /var/www/html/packages
# yum -y install createrepo
# createrepo /var/www/html/packages
1/1 - hello-1.0-1.i386.rpm
Saving Primary metadata Saving file lists metadata Saving other metadata |
# service httpd start
⑪ hello.repo 파일 생성
rpm 패키지 생성 절차
(ㄱ) 소스 프로그램 개발
(ㄴ) 소스.tar.gz 파일 생성
(ㄷ) SPEC 파일 생성
(ㄹ) rpm build
(ㅁ) GPG Key 생성
(ㅂ) 패키지 sign
(ㅅ) Yum Repository 구성
(ㅇ) 테스트
# vi /etc/yum.repos.d/hello.repo
[hello] name=hello description=Test Yum Repository baseurl=http://172.16.9.252/packages enabled=1 gpgcheck=1 gpgkey=http://172.16.9.252/packages/RPM-GPG-KEY-test |
⑫ 설치 확인
# yum -y install hello
Loaded plugins: fastestmirror, security Loading mirror speeds from cached hostfile * base: mirror.oasis.onnetcorp.com * extras: mirror.oasis.onnetcorp.com * updates: mirror.oasis.onnetcorp.com hello | 951 B 00:00 hello/primary | 668 B 00:00 hello 1/1 Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package hello.i386 0:1.0-1 set to be updated --> Finished Dependency Resolution
Dependencies Resolved
============================================================================= Package Arch Version Repository Size ============================================================================= Installing: hello i386 1.0-1 hello 2.2 k
Transaction Summary ============================================================================= Install 1 Package(s) Upgrade 0 Package(s)
Total download size: 2.2 k Downloading Packages: hello-1.0-1.i386.rpm | 2.2 kB 00:00 warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID c1d1124a hello/gpgkey | 1.6 kB 00:00 Importing GPG key 0xC1D1124A "baik,seoungchan <jang4sc@hanmail.net>" from http://172.16.10.249/packages/RPM-GPG-KEY-test Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing : hello 1/1
Installed: hello.i386 0:1.0-1
Complete! |
# hello.sh
This is a test.
________________________ / \ | | | 야 !! 공부좀 해라!!! | | | \________________________/ \ \ (__) (oo)______ (__) )\ ||---|| * || ||
|
(복원) hello.repo 파일 복원
# cd /etc/yum.repos.d
# vi hello.repo
[hello] name=hello description=Test Yum Repository baseurl=http://172.16.9.252/packages enabled=0 gpgcheck=1 gpgkey=http://172.16.9.252/packages/RPM-GPG-KEY-test |
'모의해킹 침해대응 전문가 과정' 카테고리의 다른 글
| 20160804 SELinux (0) | 2016.08.04 |
|---|---|
| 20160803 SELinux (0) | 2016.08.03 |
| 20160802 웹 방화벽 (0) | 2016.08.02 |
| 20160802 Snort (0) | 2016.08.02 |
| 20160801 IDS (0) | 2016.08.01 |
