srpm 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #! /bin/sh
  2. #
  3. # Written by Erik Troan (ewt@redhat.com) 1996
  4. # Jakub Jelinek (jj@sunsite.mff.cuni.cz) 1996,2004
  5. # Tomasz K³oczko (kloczek@rudy.mif.pg.gda.pl) 1997
  6. # minor changes by Wojtek Pilorz (wpilorz@bdk.lublin.pl) 1997
  7. # minor changes by Michele Marziani (marziani@fe.infn.it) 1997
  8. # bug files by Marc Merlin (marcsoft@merlins.org) 1998
  9. # locale bugfix by Michal Svec (rebel@penguin.cz) 2000
  10. # Whitespace(s) & single quote(s) in filename workaround
  11. # by Andrew V. Samoilov <sav@bcs.zp.ua> 2004
  12. # https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=64007
  13. #
  14. # (C) 1996-2004 The Free Software Foundation.
  15. #
  16. # override any locale for dates
  17. unset LC_ALL
  18. LC_TIME=C
  19. export LC_TIME
  20. if rpmbuild --version >/dev/null 2>&1; then
  21. RPMBUILD="rpmbuild"
  22. else
  23. RPMBUILD="rpm"
  24. fi
  25. if rpm --nosignature --version >/dev/null 2>&1; then
  26. RPM="rpm --nosignature"
  27. RPMBUILD="$RPMBUILD --nosignature"
  28. else
  29. RPM="rpm"
  30. fi
  31. RPM2CPIO="rpm2cpio"
  32. SED="sed"
  33. # Surround the whole filename with single quotes and handle specially
  34. # \', ' and \ at the end of the string.
  35. SEDCMD="s/\\(\\\\\\?\\)'/'\\1\\1\\\\''/g;s/\\\\\$/'\\\\\\\\'/;s/^/'/;s/\$/'/"
  36. mcrpmfs_list ()
  37. {
  38. # set MCFASTRPM_DFLT to 1 for faster rpm files handling by default, to 0 for
  39. # slower handling
  40. MCFASTRPM_DFLT=0
  41. if test -z "$MCFASTRPM"; then
  42. MCFASTRPM=$MCFASTRPM_DFLT
  43. fi
  44. f="`echo "$1" | $SED "$SEDCMD"`"
  45. FILEPREF="-r--r--r-- 1 root root "
  46. DESC=`$RPM -qip "$f" 2>/dev/null` || {
  47. echo "$FILEPREF 0 "`date +"%b %d %H:%M"`" ERROR"
  48. exit 1
  49. }
  50. DATE=`$RPM -qp --qf "%{BUILDTIME:date}\n" "$f" | cut -c 5-11,21-24`
  51. HEADERSIZE=`echo "$DESC" | wc -c`
  52. echo "-r--r--r-- 1 root root $HEADERSIZE $DATE HEADER"
  53. echo "-r-xr-xr-x 1 root root 39 $DATE INSTALL"
  54. echo "-r-xr-xr-x 1 root root 39 $DATE REBUILD"
  55. echo "dr-xr-xr-x 3 root root 0 $DATE INFO"
  56. echo "$FILEPREF 0 $DATE INFO/NAME-VERSION-RELEASE"
  57. echo "$FILEPREF 0 $DATE INFO/GROUP"
  58. echo "$FILEPREF 0 $DATE INFO/BUILDHOST"
  59. echo "$FILEPREF 0 $DATE INFO/SOURCERPM"
  60. if test "$MCFASTRPM" = 0 ; then
  61. test "`$RPM -qp --qf \"%{DISTRIBUTION}\" \"$f\"`" = "(none)" ||
  62. echo "$FILEPREF 0 $DATE INFO/DISTRIBUTION"
  63. test "`$RPM -qp --qf \"%{VENDOR}\" \"$f\"`" = "(none)" ||
  64. echo "$FILEPREF 0 $DATE INFO/VENDOR"
  65. test "`$RPM -qp --qf \"%{DESCRIPTION}\" \"$f\"`" = "(none)" ||
  66. echo "$FILEPREF 0 $DATE INFO/DESCRIPTION"
  67. test "`$RPM -qp --qf \"%{SUMMARY}\" \"$f\"`" = "(none)" ||
  68. echo "$FILEPREF 0 $DATE INFO/SUMMARY"
  69. if test "`$RPM -qp --qf \"%{RPMTAG_PREIN}%{RPMTAG_POSTIN}%{RPMTAG_PREUN}%{RPMTAG_POSTUN}%{VERIFYSCRIPT}\" \"$f\"`" != "(none)(none)(none)(none)(none)"; then
  70. echo "dr-xr-xr-x 1 root root 0 $DATE INFO/SCRIPTS"
  71. test "`$RPM -qp --qf \"%{RPMTAG_PREIN}\" \"$f\"`" = '(none)' ||
  72. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREIN"
  73. test "`$RPM -qp --qf \"%{RPMTAG_POSTIN}\" \"$f\"`" = '(none)' ||
  74. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTIN"
  75. test "`$RPM -qp --qf \"%{RPMTAG_PREUN}\" \"$f\"`" = '(none)' ||
  76. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREUN"
  77. test "`$RPM -qp --qf \"%{RPMTAG_POSTUN}\" \"$f\"`" = '(none)' ||
  78. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTUN"
  79. test "`$RPM -qp --qf \"%{VERIFYSCRIPT}\" \"$f\"`" = '(none)' ||
  80. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/VERIFYSCRIPT"
  81. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/ALL"
  82. fi
  83. else
  84. echo "$FILEPREF 0 $DATE INFO/DISTRIBUTION"
  85. echo "$FILEPREF 0 $DATE INFO/VENDOR"
  86. echo "$FILEPREF 0 $DATE INFO/DESCRIPTION"
  87. echo "$FILEPREF 0 $DATE INFO/SUMMARY"
  88. echo "dr-xr-xr-x 1 root root 0 $DATE INFO/SCRIPTS"
  89. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREIN"
  90. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTIN"
  91. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREUN"
  92. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTUN"
  93. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/VERIFYSCRIPT"
  94. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/ALL"
  95. fi
  96. if test "$MCFASTRPM" = 0 ; then
  97. test "`$RPM -qp --qf \"%{PACKAGER}\" \"$f\"`" = "(none)" ||
  98. echo "$FILEPREF 0 $DATE INFO/PACKAGER"
  99. test "`$RPM -qp --qf \"%{URL}\" \"$f\"`" = "(none)" ||
  100. echo "$FILEPREF 0 $DATE INFO/URL"
  101. test "`$RPM -qp --qf \"%{EPOCH}\" \"$f\"`" = "(none)" ||
  102. echo "$FILEPREF 0 $DATE INFO/EPOCH"
  103. test "`$RPM -qp --qf \"%{LICENSE}\" \"$f\"`" = "(none)" ||
  104. echo "$FILEPREF 0 $DATE INFO/LICENSE"
  105. else
  106. echo "$FILEPREF 0 $DATE INFO/PACKAGER"
  107. echo "$FILEPREF 0 $DATE INFO/URL"
  108. echo "$FILEPREF 0 $DATE INFO/EPOCH"
  109. echo "$FILEPREF 0 $DATE INFO/LICENSE"
  110. fi
  111. echo "$FILEPREF 0 $DATE INFO/BUILDTIME"
  112. echo "$FILEPREF 0 $DATE INFO/RPMVERSION"
  113. echo "$FILEPREF 0 $DATE INFO/OS"
  114. echo "$FILEPREF 0 $DATE INFO/SIZE"
  115. if test "$MCFASTRPM" != 0 ; then
  116. $RPM -qp --qf "[%{REQUIRENAME}\n]" "$f" | grep "(none)" > /dev/null ||
  117. echo "$FILEPREF 0 $DATE INFO/REQUIRENAME"
  118. $RPM -qp --qf "[%{OBSOLETES}\n]" "$f" | grep "(none)" > /dev/null ||
  119. echo "$FILEPREF 0 $DATE INFO/OBSOLETES"
  120. $RPM -qp --qf "[%{PROVIDES}\n]" "$f" | grep "(none)" > /dev/null ||
  121. echo "$FILEPREF 0 $DATE INFO/PROVIDES"
  122. $RPM -qp --qf "[%{CONFLICTS}\n]" "$f" | grep "(none)" > /dev/null ||
  123. echo "$FILEPREF 0 $DATE INFO/CONFLICTS"
  124. test "`$RPM -qp --qf \"%{CHANGELOGTEXT}\" \"$f\"`" = "(none)" ||
  125. echo "$FILEPREF 0 $DATE INFO/CHANGELOG"
  126. else
  127. echo "$FILEPREF 0 $DATE INFO/REQUIRENAME"
  128. echo "$FILEPREF 0 $DATE INFO/OBSOLETES"
  129. echo "$FILEPREF 0 $DATE INFO/PROVIDES"
  130. echo "$FILEPREF 0 $DATE INFO/CONFLICTS"
  131. echo "$FILEPREF 0 $DATE INFO/CHANGELOG"
  132. fi
  133. echo "$FILEPREF 0 $DATE CONTENTS.cpio"
  134. }
  135. mcrpmfs_copyout ()
  136. {
  137. f="`echo "$1" | $SED "$SEDCMD"`"
  138. case "$2" in
  139. HEADER) $RPM -qip "$f" > "$3"; exit 0;;
  140. INSTALL) echo "# Run this to install this RPM package" > "$3"; exit 0;;
  141. REBUILD) echo "# Run this to rebuild this RPM package" > "$3"; exit 0;;
  142. ERROR) $RPM -qip "$f" > /dev/null 2> "$3"; exit 0;;
  143. INFO/NAME-VERSION-RELEASE) $RPM -qp --qf "%{NAME}-%{VERSION}-%{RELEASE}\n" "$f" > "$3"; exit 0;;
  144. INFO/RELEASE) $RPM -qp --qf "%{RELEASE}\n" "$f" > "$3"; exit 0;;
  145. INFO/GROUP) $RPM -qp --qf "%{GROUP}\n" "$f" > "$3"; exit 0;;
  146. INFO/DISTRIBUTION) $RPM -qp --qf "%{DISTRIBUTION}\n" "$f" > "$3"; exit 0;;
  147. INFO/VENDOR) $RPM -qp --qf "%{VENDOR}\n" "$f" > "$3"; exit 0;;
  148. INFO/BUILDHOST) $RPM -qp --qf "%{BUILDHOST}\n" "$f" > "$3"; exit 0;;
  149. INFO/SOURCERPM) $RPM -qp --qf "%{SOURCERPM}\n" "$f" > "$3"; exit 0;;
  150. INFO/DESCRIPTION) $RPM -qp --qf "%{DESCRIPTION}\n" "$f" > "$3"; exit 0;;
  151. INFO/PACKAGER) $RPM -qp --qf "%{PACKAGER}\n" "$f" > "$3"; exit 0;;
  152. INFO/URL) $RPM -qp --qf "%{URL}\n" "$f" >"$3"; exit 0;;
  153. INFO/BUILDTIME) $RPM -qp --qf "%{BUILDTIME:date}\n" "$f" >"$3"; exit 0;;
  154. INFO/EPOCH) $RPM -qp --qf "%{EPOCH}\n" "$f" >"$3"; exit 0;;
  155. INFO/LICENSE) $RPM -qp --qf "%{LICENSE}\n" "$f" >"$3"; exit 0;;
  156. INFO/RPMVERSION) $RPM -qp --qf "%{RPMVERSION}\n" "$f" >"$3"; exit 0;;
  157. INFO/REQUIRENAME) $RPM -qp --qf "[%{REQUIRENAME} %{REQUIREFLAGS:depflags} %{REQUIREVERSION}\n]" "$f" >"$3"; exit 0;;
  158. INFO/PROVIDES) $RPM -qp --qf "[%{PROVIDES}\n]" "$f" >"$3"; exit 0;;
  159. INFO/SCRIPTS/PREIN) $RPM -qp --qf "%{RPMTAG_PREIN}\n" "$f" >"$3"; exit 0;;
  160. INFO/SCRIPTS/POSTIN) $RPM -qp --qf "%{RPMTAG_POSTIN}\n" "$f" >"$3"; exit 0;;
  161. INFO/SCRIPTS/PREUN) $RPM -qp --qf "%{RPMTAG_PREUN}\n" "$f" >"$3"; exit 0;;
  162. INFO/SCRIPTS/POSTUN) $RPM -qp --qf "%{RPMTAG_POSTUN}\n" "$f" >"$3"; exit 0;;
  163. INFO/SCRIPTS/VERIFYSCRIPT) $RPM -qp --qf "%{VERIFYSCRIPT}\n" "$f" >"$3"; exit 0;;
  164. INFO/SCRIPTS/ALL) $RPM -qp --scripts "$f" > "$3"; exit 0;;
  165. INFO/SUMMARY) $RPM -qp --qf "%{SUMMARY}\n" "$f" > "$3"; exit 0;;
  166. INFO/OS) $RPM -qp --qf "%{OS}\n" "$f" > "$3"; exit 0;;
  167. INFO/CHANGELOG) $RPM -qp --qf "[* %{CHANGELOGTIME:date} %{CHANGELOGNAME}\n%{CHANGELOGTEXT}\n\n]\n" "$f" > "$3"; exit 0;;
  168. INFO/SIZE) $RPM -qp --qf "%{SIZE} bytes\n" "$f" > "$3"; exit 0;;
  169. INFO/OBSOLETES) $RPM -qp --qf "[%{OBSOLETENAME} %|OBSOLETEFLAGS?{%{OBSOLETEFLAGS:depflags} %{OBSOLETEVERSION}}:{}|\n]" "$f" > "$3"; exit 0;;
  170. INFO/CONFLICTS) $RPM -qp --qf "[%{CONFLICTNAME} %{CONFLICTFLAGS:depflags} %{CONFLICTVERSION}\n]" "$f" >"$3"; exit 0;;
  171. CONTENTS.cpio) $RPM2CPIO "$1" > "$3"; exit 0;;
  172. *)
  173. ;;
  174. esac
  175. }
  176. mcrpmfs_run ()
  177. {
  178. f="`echo "$1" | $SED "$SEDCMD"`"
  179. case "$2" in
  180. INSTALL) echo "Installing \"\"$f\"\""; $RPM -ivh "$f"; exit 0;;
  181. REBUILD) echo "Rebuilding \"$1\""; $RPMBUILD --rebuild "$1"; exit 0;;
  182. esac
  183. }
  184. umask 077
  185. case "$1" in
  186. list) mcrpmfs_list "$2"; exit 0;;
  187. copyout) mcrpmfs_copyout "$2" "$3" "$4"; exit 0;;
  188. run) mcrpmfs_run "$2" "$3"; exit 1;;
  189. esac
  190. exit 1