Advertisement
Guest User

Untitled

a guest
Jun 13th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 76.53 KB | None | 0 0
  1. Task 1
  2. RPM CREATION
  3. Set up non-root RPM build environment
  4. Rebuild a binary package from a src.rpm
  5. This lab will primarily be done while logged in as a non-root user. Occasionally
  6. you will need root privileges. The lab will direct you to use the su command to
  7. become root when required. Start by logging in —or obtaining a shell as a non-
  8. root user.
  9.  
  10. 1. The creation of RPMs requires the use of several developer tools. These
  11. include both the standard development tools such as the GNU Compiler
  12. Collection, GNU make, and related packages, as well as specific RPM building
  13. 12-39tools. Verify that you have the following standard development tool packages
  14. installed:
  15. $ rpm -q gcc
  16. gcc-3.2.2-5
  17. • The exact version returned on this package and others will vary
  18. depending on what version of RHEL/FC or SLES/SL Linux you are
  19. $ rpm -q gcc-c++
  20. using. What matters is that the packages are installed, not the
  21. rpm-c++-3.2.2-5
  22. exact versions which are installed.
  23. $ rpm -q make
  24. make-3.79.1-17
  25. $ rpm -q bison
  26. bison-1.35-6
  27. $ rpm -q binutils
  28. binutils-2.13.90.0.18-9
  29. Note that a full development environment will have many more related
  30. packages installed as well. However, if the above packages are installed, it is a
  31. strong indication that the other needed packages are also installed.
  32. Now, verify that you have the proper RPM building utilities installed. On
  33. RHEL/FC the utilites are part of the rpm-build RPM package which can be
  34. optionally installed. On SLES/SL the utilties are part of the rpm package which
  35. is always installed. Run the following command only on RHEL/FC:
  36. [RHEL/FC]$ rpm -q rpm-build
  37. rpm-build-4.3.2-21
  38. Also determine which RPM version you have installed:
  39. $ rpm -q rpm
  40. rpm-4.3.2-21
  41. Different RPM versions support different features and are used differently, so it
  42. is important to determine which version of RPM is being used.
  43. 2. Remove any installed packages that will conflict with packages built manually in
  44. upcoming steps:
  45. [SLES/SL]# rpm -e ltris nmap lbreakout
  46. [RHEL/FC]# rpm -e nmap nmap-frontend
  47. 3. Out of the box on RHEL/FC, the system RPM build directory structure,
  48. /usr/src/redhat/, is only writable by the root user. On SLES/SL the RPM
  49. 12-40build directory structure is located at /usr/src/packages/ and is writable
  50. by everyone.
  51. The recommended practice is NOT to build RPMs as the root user, create a
  52. RPM build directory tree in your non-root user’s home directory for isolation
  53. from other users.
  54. Make sure your present working directory is your home directory, and then
  55. create the RPM build directory structure:
  56. $ cd
  57. $ mkdir -p rpmbuild/{SOURCES,SPECS,BUILD,SRPMS,RPMS}
  58. $ mkdir rpmbuild/RPMS/{i386,i586,i686}
  59. 4. When building RPMs using the rpmbuild command, the RPM software must
  60. locate the RPM build directory structure. To do this, it reads the value of the
  61. %_topdir RPM macro. The macro container files that macros are read from
  62. start with the RPM default /usr/lib/rpm/macros file, then the local system
  63. override file /etc/rpm/macros is consulted (if it exists), and finally, the per-
  64. user macro file is read, ~/.rpmmacros (if it exists). Any macro found in the
  65. per-user macro file will override the same macro in the local system override
  66. file, and any macro found in the local system override file will override macros
  67. from the RPM default file.
  68. Create a ~/.rpmmacros file and set the %_topdir RPM macro to point to • Red Hat Linux 9 and later RHEL/FC releases generate debuginfo
  69. packages by default. These debuginfo RPMs can be installed
  70. the directory structure you created in the previous step. Also, set the
  71. when installing an application to get more capability to debug
  72. %debug_package macro to turn off the automatic creation of the debuginfo
  73. the application. They are not typically necessary, and are often
  74. RPM.
  75. not desired, as they are quite large.
  76. Use your favorite text editor and create the file ~/.rpmmacros with the
  77. following contents:
  78. %_topdir
  79. %(echo $HOME)/rpmbuild
  80. %debug_package
  81. %{nil}
  82. • This %debug_package macro is only needed on systems with
  83. RPM 4.2 or newer.
  84. 5. Test your non-root RPM building environment by rebuilding a binary RPM from • This is something that is commonly done when obtaining RPMs
  85. off of the Internet. Unless you know for sure that an Internet
  86. an existing source RPM.
  87. binary RPM was built specifically against your version of Red Hat
  88. The LTris game is a popular Tetris clone. Verify that your RPM build
  89. Linux, it is preferable to download the src.rpm of the
  90. environment works by creating a binary LTris RPM from the source RPM:
  91. package and rebuild a binary RPM with the application linked
  92. $ rpmbuild --rebuild /labfiles/ltris-1.0.4-2.src.rpm
  93. against the exact versions of the libraries provided by your
  94. Installing /labfiles/ltris-1.0.4-2.src.rpm
  95. system, and not other, hopefully compatible libraries, or even
  96. library versions that are not on your system.
  97. Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.2652
  98. 12-41+ umask 022
  99. + cd /home/guru/rpmbuild/BUILD
  100. + LANG=C
  101. + export LANG
  102. + cd /home/guru/rpmbuild/BUILD
  103. + rm -rf ltris-1.0.4
  104. + /usr/bin/gzip -dc /home/guru/rpmbuild/SOURCES/ltris-
  105. 1.0.4.tar.gz
  106. + tar -xf -
  107. + STATUS=0
  108. ...Output Omitted...
  109. After a few minutes have elapsed, look for the Wrote: line near the end of the
  110. output:
  111. Requires: SDL >= 1.1.4 config(ltris) = 1.0.4-2 libSDL-1.2.so.0 libSDL_mixer-1.2.so.0 libc.so.6
  112. libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1) libc.so.6(GLIBC_2.1.3) libc.so.6(GLIBC_2.3) libm.so.6
  113. libpthread.so.0
  114. Checking for unpackaged file(s): /usr/lib/rpm/check-files
  115. /var/tmp/ltris-root
  116. Wrote: /home/guru/rpmbuild/RPMS/i386/ltris-1.0.4-2.i386.rpm • This is the line you are looking for.
  117. Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.9014
  118. + umask 022
  119. + cd /home/guru/rpmbuild/BUILD
  120. + cd ltris-1.0.4
  121. + rm -rf /var/tmp/ltris-root
  122. + exit 0
  123. 6. Install the binary RPM which was created in the previous step. The path to the
  124. binary RPM was displayed on the Wrote: line. Remember, you must switch to
  125. the root user to install binary RPMs to the system.
  126. $ su -
  127. Password:
  128. # rpm -Uvh /home/guru/rpmbuild/RPMS/i386/ltris-1.0.4-2.i386.rpm
  129. # exit
  130. $ ltris
  131. • Test the LTris program as a non-root user. You must be working
  132. in the GUI environment for this to work.
  133. 12-42Task 2
  134. Update an existing source RPM with the latest software version
  135. Linux distributions are a collection of software packages that have been tested
  136. and validated together. The Linux distributions are released periodically,
  137. typically on a 6 month interval, while the individual packages are developed
  138. independently and released on separate release schedules.
  139. Most Linux distribution vendors release updated packages only in two
  140. circumstances, to fix security vulnerabilities, and to fix major bugs that impact
  141. many people. In all other cases, Linux distribution vendors normally wait until
  142. the next version of their distribution to upgraded to any other updated versions.
  143. Sometimes there will be a newer version of a package available —with features
  144. that you need— than what came with the Linux distribution version you are
  145. using. However, this update does not meet the requirements to be released as
  146. an official update for the Linux distribution. In such circumstances, you can
  147. create your own RPM update for the application. This is desirable over just
  148. downloading, compiling and installing the package to /usr/local/ in a un-
  149. tracked state.
  150. 1. To update an RPM that shipped with your distribution, start by installing an
  151. existing source RPM, such as one provided with your distribution. The
  152. distribution source RPMs for Nmap have been placed in the /labfiles/
  153. directory.
  154. $ rpm -Uvh /labfiles/nmap-3.70-1.src.rpm
  155. warning: /labfiles/nmap-3.70-1.src.rpm: V3 DSA signature: NOKEY, key ID 4f2a6fd2
  156. 1:nmap
  157. ########################################### [100%]
  158. Note that this may not be the actual source RPM for for Nmap for your specific
  159. Linux distribution but for the sake of consistency in the lab, will be used as
  160. such.
  161. This places the pristine source and any patches for this package into the
  162. ~/rpmbuild/SOURCES/ directory, and the spec file for this package into the
  163. ~/rpmbuild/SPECS/ directory.
  164. 2. Copy the newer pristine tarball of Nmap source code into your
  165. ~/rpmbuild/SOURCES/ directory. The tarball has been placed in
  166. /labfiles/ for you.
  167. 12-43$ cp /labfiles/nmap-3.81.tar.bz2 ~/rpmbuild/SOURCES/
  168. List the contents of the ~rpmbuild/SOURCES/ directory. You should see the
  169. tarball you just copied, plus the files provided by the source RPM you installed
  170. in the previous step.
  171. $ ls -al ~/rpmbuild/SOURCES/
  172. total 2574
  173. drwxrwxr-x
  174. 2 guru
  175. guru
  176. 1024 Apr 28 12:03 .
  177. drwxrwxr-x
  178. 7 guru
  179. guru
  180. 1024 Apr 26 23:45 ..
  181. -rw-rw-r--
  182. 1 guru
  183. guru
  184. 836 Sep 9 2004 inet_aton.patch
  185. -rw-rw-r--
  186. 1 guru
  187. guru
  188. 324 Sep 9 2004 makefile.patch
  189. -rw-rw-r--
  190. 1 guru
  191. guru
  192. 922293 Sep 13 2004 nmap-3.00.tar.bz2
  193. -rw-r--r--
  194. 1 guru
  195. guru
  196. 871101 Mar 22 11:29 nmap-3.81.tar.bz2
  197. $
  198. 3. The next step requires modifying the spec file. This can involve two or more
  199. edits, depending on the differences between the older version and the current
  200. version. The two major changes which are always necessary include updating
  201. the version and release numbers (in one or more locations), and adding a
  202. %changelog entry. Additional changes that may be required are forward-
  203. porting patches to the current version, or removing patches that are no longer
  204. required. Finally, sometimes the newer package changes which files are to be
  205. installed, requiring adjustment of the %files section.
  206. Open the Nmap spec file with your favorite text editor, and display the headers
  207. of the file ~/rpmbuild/SPECS/nmap.spec. The following example uses the
  208. nmap-3.70-1 spec file, with line numbers added for reference; small differences
  209. may exist if you are starting from a different spec file.
  210. 1 %{!?withgtk1:%define withgtk1 1}
  211. 2
  212. 3 Summary: Network exploration tool and security scanner
  213. 4 Name: nmap
  214. 5 Version: 3.70
  215. 6 Release: 1
  216. 7 License: GPL
  217. 8 Group: Applications/System
  218. 9 Source0: http://download.insecure.org/nmap/dist/%{name}-%{version}.tar.bz2
  219. 10 #Source1: nmapfe.desktop
  220. 12-4411 Patch0: inet_aton.patch
  221. 12 Patch1: makefile.patch
  222. 13 URL: http://www.insecure.org/nmap/
  223. 14 BuildRoot: %{_tmppath}/%{name}-root
  224. 15 Epoch: 2
  225. 16 BuildRequires: openssl-devel, gtk+-devel, pcre-devel, libpcap
  226. Change lines 5 to match the version of the newer Nmap, version 3.81.
  227. Verify that on line 6 the release number is set to 1 since this will be the first
  228. RPM release of version 3.81.
  229. (SLES/SL only) Change part of line 16 from gtk+-devel to gtk-devel
  230. since on SLES/SL this package has the needed dependencies.
  231. (SLES/SL only) On lines 30 and 31 make a similar changing references to
  232. gtk+ and gtk+-devel to gtk and gtk-devel.
  233. Move to the line starting with %changelog. Add a new entry by adding the
  234. following two lines —changing the date to today’s date— followed by a blank
  235. line right beneath it, for example:
  236. * Tue Mar 22 2005 Firstname Lastname <your@emailaddr.com> - 2:3.81-1
  237. - ver 3.81
  238. The number at the end of the first line is a common, yet not required
  239. convention, for including the epoch, version, and release info linked to each
  240. changelog entry.
  241. Finally, save and exit the file.
  242. 4. The changes that have been made may be enough. The next step is to verify
  243. that all current patches still apply to the newer source code. To find out, change
  244. into the spec file directory, and execute the Prep stage of the build:
  245. $ cd ~rpmbuild/SPECS/
  246. $ rpmbuild -bp nmap.spec
  247. ...Output Omitted...
  248. If everything works out, it should finish with no error messages or prompting for
  249. user input .
  250. If there were problems, be sure to read the next two steps for examples
  251. problems and their solutions. If there were no problems, you may skip to step 8
  252. if you wish.
  253. 12-455. You will know that the initial spec file changes are not enough if you get an error
  254. message. The most likely problem you might encounter is that patches which
  255. were previously applied to the older source code no longer apply against the
  256. newer source code. This problem might be caused by any of three different
  257. reasons:
  258. • Perhaps the old patch has been adopted and applied by the software
  259. maintainer, and as such should be dropped from the spec file.
  260. • Perhaps the patch is no longer needed since the software maintainer addressed
  261. the problem using some other mechanism, and as such should be dropped
  262. from the spec file.
  263. • Perhaps the old patch is still needed, but will not apply to the new source. In
  264. this case, a new patch against the current software should be generated to
  265. replace the old patch in the spec file.
  266. Which of these three situations is the cause of any errors, and what action to
  267. take, requires intelligent analysis of the patches and source code of the
  268. software. For example, the Nmap 3.00-4 spec file includes a patch to Nmap,
  269. nmap-3.00-nowarn.patch. When updating to 3.27 and leaving the patch in
  270. place in the spec file, the following error is produced when trying to prepare the
  271. new RPMs:
  272. $ rpmbuild -bp nmap.spec
  273. [snip]
  274. + echo 'Patch #2 (nmap-3.00-nowarn.patch):'
  275. Patch #2 (nmap-3.00-nowarn.patch):
  276. + patch -p1 -b --suffix .nowarn -s
  277. The text leading up to this was:
  278. --------------------------
  279. |--- nmap-3.00/tcpip.c.nowarn
  280. 2003-01-09 15:46:53.000000000 +0100
  281. |+++ nmap-3.00/tcpip.c 2003-01-09 15:49:34.000000000 +0100
  282. --------------------------
  283. File to patch:
  284. At this point the build process stops, with the patch command waiting for input.
  285. Press <CTRL-C> to abort.
  286. Examining the directory listing of the ~rpmbuild/BUILD/nmap-3.27/
  287. directory reveals that it is likely that the file tcpip.c in the 3.00 source has
  288. been renamed to tcpip.cc in the 3.27 source. This change prevents the
  289. patch from applying.
  290. 12-46However, more inspection is needed. Examining the patch file itself,
  291. ~rpmbuild/SOURCE/nmap-3.00-nowarn.patch, reveals that the patch is
  292. changing the following lines of code:
  293. printf("Data portion:\n");
  294. while(i < tot_len) printf("%2X%c", data[i], (++i%16)? ' ' : '\n');
  295. To:
  296. printf("Data portion:\n");
  297. while(i < tot_len) {
  298. printf("%2X%c", data[i], ((i+1)%16)? ' ' : '\n');
  299. i++;
  300. }
  301. in two spots in the tcpip.c file. It is important to note that you DO NOT have
  302. to understand the C code to analyze if the patch has already been applied.
  303. Opening the file ~rpmbuild/BUILD/nmap-3.27/tcpip.cc and searching
  304. for the string Data portion, we find the lines (in two different locations):
  305. printf("Data portion:\n");
  306. while(i < tot_len) {
  307. printf("%2X%c", data[i], ((i+1) %16)? ' ' : '\n');
  308. i++;
  309. }
  310. So, it appears as if the official 3.27 Nmap has integrated the patch that was
  311. being applied in the RPM building process to the 3.00 Nmap. So, the proper
  312. course of action is to remove references to this patch in our new spec file.
  313. 6. Open the file ~rpmbuild/SPECS/nmap.spec using a text editor and remove
  314. the two lines (prefixed here by their line numbers):
  315. 12 Patch2: nmap-3.00-nowarn.patch
  316. 36 %patch2 -p 1 -b .nowarn
  317. Save the file and exit the text editor, and re-run the Prep by running the
  318. following command:
  319. $ rpmbuild -bp nmap.spec
  320. 12-47Repeat this process until all patching failures are resolved.
  321. 7. Once the spec file successfully patches the software without any errors, run the
  322. following command to compile packages of the Nmap software:
  323. $ rpmbuild -ba nmap.spec
  324. 8. Another common problem that can prevent the successful building of the new
  325. RPMs are difference in files installed to the virtual root filesystem. If any files
  326. are installed in the virtual root filesystem, but are not referenced in the %files
  327. section, RPM 4.1 and higher releases will display an error and abort the build
  328. process. You will encounter this problem in subsequent lab sequences,
  329. assuming you are using RPM version 4.1 or newer.
  330. When you encounter those sorts of problems, you will have two possible
  331. solutions:
  332. • If the file is needed, add an entry to the %files section so that the file gets
  333. packaged.
  334. • If the file is not needed, use commands in the Install stanza to delete the
  335. unwanted file from the virtual root filesystem.
  336. On RHEL4/FC3 you will see an example of the 2nd scenario with the following
  337. error message will be displayed:
  338. error: Installed (but unpackaged) file(s) found:
  339. /usr/share/applications/nmapfe.desktop
  340. RPM build errors:
  341. Installed (but unpackaged) file(s) found:
  342. /usr/share/applications/nmapfe.desktop
  343. This refers to a menu desktop file. Open the spec file with a text editor, and
  344. examine the %install section. You will notice the following lines:
  345. # remove unused files
  346. rm -f $RPM_BUILD_ROOT/usr/share/gnome/apps/Utilities/nmapfe.desktop
  347. The intent is to delete the menu desktop file, but in this newer version it is
  348. being installed into a different location so this deletion attempt is failing.
  349. Correct the line to point to the new location by editing the line to read:
  350. rm -f $RPM_BUILD_ROOT/usr/share/applications/nmapfe.desktop
  351. 12-48Re-run the following command to compile packages of the Nmap software:
  352. $ rpmbuild -ba nmap.spec
  353. This should complete with out error.
  354. On SLES9/SL92 you will encounter two problems. The first build attempt should
  355. end with the following error:
  356. RPM build errors:
  357. File not found: /var/tmp/nmap-root/usr/share/nmap
  358. This indicates that a required directory was not found in the virtual root. Under
  359. the /usr/share/nmap/ directory the file nmap.dtd should exist. Do a
  360. search to find where it is is located inside of the virtual root:
  361. $ find /var/tmp/nmap-root -name nmap.dtd
  362. /var/tmp/nmap-root/var/tmp/nmap-root/usr/share/nmap/nmap.dtd
  363. If you examine the path you’ll notice that there is a var/tmp/nmap-root/
  364. inside of /var/tmp/nmap-root/. This is likely a error that occurs during the
  365. installation phase, open the spec file and locate the line make install line:
  366. %makeinstall nmapdatadir=$RPM_BUILD_ROOT%{_datadir}/nmap
  367. Edit the line and remove the extra parameter as the stock %makeinstall
  368. macro should be sufficient. Change the line to read:
  369. %makeinstall
  370. Re-run the following command to compile packages of the Nmap software:
  371. $ rpmbuild -ba nmap.spec
  372. You will see an example of the 2nd scenario with the following error message
  373. will be displayed:
  374. error: Installed (but unpackaged) file(s) found:
  375. /usr/share/applications/nmapfe.desktop
  376. RPM build errors:
  377. Installed (but unpackaged) file(s) found:
  378. /usr/share/applications/nmapfe.desktop
  379. This refers to a menu desktop file. Open the spec file with a text editor, and
  380. examine the %install section. You will notice the following lines:
  381. # remove unused files
  382. rm -f $RPM_BUILD_ROOT/usr/share/gnome/apps/Utilities/nmapfe.desktop
  383. 12-49The intent is to delete the menu desktop file, but in this newer version it is
  384. being installed into a different location so this deletion attempt is failing.
  385. Correct the line to point to the new location by editing the line to read:
  386. rm -f $RPM_BUILD_ROOT/usr/share/applications/nmapfe.desktop
  387. Re-run the following command to compile packages of the Nmap software:
  388. $ rpmbuild -ba nmap.spec
  389. This should complete with out error.
  390. 9. Install the new updated Nmap RPMs as root:
  391. $ su -
  392. Password:
  393. [RHEL4/FC3 ]# rpm -Uvh /home/guru/rpmbuild/RPMS/i386/nmap-*
  394. [SLES9/SL92]# rpm -Uvh /home/guru/rpmbuild/RPMS/i586/nmap-*
  395. Preparing...
  396. ########################################### [100%]
  397. 1:nmap
  398. ########################################### [ 50%]
  399. 2:nmap-frontend
  400. ########################################### [100%]
  401. 10. Newer Nmap versions supports version scans that report the version of
  402. services. Try using this feature during a confirmation run to see that your new
  403. Nmap RPM is working properly.
  404. # nmap -sV 127.0.0.1
  405. Starting nmap 3.81 ( http://www.insecure.org/nmap/ ) at 2005-03-25 18:39 MST
  406. Interesting ports on localhost (127.0.0.1):
  407. (The 1659 ports scanned but not shown below are in state: closed)
  408. PORT
  409. STATE SERVICE VERSION
  410. 22/tcp open ssh
  411. OpenSSH 3.9p1 (protocol 1.99)
  412. 25/tcp open smtp
  413. Postfix smtpd
  414. 111/tcp open rpcbind 2 (rpc #100000)
  415. 631/tcp open ipp
  416. CUPS 1.1
  417. Nmap finished: 1 IP address (1 host up) scanned in 5.379 seconds
  418. An older version of NMAP without the version scanning feature would have
  419. returned the error:
  420. 12-50Illegal Argument to -P, use -P0, -PI, -PB, -PM, -PP, -PT, or -PT80 (or whatever number you want for
  421. the TCP probe destination port)
  422. QUITTING!
  423. 12-51Task 3
  424. Create a spec file from scratch for an unpackaged software application.
  425. Revise packages to correct packaging errors.
  426. Create multiple RPMs from a single source RPM.
  427. LBreakout2, http://lgames.sourceforge.net/index.php?project=LBreakout2, is
  428. a popular Breakout-style game for Linux. Unfortunately, it is not provided in
  429. RPM format, though the source code is readily available from the
  430. http://lgames.sourceforge.net/ home page. Being a devotee of all things
  431. Breakout and Breakout-related, you have decided to prepare an RPM of
  432. LBreakout2 for your system.
  433. This lab task requires that following packages are installed so that LBreakout2
  434. can be compiled:
  435. SDL-devel
  436. libpng-devel
  437. The RPM packages have the same name on RHEL/FC and SLES/SL. Verify that
  438. the packages are installed, and if not, install them now.
  439. 1. When creating an RPM from scratch, most packagers start with a skeleton
  440. spec file which lists common lines used in most spec files. Through a trial-and-
  441. error process, this template file can be modified and tested until it produces a
  442. good set of RPMs. A template spec file has been provided in your /labfiles
  443. directory; begin by copying this spec file for use with LBreakout2:
  444. $ cp /labfiles/template.spec ~/rpmbuild/SPECS/lbreakout2.spec
  445. 2. A copy of the source code for LBreakout2 has been provided for you. Copy this
  446. source code into your SOURCES directory:
  447. $ cp /labfiles/lbreakout2-2.4.1.tar.gz ~/rpmbuild/SOURCES
  448. 3. Once the source code for an application is in place and a spec file exists, the
  449. next task is to modify the spec to compile your software. Open your spec file
  450. for editing:
  451. $ cd rpmbuild/SPECS/
  452. 12-52$ vim lbreakout2.spec
  453. 4. Complete the Header stanza. At a minimum, you will need Summary, Name,
  454. Version, Release, Epoch, License, Group, Source, URL, and BuildRoot
  455. directives. Try creating these yourself, then compare your solution with the
  456. following possible solution:
  457. Summary: Breakout clone
  458. Name: lbreakout2
  459. Version: 2.4.1
  460. Release: 1
  461. Epoch: 0
  462. License: GPL
  463. Group: Amusements/Games
  464. Source0: http://ftp1.sourceforge.net/lgames/%{name}-%{version}.tar.gz
  465. URL: http://lgames.sourceforge.net/index.php?project=LBreakout2
  466. BuildRoot: %{_tmppath}/%{name}-root
  467. 5. The Header stanza also requires a %description directive which provides
  468. users with a fuller description of the purpose of the packaged application.
  469. Create your own %description block, similar to the following:
  470. %description
  471. The polished successor to LBreakout offers you a new challenge in more than 50 levels with loads of
  472. new bonuses (goldshower, joker, explosive balls, bonus magnet ...), maluses (chaos, darkness, weak
  473. balls, malus magnet ...) and special bricks (growing bricks, explosive bricks, regenerative bricks,
  474. indestructible bricks, chaotic bricks).
  475. And if you're through with all the levels you can create complete new level sets with the integrated
  476. easy-to-use level editor!
  477. 6. Save your spec file and quit the editor. At this point, you can test your spec file
  478. to be certain that your Header stanza works:
  479. $ rpmbuild -bp lbreakout2.spec
  480. Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.39167
  481. • RPM tells you it is executing the %prep section of the spec file.
  482. + umask 022
  483. + cd /home/guru/rpmbuild/BUILD
  484. 12-53+ LANG=C
  485. + export LANG
  486. + cd /home/guru/rpmbuild/BUILD
  487. + rm -rf lbreakout2-2.4.1
  488. + /usr/bin/gzip -dc /home/guru/rpmbuild/SOURCES/lbreakout2-2.4.1.tar.gz
  489. + tar -xf -
  490. + STATUS=0
  491. + '[' 0 -ne 0 ']'
  492. + cd lbreakout2-2.4.1
  493. ++ /usr/bin/id -u
  494. + '[' 50016 = 0 ']'
  495. ++ /usr/bin/id -u
  496. + '[' 50016 = 0 ']'
  497. + /bin/chmod -Rf a+rX,g-w,o-w .
  498. + exit 0
  499. • RPM indicates that the %prep section was processed
  500. successfully.
  501. $
  502. 7. The template spec file you used as a starting place has a commonly used Build
  503. stanza already created. Try compiling your software to see if this default Build
  504. stanza will work:
  505. $ rpmbuild -bc lbreakout2.spec
  506. Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.62876
  507. • First, the %prep stanza is processed
  508. ...Output Omitted...
  509. Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.81466
  510. • After the software is prepared, the %build stanza compiles it
  511. ...Output Omitted...
  512. gcc -O2 -g -pipe -march=i386 -mcpu=i686 -Wall -
  513. • This line shows the step of actually linking together the compiled
  514. objects to produce the lbreakout2 executable.
  515. I/usr/include/SDL -D_REENTRANT -o lbreakout2 credit.o
  516. shine.o extras.o balls.o shrapnells.o shots.o event.o pad-
  517. dle.o frame.o misc.o bricks.o difficulty.o player.o game.o
  518. file.o levels.o config.o item.o menu.o manager.o value.o
  519. chart.o editor.o help.o hint.o theme.o client.o
  520. client_recv.o client_data.o client_game.o client_handlers.o
  521. comm.o display.o main.o -lSDL_mixer ../common/libcommon.a
  522. ../gui/libGui.a -lpng -lz -lm -L/usr/lib -Wl,-
  523. rpath,/usr/lib -lSDL -lpthread
  524. make[3]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client'
  525. 12-54make[2]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client'
  526. Making all in docs
  527. make[2]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/docs'
  528. make[2]: Nothing to be done for `all'.
  529. make[2]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/docs'
  530. make[2]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1'
  531. make[2]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1'
  532. make[1]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1'
  533. + exit 0
  534. • This exit 0 indicates that the %build completed successfully.
  535. $
  536. 8. So far, it looks like the default Build stanza should work. Next, test out the
  537. commonly used Install stanza which was provided in the template spec file:
  538. On RHEL/FC run the following command and examine the output produced, on
  539. SLES/SL skip to step 18. on page 62 (unless you want to read about the types of
  540. problems that can occur).
  541. $ rpmbuild -bi lbreakout2.spec
  542. Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.89196
  543. • First, the %prep
  544. ...Output Omitted...
  545. Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.89196
  546. • Next, the %build
  547. ...Output Omitted...
  548. Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.70963
  549. • Next, the %install
  550. ...Output Omitted...
  551. Making install in client
  552. make[1]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client'
  553. Making install in gfx
  554. make[2]: Entering directory
  555. `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/gfx'
  556. Making install in AbsoluteB
  557. make[3]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/gfx/AbsoluteB'
  558. make[4]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/gfx/AbsoluteB'
  559. make[4]: Nothing to be done for `install-exec-am'.
  560. /bin/sh ../../../mkinstalldirs /usr/share/games/lbreakout2/gfx/AbsoluteB
  561. mkdir /usr/share/games/lbreakout2
  562. mkdir: cannot create directory `/usr/share/games/lbreakout2': Permission denied
  563. mkdir /usr/share/games/lbreakout2/gfx
  564. 12-55mkdir: cannot create directory `/usr/share/games/lbreakout2/gfx': No such file or directory
  565. mkdir /usr/share/games/lbreakout2/gfx/AbsoluteB
  566. mkdir: cannot create directory `/usr/share/games/lbreakout2/gfx/AbsoluteB': No such file or directory
  567. make[4]: *** [install-data-local] Error 1
  568. make[4]: Leaving directory
  569. `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/gfx/AbsoluteB'
  570. make[3]: *** [install-am] Error 2
  571. make[3]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/gfx/AbsoluteB'
  572. make[2]: *** [install-recursive] Error 1
  573. make[2]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/gfx'
  574. make[1]: *** [install-recursive] Error 1
  575. make[1]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client'
  576. make: *** [install-recursive] Error 1
  577. error: Bad exit status from /var/tmp/rpm-tmp.70963 (%install)
  578. RPM build errors:
  579. Bad exit status from /var/tmp/rpm-tmp.70963 (%install)
  580. $
  581. 9. The default %install script will NOT work for this software. So, try to figure
  582. out why. Looking at the spec file, you’ll see that the current %build script
  583. does:
  584. %install
  585. rm -rf %{buildroot}
  586. %makeinstall
  587. The problem here is that %makeinstall is not working. Looking through the
  588. output from the %install, you see that the %makeinstall did:
  589. make prefix=/var/tmp/lbreakout2-root/usr
  590. exec_prefix=/var/tmp/lbreakout2-root/usr
  591. bindir=/var/tmp/lbreakout2-root/usr/bin
  592. sbindir=/var/tmp/lbreakout2-root/usr/sbin syscon-
  593. fdir=/var/tmp/lbreakout2-root/etc data-
  594. dir=/var/tmp/lbreakout2-root/usr/share
  595. includedir=/var/tmp/lbreakout2-root/usr/include lib-
  596. dir=/var/tmp/lbreakout2-root/usr/lib libex-
  597. 12-56
  598. • RPM indicates that the %install script did NOT complete
  599. successfully.ecdir=/var/tmp/lbreakout2-root/usr/libexec
  600. localstatedir=/var/tmp/lbreakout2-root/var sharedstate-
  601. dir=/var/tmp/lbreakout2-root/usr/com
  602. mandir=/var/tmp/lbreakout2-root/usr/share/man info-
  603. dir=/var/tmp/lbreakout2-root/usr/share/info install
  604. That is, it ran the make install command with options intented to get it to
  605. install software to a virtual directory structure under the
  606. /var/tmp/lbreakout2-root/ directory rather than under /. However, as
  607. the error indicates, this failed:
  608. make[4]: Entering directory
  609. `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/gfx/AbsoluteB'
  610. make[4]: Nothing to be done for `install-exec-am'.
  611. /bin/sh ../../../mkinstalldirs /usr/share/games/lbreakout2/gfx/AbsoluteB
  612. mkdir /usr/share/games/lbreakout2
  613. • This should have been /var/tmp/lbreakout2-
  614. root/usr/share/games/lbreakout2.
  615. mkdir: cannot create directory
  616. `/usr/share/games/lbreakout2': Permission denied
  617. For some reason, the %makeinstall macro is not capable of getting this
  618. software to install into the Buildroot. These sorts of problems are quite
  619. common-place, and correcting them typically requires either a modification of
  620. the spec file, an addition of a patch to modify the Makefiles which specify
  621. how the software gets compiled and installed, or some combination of both
  622. spec modifications and code patches.
  623. 10. To get this software packaged, you must figure out why it cannot currently be
  624. installed into the Buildroot. So far, you know that executing the
  625. make install command in the client subdirectory of the source code fails
  626. because it tries to install software to /usr/share/games/lbreakout2/
  627. rather than /var/tmp/lbreakout2-
  628. root/usr/share/games/lbreakout2/. Looking at the
  629. /home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/Makefile,
  630. you’ll see that it does:
  631. ...
  632. hi_inst_flag = -DHI_DIR=\"/var/lib/games\"
  633. inst_dir = /usr/share/games/lbreakout2
  634. inst_flag = -DSRC_DIR=\"/usr/share/games/lbreakout2\"
  635. ...
  636. 12-57The problem here is this middle line, line 81. If this Makefile were written
  637. correctly, that line would instead look something like:
  638. inst_dir = $(datadir)/games/lbreakout2
  639. where it uses a shell variable which can be overridden to specify where the
  640. software gets installed.
  641. 11. Fixing this problem can be done in a couple of different ways:
  642. • You could create a patch for the Makefile and apply it during the %prep
  643. section. This is the “correct” solution, but is actually quite difficult, since the
  644. Makefiles for this program, like many other Linux applications, are automatically
  645. generated during the %build process by the autoconf software suite.
  646. • You could add a script as the first line of the %install stanza which edits the
  647. incorrect Makefiles. This is a little bit easier to do, but is a less “correct”
  648. solution.
  649. In many cases, though, a third option will also be available: you might simply be
  650. able to modify the incorrect Makefile variable by passing the correct value to
  651. the %makeinstall macro. If possible, that solution will be the simplest. In this
  652. case, the value of the inst_dir variable is incorrect, so modify the spec file to
  653. correct that variable. In the %install stanza, change the %makeinstall line
  654. to:
  655. • This line is too long to fit on a single 80-column line on the
  656. %makeinstall \
  657. screen. For readability, it can be typed on two lines, as is done
  658. inst_dir=${RPM_BUILD_ROOT}/usr/share/games/lbreakout2
  659. here, with a back-slash (\) at the end of the first line. This back-
  660. slash indicates to rpm that this line continues on to a
  661. subsequent line.
  662. 12. Once you have made this change, save the spec file and then try once again to
  663. compile the software and install it to a virtual root directory:
  664. $ rpmbuild -bi lbreakout2.spec
  665. ...Output Omitted...
  666. Making install in gui_theme
  667. make[2]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/gui_theme'
  668. make[3]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/gui_theme'
  669. make[3]: Nothing to be done for `install-exec-am'.
  670. /bin/sh ../../mkinstalldirs /var/tmp/lbreakout2-root/usr/share/games/lbreakout2/gui_theme
  671. mkdir /var/tmp/lbreakout2-
  672. • This solved the problem -- the directory is now being created in
  673. the virtual directory tree.
  674. root/usr/share/games/lbreakout2/gui_theme
  675. ...Output Omitted...
  676. 12-58if ! test -f /var/lib/games/lbreakout2.hscr; then \
  677. /usr/bin/install -c -m 644 -m 666 empty.hscr /var/lib/games/lbreakout2.hscr; \
  678. fi;
  679. /usr/bin/install: cannot create regular file `/var/lib/games/lbreakout2.hscr': Permission denied
  680. make[3]: *** [install-data-local] Error 1
  681. make[3]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client'
  682. make[2]: *** [install-am] Error 2
  683. make[2]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client'
  684. make[1]: *** [install-recursive] Error 1
  685. make[1]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client'
  686. make: *** [install-recursive] Error 1
  687. error: Bad exit status from /var/tmp/rpm-tmp.72065 (%install)
  688. RPM build errors:
  689. Bad exit status from /var/tmp/rpm-tmp.72065 (%install)
  690. $
  691. 13. You’ve solved the first problem, but this revealed a new problem to solve. Here,
  692. the make install command is doing:
  693. make[3]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client'
  694. ...
  695. if ! test -f /var/lib/games/lbreakout2.hscr; then \
  696. /usr/bin/install -c -m 644 -m 666 empty.hscr
  697. /var/lib/games/lbreakout2.hscr; \
  698. fi;
  699. /usr/bin/install: cannot create regular file
  700. `/var/lib/games/lbreakout2.hscr': Permission denied
  701. make[3]: *** [install-data-local] Error 1
  702. This is a similar problem to the previous one. If you search through the
  703. /home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/client/Makefile
  704. file for the string /var/lib/games, you’ll see that the Makefile does:
  705. ...
  706. doc_dir = /usr/doc
  707. hi_dir = /var/lib/games
  708. hi_inst_flag = -DHI_DIR=\"/var/lib/games\"
  709. 12-59...
  710. The problem here is this middle line, line 79. If this Makefile were written
  711. correctly, that line would instead look something like:
  712. hi_dir = $(localstatedir)/lib/games
  713. where it uses a shell variable which can be overridden to specify where the
  714. software gets installed.
  715. 14. As with the previous problem, this problem can be fixed by patching the
  716. Makefiles, modifying the Makefiles within the %install script, or by passing a
  717. variable to the %makeinstall macro. Edit the spec file again, and modify the
  718. %makeinstall macro so that it reads:
  719. %makeinstall \
  720. inst_dir=${RPM_BUILD_ROOT}/usr/share/games/lbreakout2 \
  721. hi_dir=${RPM_BUILD_ROOT}/var/lib/games
  722. 15. Once you have made this change, save the spec file and then try once again to
  723. compile the software and install it to a virtual root directory:
  724. $ rpmbuild -bi lbreakout2.spec
  725. ...Output Omitted...
  726. if ! test -f /var/tmp/lbreakout2-
  727. • This solved the problem -- the directory is now being created in
  728. the virtual directory tree.
  729. root/var/lib/games/lbreakout2.hscr; then \
  730. /usr/bin/install -c -m 644 -m 666 empty.hscr
  731. /var/tmp/lbreakout2-root/var/lib/games/lbreakout2.hscr; \
  732. fi;
  733. ...Output Omitted...
  734. Making install in docs
  735. make[1]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/docs'
  736. make[2]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/docs'
  737. make[2]: Nothing to be done for `install-exec-am'.
  738. /bin/sh ../mkinstalldirs /usr/doc/lbreakout2
  739. mkdir /usr/doc
  740. mkdir: cannot create directory `/usr/doc': Permission denied
  741. mkdir /usr/doc/lbreakout2
  742. mkdir: cannot create directory `/usr/doc/lbreakout2': No such file or directory
  743. make[2]: *** [install-data-local] Error 1
  744. 12-60make[2]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/docs'
  745. make[1]: *** [install-am] Error 2
  746. make[1]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/docs'
  747. make: *** [install-recursive] Error 1
  748. error: Bad exit status from /var/tmp/rpm-tmp.33062 (%install)
  749. RPM build errors:
  750. Bad exit status from /var/tmp/rpm-tmp.33062 (%install)
  751. $
  752. 16. You’ve solved the second problem, but now you’ve got a new problem to solve.
  753. Here, the make install command is doing:
  754. make[1]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/docs'
  755. ...
  756. /bin/sh ../mkinstalldirs /usr/doc/lbreakout2
  757. mkdir /usr/doc
  758. mkdir: cannot create directory `/usr/doc': Permission denied
  759. ...
  760. If you look at the /home/guru/rpmbuild/BUILD/lbreakout2-
  761. 2.4.1/docs/Makefile file for the string /usr/doc, you’ll find that it does:
  762. ...
  763. audio_flag = -DAUDIO_ENABLED
  764. doc_dir = /usr/doc
  765. hi_dir = /var/lib/games
  766. ...
  767. 17. As with the other problems, the trouble here is this middle line, line 78. It needs
  768. to be corrected to install to the virtual directory tree. This line also has another
  769. flaw. On RHEL/FC systems, all documentation files should be put in the
  770. directory /usr/share/doc but this line specifies that they will be placed in
  771. the /usr/doc directory.
  772. As with the previous problems, this mistake could be fixed in three different
  773. ways. To solve this problem, edit the lbreakout2 spec file again, and change
  774. the %makeinstall line to the following:
  775. 12-61%makeinstall \
  776. inst_dir=${RPM_BUILD_ROOT}/usr/share/games/lbreakout2 \
  777. hi_dir=${RPM_BUILD_ROOT}/var/lib/games \
  778. doc_dir=${RPM_BUILD_ROOT}/usr/share/doc
  779. 18. Once you have made this change, save the spec file and then try once again to
  780. compile the software and install it to a virtual root directory:
  781. $ rpmbuild -bi lbreakout2.spec
  782. ...Output Omitted...
  783. mkdir /var/tmp/lbreakout2-root/usr/share/doc
  784. • Problem solved!
  785. mkdir /var/tmp/lbreakout2-root/usr/share/doc/lbreakout2
  786. /usr/bin/install -c -m 644 index.html /var/tmp/lbreakout2-root/usr/share/doc/lbreakout2/index.html
  787. make[2]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/docs'
  788. make[1]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1/docs'
  789. make[1]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1'
  790. make[2]: Entering directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1'
  791. make[2]: Nothing to be done for `install-exec-am'.
  792. make[2]: Nothing to be done for `install-data-am'.
  793. make[2]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1'
  794. make[1]: Leaving directory `/home/guru/rpmbuild/BUILD/lbreakout2-2.4.1'
  795. + /usr/lib/rpm/redhat/brp-compress
  796. • At this point, the %install has finished, and RPM is now
  797. processing the %files stanza.
  798. + /usr/lib/rpm/redhat/brp-strip /usr/bin/strip
  799. + /usr/lib/rpm/redhat/brp-strip-static-archive
  800. /usr/bin/strip
  801. + /usr/lib/rpm/redhat/brp-strip-comment-note /usr/bin/strip /usr/bin/objdump
  802. Processing files: lbreakout2-2.4.1-1
  803. error: File not found by glob: /var/tmp/lbreakout2-root/usr/lib/*.so.*
  804. error: File not found: /var/tmp/lbreakout2-root/usr/share/lbreakout2
  805. error: File not found by glob: /var/tmp/lbreakout2-root/usr/share/man/man8/*
  806. Executing(%doc): /bin/sh -e /var/tmp/rpm-tmp.22825
  807. + umask 022
  808. + cd /home/guru/rpmbuild/BUILD
  809. + cd lbreakout2-2.4.1
  810. + DOCDIR=/var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  811. + export DOCDIR
  812. + rm -rf /var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  813. 12-62+ /bin/mkdir -p /var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  814. + cp -pr AUTHORS COPYING ChangeLog NEWS README TODO /var/tmp/lbreakout2-
  815. root/usr/share/doc/lbreakout2-2.4.1
  816. + exit 0
  817. RPM build errors:
  818. File not found by glob: /var/tmp/lbreakout2-root/usr/lib/*.so.*
  819. File not found: /var/tmp/lbreakout2-root/usr/share/lbreakout2
  820. File not found by glob: /var/tmp/lbreakout2-root/usr/share/man/man8/*
  821. $
  822. 19. At this point, the %build and %install sections of the spec file are correct.
  823. Now, the RPM compile is failing because the default %files stanza in the
  824. template file is not correct. To solve this problem, first use the ls command to
  825. explore what files and directories are in the Buildroot,
  826. /var/tmp/lbreakout2-root. You should find the following files and
  827. directories:
  828. /var/lib/games/lbreakout2.hscr
  829. /usr/share/games/lbreakout2/{gfx,gui_theme,levels,sounds}
  830. /usr/share/doc/lbreakout2
  831. /usr/share/doc/lbreakout2-2.4.1
  832. /usr/bin/lbreakout2
  833. /usr/bin/lbreakout2server
  834. 20. There are two problems here. One is that these files and directories need to be
  835. listed in the %files section of the spec file.
  836. There is another, more subtle problem, however. Looking again at this ls
  837. output, you should notice that there are two documentation directories:
  838. RHEL/FC: /usr/share/doc/lbreakout2
  839. RHEL/FC: /usr/share/doc/lbreakout2-2.4.1
  840. ---------
  841. SLES/SL: /usr/doc/lbreakout2
  842. SLES/SL: /usr/share/doc/packages/lbreakout2
  843. There should only be one documentation directory.
  844. 12-63On RHEL/FC it should be the one with the application version,
  845. /usr/share/doc/lbreakout2-2.4.1.
  846. On SLES/SL it should be /usr/share/doc/packages/lbreakout2/.
  847. 21. If you look at the contents of the wrongly located documentation
  848. directory you should discover that it's all HTML documentation. To combine
  849. these two directories, you should put the contents of the rouge directory as
  850. subdirectory named html in the proper documentation directory.
  851. On RHEL/FC modify the %install stanza of the spec file to end with the line:
  852. mv ${RPM_BUILD_ROOT}/usr/share/doc/lbreakout2 html
  853. On SLES/SL modify the %install stanza of the spec file to end with the line:
  854. mv ${RPM_BUILD_ROOT}/usr/doc/lbreakout2 html
  855. On RHEL/FC When you finish, your Install stanza should read:
  856. %install
  857. rm -rf %{buildroot}
  858. %makeinstall \
  859. inst_dir=${RPM_BUILD_ROOT}/usr/share/games/lbreakout2 \
  860. hi_dir=${RPM_BUILD_ROOT}/var/lib/games \
  861. doc_dir=${RPM_BUILD_ROOT}/usr/share/doc
  862. mv ${RPM_BUILD_ROOT}/usr/share/doc/lbreakout2 html
  863. %clean
  864. rm -rf %{buildroot}
  865. On SLES/SL When you finish, your Install stanza should read:
  866. %install
  867. rm -rf %{buildroot}
  868. %makeinstall
  869. mv ${RPM_BUILD_ROOT}/usr/doc/lbreakout2 html
  870. %clean
  871. rm -rf %{buildroot}
  872. 12-6422. After modifying the contents of the documentation directory, you need to
  873. adjust the %files section to list the newly included documentation files. Add
  874. the html directory to the %doc macro within the %files stanza, so that it
  875. reads:
  876. %doc AUTHORS COPYING ChangeLog NEWS README TODO html
  877. 23. Look at the rest of your %files stanza. It currently reads:
  878. %files
  879. %defattr(-, root, root)
  880. %doc AUTHORS COPYING ChangeLog NEWS README TODO html
  881. %{_bindir}/*
  882. %{_libdir}/*.so.*
  883. %{_datadir}/%{name}
  884. %{_mandir}/man8/*
  885. Compare this with the list you obtained in step 19 of the files which you wish to
  886. package. When you compare the two lists, you will find that the %{_bindir}
  887. file-matching macro is needed, but that the %{_libdir} and the %{_mandir}
  888. statements need to be deleted.
  889. • This statement sets ownership on the packaged files and
  890. directories.
  891. • The files in /var/tmp/lbreakout2-root/usr/bin
  892. • The files in /var/tmp/lbreakout2-root/usr/lib/*.so.*
  893. • The files in /var/tmp/lbreakout2-root/usr/share/lbreakout2
  894. • The files in /var/tmp/lbreakout2-root/usr/share/man/man8
  895. 24. Correct your %files stanza to define the correct files produced with
  896. LBreakout2 by changing it to the following:
  897. %files
  898. %defattr(-, root, root)
  899. %doc AUTHORS COPYING ChangeLog NEWS README TODO html
  900. %{_bindir}/*
  901. %{_datadir}/%{name}
  902. 25. Once you have made this change, save the spec file and then try once again to
  903. compile the software and install it to a virtual root directory:
  904. $ rpmbuild -bi lbreakout2.spec
  905. ...Output Omitted...
  906. Processing files: lbreakout2-2.4.1-1
  907. error: File not found: /var/tmp/lbreakout2-
  908. • The %files stanza listed a file which could not be found.
  909. root/usr/share/lbreakout2
  910. Executing(%doc): /bin/sh -e /var/tmp/rpm-tmp.546
  911. 12-65+ umask 022
  912. + cd /home/guru/rpmbuild/BUILD
  913. + cd lbreakout2-2.4.1
  914. + DOCDIR=/var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  915. + export DOCDIR
  916. + rm -rf /var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  917. + /bin/mkdir -p /var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  918. + cp -pr AUTHORS COPYING ChangeLog NEWS README TODO html
  919. /var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  920. + exit 0
  921. RPM build errors:
  922. File not found: /var/tmp/lbreakout2-root/usr/share/lbreakout2
  923. $
  924. 26. At this point, the spec file is almost working. This procedure failed because the
  925. %files stanza is still slightly incorrect. The %files stanza is currently trying
  926. to package the directory /usr/share/lbreakout2, which does not exist.
  927. Looking back at the list of files and directories produced in step 19. on page 63,
  928. you’ll see that this should instead be /usr/share/games/lbreakout2. To
  929. fix this problem, edit the spec file and change the line:
  930. %{_datadir}/%{name}
  931. to:
  932. %{_datadir}/games/%{name}
  933. 27. Once you have made this change, save the spec file and then try once again to
  934. compile the software and install it to a virtual root directory:
  935. $ rpmbuild -bi lbreakout2.spec
  936. ...Output Omitted...
  937. 28. If you are using RPM 4.1 or later versions, when you complete the previous
  938. step, you will get output similar to the following:
  939. Checking for unpackaged file(s): /usr/lib/rpm/check-files
  940. /var/tmp/lbreakout2-root
  941. 12-66error: Installed (but unpackaged) file(s) found:
  942. /var/lib/games/lbreakout2.hscr
  943. • This error indicates that a file is installed in the virtual root, but is
  944. not listed in the %files stanza.
  945. RPM build errors:
  946. Installed (but unpackaged) file(s) found:
  947. /var/lib/games/lbreakout2.hscr
  948. • This is the problem mentioned in Step 8 of Task 2. RPM 4.1 and
  949. This build attempt is getting closer to succeeding. Now, the build is exiting
  950. later releases check for installed but unpackaged files and
  951. because a file, /var/lib/games/lbreakout2.hscr, was found in the virtual
  952. produce a warning or error when any are encountered.
  953. root, but was not listed in the %files stanza. Skip the next step, and proceed
  954. to step 30 which explains how to add this missing file to the spec file.
  955. 29. If you are using RPM 4.0 or older versions, you will not get output similar to that • If you are using RPM 4.1 or newer versions, you DO NOT have to
  956. complete the commands in this step. Be grateful!
  957. in the previous step. Instead, your build will actually appear to complete
  958. successfully, producing output similar to the following:
  959. ...Output Omitted...
  960. + exit 0
  961. Finding Provides: (using /usr/lib/rpm/find-provides)...
  962. Finding Requires: (using /usr/lib/rpm/find-requires)...
  963. PreReq: rpmlib(PayloadFilesHavePrefix) <= 4.0-1 rpmlib(Com-
  964. pressedFileNames) <= 3.0.4-1
  965. Requires(rpmlib): rpmlib(PayloadFilesHavePrefix) <= 4.0-1
  966. rpmlib(CompressedFileNames) <= 3.0.4-1
  967. Requires: ld-linux.so.2 libartsc.so.0 libaudiofile.so.0
  968. libc.so.6 libdl.so.2 libesd.so.0 libm.so.6 libpng.so.2
  969. libpthread.so.0 libSDL-1.2.so.0 libX11.so.6 libXext.so.6
  970. libz.so.1 libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1)
  971. libc.so.6(GLIBC_2.1.3) libm.so.6(GLIBC_2.0)
  972. libpthread.so.0(GLIBC_2.0)
  973. RPM 4.1 and later automatically “validate” installations to make sure that all
  974. • Remember, these commands are only used if you are using RPM
  975. 4.0 or earlier releases.
  976. files installed into the ${RPM_BUILD_ROOT}, complaining if any files were
  977. installed but not packaged. RPM 4.0 and earlier releases do not do this, so you
  978. must manually validate your installation. To do this, first prepare a list of the
  979. files installed by the completed LBreakout2 install, and store these files into a
  980. text file in your home directory:
  981. $ find /var/tmp/lbreakout2-root | sort > ~/lbreakout2-installed-files
  982. 12-67This list of files will incorrectly prepend the ${RPM_BUILD_ROOT} at the
  983. beginning of every file name. Strip this path off:
  984. $ perl -pi -e 's/^\/var\/tmp\/lbreakout2-root//g' ~/lbreakout2-installed-files
  985. Now, actually build a package:
  986. $ rpmbuild -ba lbreakout2.spec
  987. ...Output Omitted...
  988. Wrote: /home/guru/rpmbuild/SRPMS/lbreakout2-2.4.1-1.src.rpm
  989. Wrote: /home/guru/rpmbuild/RPMS/i386/lbreakout2-2.4.1-
  990. • This is the location of the built package.
  991. 1.i386.rpm
  992. Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.63876
  993. + umask 022
  994. + cd /home/guru/rpmbuild/BUILD
  995. + cd lbreakout2-2.4.1
  996. + rm -rf /var/tmp/lbreakout2-root
  997. + exit 0
  998. Once your package is built, query it for the files it contains, and store those file
  999. names in a text file in your home directory:
  1000. $ rpm -qlp ../RPMS/i386/lbreakout2-2.4.1-1.i386.rpm | sort >
  1001. ~/lbreakout2-packaged-files
  1002. Finally, compare the list of packaged files with the list of installed files:
  1003. $ diff -Naur ~/lbreakout2-packaged-files ~/lbreakout2-
  1004. • In this output, a plus sign (+) indicates a file which was
  1005. installed but not packaged.
  1006. installed-files
  1007. --- /home/guru/lbreakout2-packaged-files
  1008. +++ /home/guru/lbreakout2-installed-files
  1009. @@ -1,5 +1,10 @@
  1010. +
  1011. +/usr
  1012. +/usr/bin
  1013. /usr/bin/lbreakout2
  1014. /usr/bin/lbreakout2server
  1015. +/usr/share
  1016. +/usr/share/doc
  1017. /usr/share/doc/lbreakout2-2.4.1
  1018. /usr/share/doc/lbreakout2-2.4.1/AUTHORS
  1019. 12-68
  1020. Thu May 22 14:43:42 2003
  1021. Thu May 22 14:44:15 2003/usr/share/doc/lbreakout2-2.4.1/ChangeLog
  1022. @@ -42,6 +47,7 @@
  1023. /usr/share/doc/lbreakout2-2.4.1/NEWS
  1024. /usr/share/doc/lbreakout2-2.4.1/README
  1025. /usr/share/doc/lbreakout2-2.4.1/TODO
  1026. +/usr/share/games
  1027. /usr/share/games/lbreakout2
  1028. /usr/share/games/lbreakout2/gfx
  1029. /usr/share/games/lbreakout2/gfx/AbsoluteB
  1030. @@ -247,3 +253,7 @@
  1031. /usr/share/games/lbreakout2/sounds/wall.wav
  1032. /usr/share/games/lbreakout2/sounds/weak_ball.wav
  1033. /usr/share/games/lbreakout2/sounds/wontgiveup.wav
  1034. +/var
  1035. +/var/lib
  1036. +/var/lib/games
  1037. +/var/lib/games/lbreakout2.hscr
  1038. Looking over that list, you’ll see that the following files or directories are
  1039. installed, but are not included in the package:
  1040. /usr
  1041. /usr/bin
  1042. /usr/share
  1043. /usr/share/doc
  1044. /usr/share/games
  1045. /var
  1046. /var/lib
  1047. /var/lib/games
  1048. /var/lib/games/lbreakout2.hscr
  1049. Of those files and directories, most are shared directories which should NOT be
  1050. part of the package, but one file, /var/lib/games/lbreakout2.hscr, does
  1051. need to be added to the package.
  1052. 12-6930. Your spec file currently correctly compiles LBreakout2, but it fails to install one
  1053. file which is needed by LBreakout2. To fix this problem, add this file to the
  1054. %files list in the spec file by adding the line:
  1055. %{_localstatedir}/lib/games/lbreakout2.hscr
  1056. When you finish, your Files stanza should now look like:
  1057. %files
  1058. %defattr(-, root, root)
  1059. %doc AUTHORS COPYING ChangeLog NEWS README TODO html
  1060. %{_bindir}/*
  1061. %{_datadir}/games/%{name}
  1062. %{_localstatedir}/lib/games/lbreakout2.hscr
  1063. 31. Once you have made this change, save the spec file and then try once again to
  1064. compile the software and install it to a virtual root directory:
  1065. $ rpmbuild -bi lbreakout2.spec
  1066. ...Output Omitted...
  1067. Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1
  1068. rpmlib(PayloadFilesHavePrefix) <= 4.0-1
  1069. Requires: /sbin/ldconfig libSDL-1.2.so.0 libSDL_mixer-1.2.so.0 libc.so.6
  1070. libc.so.6(GLIBC_2.0) libc.so.6(GLIBC_2.1) libc.so.6(GLIBC_2.1.3)
  1071. libc.so.6(GLIBC_2.3) libm.so.6 libm.so.6(GLIBC_2.0) libpng12.so.0
  1072. libpthread.so.0 libpthread.so.0(GLIBC_2.0) libz.so.1
  1073. Checking for unpackaged file(s): /usr/lib/rpm/check-files
  1074. /var/tmp/lbreakout2-root
  1075. $
  1076. 32. This time, the build worked! To finish packaging your software, edit the spec
  1077. file one final time and update the Changelog with contents similar to the
  1078. following:
  1079. %changelog
  1080. * Tue Apr 02 2005 John Doe <student@gurulabs.com> 2.4.1-1
  1081. - Initial package
  1082. 12-7033. Once you have made this change, save the spec file and then try once again to
  1083. compile the software, install it to a virtual root directory, and package it:
  1084. $ rpmbuild -ba lbreakout2.spec
  1085. Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.1332
  1086. • First, the %prep
  1087. ...Output Omitted...
  1088. Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.1332
  1089. • Next, the %build
  1090. ...Output Omitted...
  1091. Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.41692
  1092. • Next, the %install
  1093. ...Output Omitted...
  1094. Processing files: lbreakout2-2.4.1-3
  1095. • Next, the %files
  1096. Executing(%doc): /bin/sh -e /var/tmp/rpm-tmp.60710
  1097. • The %doc macro in %files
  1098. + umask 022
  1099. + cd /home/guru/rpmbuild/BUILD
  1100. + cd lbreakout2-2.4.1
  1101. + DOCDIR=/var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  1102. + export DOCDIR
  1103. + rm -rf /var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  1104. + /bin/mkdir -p /var/tmp/lbreakout2-root/usr/share/doc/lbreakout2-2.4.1
  1105. + cp -pr AUTHORS COPYING ChangeLog NEWS README TODO html /var/tmp/lbreakout2-
  1106. root/usr/share/doc/lbreakout2-2.4.1
  1107. + exit 0
  1108. Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
  1109. Requires: /sbin/ldconfig libSDL-1.2.so.0 libSDL_mixer-1.2.so.0 libc.so.6 libc.so.6(GLIBC_2.0)
  1110. libc.so.6(GLIBC_2.1) libc.so.6(GLIBC_2.1.3) libc.so.6(GLIBC_2.3) libm.so.6 libm.so.6(GLIBC_2.0)
  1111. libpng12.so.0 libpthread.so.0 libpthread.so.0(GLIBC_2.0) libz.so.1
  1112. Checking for unpackaged file(s): /usr/lib/rpm/check-files /var/tmp/lbreakout2-root
  1113. Wrote: /home/guru/rpmbuild/SRPMS/lbreakout2-2.4.1-3.src.rpm • Next, build the SRPM
  1114. Wrote: /home/guru/rpmbuild/RPMS/i386/lbreakout2-2.4.1-
  1115. • Next, build all RPMs
  1116. 3.i386.rpm
  1117. Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.81877
  1118. • Finish by executing the %clean macro from the %install section
  1119. + umask 022
  1120. + cd /home/guru/rpmbuild/BUILD
  1121. + cd lbreakout2-2.4.1
  1122. + rm -rf /var/tmp/lbreakout2-root
  1123. + exit 0
  1124. $
  1125. 12-7134. You've now got the RPM
  1126. /home/guru/rpmbuild/RPMS/i386/lbreakout2-2.4.1-1.i386.rpm!
  1127. To try it out, install it as root:
  1128. RHEL/FC $ su -c "rpm -Uvh ../RPMS/i386/lbreakout2-2.4.1-1.i386.rpm"
  1129. SLES/SL $ su -c "rpm -Uvh ../RPMS/i586/lbreakout2-2.4.1-1.i586.rpm"
  1130. Password:
  1131. Preparing...
  1132. 1:lbreakout2
  1133. $
  1134. ########################## [100%]
  1135. ########################## [100%]
  1136. 35. Rn the LBreakout2 program to verify that it works:
  1137. $ lbreakout2
  1138. 36. After playing a game of LBreakout2, verify the RPM:
  1139. $ rpmverify -V lbreakout2
  1140. S.5....T
  1141. /var/lib/games/lbreakout2.hscr
  1142. $
  1143. Here, you see that the file /var/lib/games/lbreakout2.hscr has been
  1144. modified in various ways:
  1145. • Its size is modified (S)
  1146. • Its MD5 hash is different, meaning its contents are changed (5)
  1147. • Its timestamps are changed (T)
  1148. 37. Good Linux administrators periodically verify the files on their systems to make
  1149. sure they are not modified, since most installed files should never change.
  1150. However, some files (such as this high scores file) might reasonably be
  1151. modified. RPM allows files which might change to be flagged as configuration
  1152. files, so that administrators verifying the system won’t panic when they notice
  1153. changes to these files.
  1154. To accomodate your administrators, you decide to revise your lbreakout2 RPM.
  1155. Fix your lbreakout2 spec file to indicate that the high-scores file for LBreakout2
  1156. is a configuration file. To do this, edit your spec file and change the line in the
  1157. %files stanza for the high-scores file from:
  1158. %{_localstatedir}/lib/games/lbreakout2.hscr
  1159. 12-72
  1160. • You must be in X for this program to run.
  1161. • This is the high-scores file. It will appear modified, as it does
  1162. here, as long as you’ve beaten one of the previous high scores.to
  1163. %config %{_localstatedir}/lib/games/lbreakout2.hscr
  1164. Also, modify the Release field in the Header stanza, changing it to:
  1165. Release: 2
  1166. Finally, document the change you’ve made to the package by adding an entry
  1167. to the %changelog section similar to the following:
  1168. * Tue Apr 02 2005 John Doe <student@gurulabs.com> 2.4.1-2
  1169. - Mark high-scores file as config file
  1170. • The %config macro in the %files section indicates that the
  1171. packaged file is a configuration file, and might reasonably
  1172. change on a production system.
  1173. 38. Once you have made these three changes to revise your package, save the
  1174. spec file and then try once again to compile the software, install it to a virtual
  1175. root directory, and package it:
  1176. $ rpmbuild -ba lbreakout2.spec
  1177. ...Output Omitted...
  1178. Wrote: /home/guru/rpmbuild/SRPMS/lbreakout2-2.4.1-2.src.rpm
  1179. Wrote: /home/guru/rpmbuild/RPMS/i386/lbreakout2-2.4.1-2.i386.rpm
  1180. ...Output Omitted...
  1181. $
  1182. 39. Now that you’ve built this revised package, upgrade using the -F option to the
  1183. rpm command and test it out:
  1184. RHEL/FC $ su -c "rpm -Fvh ../RPMS/i386/lbreakout2-2.4.1-2.i386.rpm"
  1185. SLES/SL $ su -c "rpm -Fvh ../RPMS/i586/lbreakout2-2.4.1-2.i586.rpm"
  1186. Password:
  1187. Preparing...
  1188. ########################## [100%]
  1189. 1:lbreakout2
  1190. ########################## [100%]
  1191. $ lbreakout2
  1192. 40. Play a couple more games of LBreakout2, making sure to get on the High
  1193. Scores list, then verify the RPM again:
  1194. $ rpmverify -V lbreakout2
  1195. S.5....T c /var/lib/games/lbreakout2.hscr
  1196. $
  1197. 12-73The high-scores file is now correctly flagged as a configuration file (c), so your
  1198. administrators will not panic when they notice it has changed.
  1199. 41. At this point, you have created an RPM from scratch for LBreakout2, and have
  1200. successfully revised it to fix a minor packaging error. Depending on how
  1201. thoroughly you have tested LBreakout2, you might have discovered one other
  1202. problem with your package -- due to a packaging mistake, your LBreakout2
  1203. game does not actually handle high score logging correctly, though you
  1204. probably will not notice this unless you play as multiple different users.
  1205. The basic mistake made here is this: when a program runs on Unix or Linux, it
  1206. normally runs as the user who executes it, which means it only has write access
  1207. to the files which that user can write. For high-score tracking to work correctly
  1208. for LBreakout2, its high-score file, /var/lib/games/lbreakout2.hscr,
  1209. must be writable by every user who runs the lbreakout2 binary.
  1210. To accomplish this, two changes are necessary:
  1211. • The /var/lib/games/lbreakout2.hscr file should have permissions of
  1212. rw-rw-r-- and be owned by the games user and games group
  1213. • The /usr/bin/lbreakout2 file should have permissions of r-xr-sr-x and
  1214. owned by the root user and the games group
  1215. To make these changes, edit your spec file and modify the %files section to
  1216. the following:
  1217. %files
  1218. %defattr(-, root, root)
  1219. %doc AUTHORS COPYING ChangeLog NEWS README TODO html
  1220. %{_bindir}/lbreakout2server
  1221. • List each binary separately, since they need different
  1222. permissions.
  1223. %attr(2555,root,games) %{_bindir}/lbreakout2
  1224. • Make /usr/bin/lbreakout2 belong to the games group and SGID.
  1225. %{_datadir}/games/%{name}
  1226. %defattr(0664,games,games)
  1227. • Make the /var/lib/games/lbreakout2.hscr file group-writable and
  1228. owned by the games group.
  1229. %config %{_localstatedir}/lib/games/lbreakout2.hscr
  1230. Also, modify the Release token in the Header stanza to:
  1231. Release: 3
  1232. Finally, document your changes in the %changelog with a new entry similar to
  1233. the following:
  1234. * Tue Apr 02 2005 John Doe <student@gurulabs.com> 2.4.1-3
  1235. - Make SGID games and fix ownership and perms of
  1236. 12-74high-scores file so that high scores work
  1237. 42. Once you have made these three changes to revise your package, save the
  1238. spec file and then try once again to compile the software, install it to a virtual
  1239. root directory, and package it:
  1240. $ rpmbuild -ba lbreakout2.spec
  1241. ...Output Omitted...
  1242. Wrote: /home/guru/rpmbuild/SRPMS/lbreakout2-2.4.1-3.src.rpm
  1243. Wrote: /home/guru/rpmbuild/RPMS/i386/lbreakout2-2.4.1-3.i386.rpm
  1244. ...Output Omitted...
  1245. $
  1246. 43. Now that you’ve built this revised package, uninstall the existing package and
  1247. install the new package:
  1248. $ su -c "rpm -e lbreakout2"
  1249. Password:
  1250. $ su -c "rpm -Uvh ../RPMS/i386/lbreakout2-2.4.1-3.i386.rpm"
  1251. Password:
  1252. Preparing...
  1253. ########################## [100%]
  1254. 1:lbreakout2
  1255. ########################## [100%]
  1256. $
  1257. 44. Notice the new permissions on the files installed by your revised package:
  1258. $ ls -l /usr/bin/lbreakout2* /var/lib/games/lbreakout2.hscr
  1259. -r-xr-sr-x
  1260. 1 root
  1261. games
  1262. 279698 Apr 29 12:58 /usr/bin/lbreakout2
  1263. -rwxr-xr-x
  1264. 1 root
  1265. root
  1266. 49665 Apr 29 12:58 /usr/bin/lbreakout2server
  1267. -rw-rw-r--
  1268. 1 games
  1269. games
  1270. 227 Apr 29 12:58 /var/lib/games/lbreakout2.hscr
  1271. $
  1272. Congratulations! At this point you have a high-quality, usable RPM for the
  1273. LBreakout2 application which you can give to your users....
  1274. 45. There is one additional customization which you can make to your LBreakout2
  1275. RPM which might be useful to some of your users. RPM supports “sub
  1276. 12-75•
  1277. packages” -- the creation of multiple binary RPMs from a single source RPM
  1278. file. Look at the binaries installed by your current lbreakout2 RPM:
  1279. $ rpm -ql lbreakout2 | grep bin
  1280. /usr/bin/lbreakout2
  1281. /usr/bin/lbreakout2server
  1282. $
  1283. Also, examine the number and size of the graphics and sound files installed by
  1284. LBreakout2:
  1285. $ rpm -ql lbreakout2 | grep "/usr/share/games" | wc -l
  1286. 205
  1287. $ du -sh /usr/share/games/lbreakout2
  1288. 3.4M
  1289. /usr/share/games/lbreakout2
  1290. $
  1291. The /usr/bin/lbreakout2 binary is the stand-alone application users run
  1292. to play LBreakout2. In addition, however, LBreakout2 also provides the
  1293. /usr/bin/lbreakout2server binary. This is a network daemon which can
  1294. be run on a server. Once started on a server, clients can run
  1295. /usr/bin/lbreakout2 on their systems, connect to this server daemon,
  1296. and start a network game of LBreakout2. The directory
  1297. /usr/share/games/lbreakout2 contains 205 files consuming about 3.4
  1298. megabytes of space for artwork required by the client, but not by the server.
  1299. For convenience, you might choose to package LBreakout2 in four files:
  1300. lbreakout2, which provides the client binary
  1301. lbreakout2-server, which provides the server binary
  1302. lbreakout2-graphics, which provides the graphics and sound files needed
  1303. by the client and optionally useful on the server
  1304. lbreakout2-doc, which provides the documentation files
  1305. Splitting LBreakout2 in this fashion will provide your users more flexibility -- they
  1306. can install just the parts of LBreakout2 they need, on just the machines on
  1307. which they need them.
  1308. 46. To split LBreakout2 into sub packages, edit the spec file one final time. Sub
  1309. packages are made simply by adding additional %package and
  1310. %description stanzas to the Header section, then adding additional %files
  1311. stanzas which indicate which files get put in which sub packages. First, add a
  1312. 12-76line to the current %description stanza, indicating that the lbreakout2
  1313. package supplies the LBreakout2 client, like the following:
  1314. This package supplies only the lbreakout2 client, suitable
  1315. for use in single-player games.
  1316. 47. After that %description stanza, add additional %package and
  1317. %description stanzas for the new sub packages:
  1318. %package server
  1319. Summary: lbreakout2 network server
  1320. Group: Amusements/Games
  1321. • The “main” %description and %package information applies to
  1322. the “base” package, in this case lbreakout2
  1323. • Create a new sub package, lbreakout2-server
  1324. %description server
  1325. This package supplies the lbreakout2server daemon, useful for creating
  1326. multi-player LBreakout2 servers
  1327. %package graphics
  1328. Summary: lbreakout2 graphics, sound, and level files
  1329. Group: Amusements/Games
  1330. • Create a new sub package, lbreakout2-graphics
  1331. %description graphics
  1332. This package supplies LBreakout2 graphics, sound, and level files. This package must be installed on
  1333. client systems, and can be installed on server systems if desired.
  1334. %package doc
  1335. Summary: lbreakout2 documentation
  1336. Group: Amusements/Games
  1337. • Create a new sub package, lbreakout2-doc
  1338. %description doc
  1339. This package supplies documentation of LBreakout2.
  1340. 48. Next, split the %files section up into individual sections for each sub
  1341. package. When you finish, your %files section should look something like:
  1342. %files
  1343. %attr(2555,root,games) %{_bindir}/lbreakout2
  1344. %defattr(0664,games,games)
  1345. • Files to put in the lbreakout2 package
  1346. 12-77%config %{_localstatedir}/lib/games/lbreakout2.hscr
  1347. %files server
  1348. %defattr(-, root, root)
  1349. %{_bindir}/lbreakout2server • Files to put in the lbreakout2-server package
  1350. %files graphics
  1351. %defattr(-, root, root)
  1352. %{_datadir}/games/%{name} • Files to put in the lbreakout2-graphics package
  1353. %files doc
  1354. %defattr(-, root, root)
  1355. %doc AUTHORS COPYING ChangeLog NEWS README TODO html • Files to put in the lbreakout2-doc package
  1356. 49. Now, add an entry to the Changelog documenting your latest change, similar to
  1357. the following:
  1358. * Tue Apr 02 2005 John Doe <student@gurulabs.com> 2.4.1-4
  1359. - Split into multiple packages for user convenience
  1360. 50. In the Header stanza, increase the Release field one more time:
  1361. Release: 4
  1362. 51. One additional change is required in the Header stanza. The
  1363. /usr/bin/lbreakout2 binary will not run without the graphics, sound, and
  1364. level files installed, so the lbreakout2 package needs to require the lbreakout2-
  1365. graphics package. Change the Requires field in the Header to require the
  1366. lbreakout2-graphics package:
  1367. Requires: /sbin/ldconfig lbreakout2-graphics
  1368. • The graphics, art, and music files could just be put in the
  1369. lbreakout2 package, but then they could not be installed on the
  1370. server easily without also unnecessarily installing the client....
  1371. 52. Once you have made these changes to revise your package, save the spec file
  1372. and then try once again to compile the software, install it to a virtual root
  1373. directory, and package it:
  1374. $ rpmbuild -ba lbreakout2.spec
  1375. ...Output Omitted...
  1376. Wrote: /export/home/rpmtestuser/rpmbuild/SRPMS/lbreakout2-2.4.1-4.src.rpm
  1377. 12-78Wrote: /export/home/rpmtestuser/rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm
  1378. Wrote: /export/home/rpmtestuser/rpmbuild/RPMS/i386/lbreakout2-server-2.4.1-4.i386.rpm
  1379. Wrote: /export/home/rpmtestuser/rpmbuild/RPMS/i386/lbreakout2-graphics-2.4.1-4.i386.rpm
  1380. Wrote: /export/home/rpmtestuser/rpmbuild/RPMS/i386/lbreakout2-doc-2.4.1-4.i386.rpm
  1381. ...Output Omitted...
  1382. $
  1383. 53. Congratulations! You’ve now packaged LBreakout2 from scratch, creating four
  1384. sub packages from one source package.
  1385. 12-79Task 4
  1386. Create a GPG key pair.
  1387. Sign and verify your LBreakout2 RPMs.
  1388. This lab explores the functionality built into the RPM command for signing
  1389. packages, ensuring package authenticity and integrity.
  1390. 1. In a previous lab task, you created an RPM for the LBreakout2 application. RPM
  1391. provides a variety of built-in integrity and authenticity signatures which can be
  1392. checked on RPM packages. First, check the existing signatures of your
  1393. lbreakout2-2.4.1-4 RPM file:
  1394. RHEL/FC $ rpmsign -K ~/rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm
  1395. SLES/SL $ rpmsign -K ~/rpmbuild/RPMS/i586/lbreakout2-2.4.1-4.i586.rpm
  1396. rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm: sha1 md5 OK • On RPM 4.1 and later, you should see both SHA-1 digests and
  1397. MD5 checksums. On RPM 4.0 and earlier, you should only see
  1398. $
  1399. MD5 checksums. Both MD5 and SHA-1 are used to provide
  1400. Here, you see that the SHA-1 and MD5 signatures of this package are correct.
  1401. digital signatures of the package.
  1402. These are both file integrity checks, assuring you that the contents of the
  1403. package have not been modified.
  1404. 2. RPM also provides the capability to digitally sign packages using GPG or PGP.
  1405. GPG / PGP signatures are useful to the users who install your software because
  1406. these types of signatures allow both the integrity of the package to be verified
  1407. (much like MD5 and SHA-1), and also the authenticity of the package to be
  1408. verified -- if you sign your packages with GPG, your users can be guaranteed
  1409. that the software they install comes from you, and not from someone creating
  1410. Trojan Horses which appear to come from you.
  1411. • The output below is from GnuPG 1.2. Older releases of GnuPG,
  1412. To utilize this GPG functionality, you must first create GPG keys which will be
  1413. such as GnuPG 1.0, will produce different output, and will
  1414. used to sign your packages. To create keys, first run the gpg command to
  1415. actually exit immediately after creating initial configuration files
  1416. create the GPG configuration files in your home directory:
  1417. RHEL/FC $ mkdir ~/.gnupg; chmod 700 ~/.gnupg
  1418. $ gpg
  1419. gpg: /home/guru/.gnupg: directory created
  1420. gpg: new configuration file `/home/guru/.gnupg/gpg.conf' created
  1421. gpg: keyblock resource `/home/guru/.gnupg/secring.gpg': file open error
  1422. gpg: keyring `/home/guru/.gnupg/pubring.gpg' created
  1423. 12-80gpg: Go ahead and type your message ...
  1424. CTRL-C
  1425. gpg: some signal caught ... exiting
  1426. • Press CTRL-C to exit out of gpg. You will not need to do this on
  1427. older versions of gpg.
  1428. $
  1429. 3. Once the GPG configuration files have been created, generate GPG keys:
  1430. $ gpg --gen-key
  1431. gpg (GnuPG) 1.2.6; Copyright (C) 2004 Free Software Foundation, Inc.
  1432. This program comes with ABSOLUTELY NO WARRANTY.
  1433. This is free software, and you are welcome to redistribute it
  1434. under certain conditions. See the file COPYING for details.
  1435. Please select what kind of key you want:
  1436. (1) DSA and ElGamal (default)
  1437. (2) DSA (sign only)
  1438. (5) RSA (sign only)
  1439. Your selection? 1
  1440. DSA keypair will have 1024 bits.
  1441. About to generate a new ELG-E keypair.
  1442. minimum keysize is 768 bits
  1443. default keysize is 1024 bits
  1444. highest suggested keysize is 2048 bits
  1445. What keysize do you want? (1024) 1024
  1446. Requested keysize is 1024 bits
  1447. Please specify how long the key should be valid.
  1448. 0 = key does not expire
  1449. <n> = key expires in n days
  1450. <n>w = key expires in n weeks
  1451. <n>m = key expires in n months
  1452. <n>y = key expires in n years
  1453. Key is valid for? (0) 0
  1454. Key does not expire at all
  1455. Is this correct (y/n)? y
  1456. • Output seen here will vary slightly with GnuPG version. Select
  1457. the default on your version of GnuPG.
  1458. • Select 1 here.
  1459. • 1024 bits is fine here, or 2048 bits if you’re more paranoid.
  1460. • 0 is fine here. In production use, people typically expire keys on a
  1461. periodic basis, however.
  1462. • If you haven’t made any mistakes, say y here. If you have made
  1463. mistakes, say n and correct them.
  1464. 12-81You need a User-ID to identify your key; the software constructs the user id
  1465. from Real Name, Comment and Email Address in this form:
  1466. "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
  1467. Real name: RPM Test
  1468. Email address: guru@gurulabs.com
  1469. Comment: RPM Package Builder
  1470. You selected this USER-ID:
  1471. "RPM Test (RPM Package Builder) <guru@gurulabs.com>" • Enter your first and last name here.
  1472. • Enter your email address.
  1473. • If you want, enter a descriptive comment here.
  1474. Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o • If you haven’t made any mistakes, say o here. If you have made
  1475. mistakes, correct them.
  1476. • Enter a password here. This password is all that prevents
  1477. someone from stealing your key file and impersonating you, so
  1478. guard it carefully.
  1479. You need a Passphrase to protect your secret key.
  1480. Enter passphrase:password
  1481. Repeat passphrase:password
  1482. We need to generate a lot of random bytes. It is a good idea
  1483. to perform some other action (type on the keyboard, move the
  1484. mouse, utilize the disks) during the prime generation; this
  1485. gives the random number
  1486. generator a better chance to gain enough entropy.
  1487. ++++++++++.+++++++++++++++++++++++++++++++++++...++++++++++
  1488. ++++++++++++++++++++..++++++++++++++++++++++++++++++.+++++.
  1489. ...++++++++++....++++++++++>++++++++++..>+++++.<.+++++.....
  1490. .>+++++.....<+++++.>.+++++......<+++++...............+++++
  1491. We need to generate a lot of random bytes. It is a good idea • Entropy (sources of “random” data) are needed by GnuPG. It
  1492. uses seemingly random events like keyboard key presses or
  1493. to perform some other action (type on the keyboard, move the
  1494. mouse movement as sources of entropy. If enough entropy is
  1495. mouse, utilize the disks) during the prime generation; this
  1496. not available, it will actually prompt you to generate more
  1497. gives the random number generator a better chance to gain
  1498. entropy by carrying out activities such as moving the mouse,
  1499. enough entropy.
  1500. typing on the keyboard, or generating hard disk traffic.
  1501. +++++++++++++++++++++++++.++++++++++++++++++++.++++++++++++
  1502. +++.+++++++++++++++++++++++++++++++++++++++++++++.+++++.+++
  1503. +++++++++++++++++>+++++.......+++++^^^
  1504. gpg: /home/guru/.gnupg/trustdb.gpg: trustdb created
  1505. • The output seen here will vary slightly with GnuPG version.
  1506. public and secret key created and signed.
  1507. key marked as ultimately trusted.
  1508. 12-82pub
  1509. sub
  1510. 1024D/87786C00 2003-04-29 RPM Test (RPM Package Builder) <guru@gurulabs.com>
  1511. Key fingerprint = 24ED F0C7 2148 E88C 51B8 1CA2 8D2A FB9A 8778 6C00
  1512. 1024g/9B24A1DC 2003-04-29
  1513. $
  1514. 4. At this point, you have generated public and private GPG keys. To verify that
  1515. they were created correctly, you can view them:
  1516. $ gpg --list-keys
  1517. /home/guru/.gnupg/pubring.gpg
  1518. --------------------------
  1519. pub 1024D/87786C00 2003-04-29 RPM Test (RPM Package Builder) <guru@gurulabs.com>
  1520. sub 1024g/9B24A1DC 2003-04-29
  1521. $
  1522. 5. Now that you have created a GPG key, you must configure RPM to allow you to
  1523. use it. First, configure RPM to use GPG:
  1524. $ echo "%_signature gpg" >> ~/.rpmmacros
  1525. $ echo "%_gpg_path $HOME/.gnupg" >> ~/.rpmmacros
  1526. $
  1527. Also, configure RPM to locate the GPG key you just created:
  1528. $ echo "%_gpg_name guru@gurulabs.com" >> ~/.rpmmacros
  1529. • Make sure you use the same email address here you used in
  1530. step 3 when you generated your GPG keys.
  1531. $
  1532. 6. Once RPM is configured to support GPG, use it to sign a package with your
  1533. new GPG private key:
  1534. RHEL/FC $ rpmsign --addsign ~/rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm
  1535. SLES/SL $ rpmsign --addsign ~/rpmbuild/RPMS/i586/lbreakout2-2.4.1-4.i586.rpm
  1536. Enter pass phrase: password
  1537. • Enter your GPG password that you created in step 3.
  1538. Pass phrase is good.
  1539. rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm:
  1540. $
  1541. 12-837. Next, examine the signatures of your freshly signed package. If you are using
  1542. RPM 4.0 or older, you will see:
  1543. RHEL/FC $ rpmsign -K ~/rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm
  1544. SLES/SL $ rpmsign -K ~/rpmbuild/RPMS/i586/lbreakout2-2.4.1-4.i586.rpm
  1545. rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm: md5 gpg OK
  1546. $
  1547. This indicates that the package has a correct MD5 signature, is signed using
  1548. • When you generated your public and private key pair in step 3,
  1549. GPG automatically added your public key to your personal public
  1550. GPG, and that the GPG signature of the package can be decrypted using a GPG
  1551. keyring. When you ran rpmsign -K, rpmsign used this
  1552. public key on your GPG keyring. Congratulations! You have signed a package,
  1553. public
  1554. key to decrypt the GPG signature within the package file.
  1555. and verified that it is correctly signed. You may skip the rest of the steps in this
  1556. lab; they are only necessary for users running RPM 4.1 and newer releases.
  1557. 8. If you are using RPM 4.1 and newer releases, when you examine the signatures
  1558. of your package, you will instead see:
  1559. RHEL/FC $ rpmsign -K ~/rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm
  1560. SLES/SL $ rpmsign -K ~/rpmbuild/RPMS/i586/lbreakout2-2.4.1-4.i586.rpm
  1561. rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm: (SHA1) DSA
  1562. sha1 md5 (GPG) NOT OK (MISSING KEYS: GPG#87786c00)
  1563. $
  1564. Although your package is signed with your correct GPG key, it still shows up as
  1565. NOT OK with RPM 4.1 and newer releases. This is because RPM 4.1 and newer
  1566. releases use their own separate GPG keyring, rather than reading the keyring of
  1567. the user running the RPM command. RPM is trying to verify the signature on
  1568. your package using the RPM GPG keyring, and RPM does not yet have your
  1569. public key installed on its keyring, so it cannot verify the signature.
  1570. 9. To correct this, you will first need to export your public key in a format RPM can
  1571. understand. To see your public key, use the command:
  1572. $ gpg --export --armor
  1573. • Fortunately, this output makes more sense to the GPG software
  1574. than it does to you!
  1575. -----BEGIN PGP PUBLIC KEY BLOCK-----
  1576. Version: GnuPG v1.2.1 (GNU/Linux)
  1577. mQGiBD6u2hQRBAC1wEn+cJvjz8P94ogeE/PCwX4mUBbY4QvKiklrXgr+bpD
  1578. d9OmaM+JqbnqyBIq9KfsxVLK651VFB7jBqKwzjBVQER+xsDJW79vKE2mDv0
  1579. zNRJuxG2ull8iwwlyub3H9Jky+VXJ4upA3CxhwDRMjZ1PShhJzPSX0paHwC
  1580. 12-84x29FQOTKZ6tfgDopoDbq4bUD/1rwocepHES4EOrzz4TVKXAtwASP+Z18OkI
  1581. RPmRQ2nkawnRMhIl+taTcbjBJapm1YiKAyqkGwiWtBMTQER9Ox+Uz1p4SmQ
  1582. VO0SAGpi+2jjmD79ViRAqdAd+JcgLSI8c9TEZo3D3UFWZI/8yv5PHJMgGQo
  1583. nmbFA/0XeJH5aluTFgFnJCP2JMFvMDG2SwiGmwOyDiAWZ7/RTulOt7Y8fMk
  1584. OgLlN9wsAZ6JNCmkUP/jiQFYpyMULI1Soca2h+PKYUenEjmwo1LRWUGkdLa
  1585. 3t8PA92mAhcJynRG+JEEYL5x3NHDVSIzBxz3mTedWj7YQLkkCrRBVGVzdCB
  1586. YWdlIChSUE0gUGFja2FnZSBCdWlsZGVyKSA8a2Fib29tQHdpbnN1Y2tzLmd
  1587. YWJzLmNvbT6IWQQTEQIAGQUCPq7aFAQLBwMCAxUCAwMWAgECHgECF4AACgk
  1588. mod4bABO7QCfWJoP+QFploVay2FPAskbrle4DjgAnAhdbdFJ27Wbolk1xob
  1589. IPd/uQENBD6u2hUQBACOgzjL5Wz0Tg/avYSfiswAC5wwKGXTxG9RZPF3cdB
  1590. F/k2KsFpoDg/5p9nzSM/h3MjH+1Lr/ZOJgMr/Bz8TunnJg+I+vx00vh0Tw2
  1591. tV3B+0jx+ots3A+Opmn77eUGSm+lOv1PQYfQ9kwRsE7+BO9ylgHsrbx9myA
  1592. BQP/aJl2yC5H9MTyiK8PvVzr2hrAdykZYGCmJzcmSJ1guiLEgQ7qG0i3Ycm
  1593. z+YxIvon42w6EqaoDBp9RHkK2KQpuvNgQfUSMUcr5tIUf3EqDAy37wgdFPx
  1594. eh4yem1zigQ12M/Vk5BkQGBs/8Ol+7VfZ1pvgtvZiXtKSoqIRgQYEQIABgU
  1595. FQAKCRCNKvuah3hsAGH6AJ9jgyNiBSEf9a5LcetnZqQez/a9dwCfeNEmgUo
  1596. /ZxE3l/sTe5Nb+8=
  1597. =OnkZ
  1598. -----END PGP PUBLIC KEY BLOCK-----
  1599. $
  1600. 10. Now, save your GPG public key to a file:
  1601. $ gpg --export --armor > /tmp/gpg-public-key.asc
  1602. $
  1603. 11. Next, import your public key into RPM’s GPG keyring:
  1604. $ su -c "rpmsign --import /tmp/gpg-public-key.asc"
  1605. Password:
  1606. $
  1607. 12. Once your public key is imported into the RPM GPG keyring, examine the
  1608. signed LBreakout2 package signatures again:
  1609. $ rpmsign -K ~/rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm
  1610. rpmbuild/RPMS/i386/lbreakout2-2.4.1-4.i386.rpm: (sha1) dsa sha1 md5 gpg OK
  1611. $
  1612. 12-8513. This time, your GPG signature verified correctly because RPM now has your
  1613. GPG public key installed correctly. You can also give your GPG public key to
  1614. your users, and they can import it into RPM using the same process you did in
  1615. step 11. Once they have imported your public key, they can verify the
  1616. authenticity and integrity of any RPMs you create for them!
  1617. 12-86
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement