rpm 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 rpm --nosignature --version >/dev/null 2>&1; then
  21. RPM="rpm --nosignature"
  22. else
  23. RPM="rpm"
  24. fi
  25. RPM2CPIO="rpm2cpio"
  26. SED="sed"
  27. # Surround the whole filename with single quotes and handle specially
  28. # \', ' and \ at the end of the string.
  29. SEDCMD="s/\\(\\\\\\?\\)'/'\\1\\1\\\\''/g;s/\\\\\$/'\\\\\\\\'/;s/^/'/;s/\$/'/"
  30. mcrpmfs_list ()
  31. {
  32. # set MCFASTRPM_DFLT to 1 for faster rpm files handling by default, to 0 for
  33. # slower handling
  34. MCFASTRPM_DFLT=0
  35. if test -z "$MCFASTRPM"; then
  36. MCFASTRPM=$MCFASTRPM_DFLT
  37. fi
  38. f="`echo "$1" | $SED "$SEDCMD"`"
  39. FILEPREF="-r--r--r-- 1 root root "
  40. DESC=`$RPM -qip "$f" 2>/dev/null` || {
  41. echo "$FILEPREF 0 "`date +"%b %d %H:%M"`" ERROR"
  42. exit 1
  43. }
  44. DATE=`$RPM -qp --qf "%{BUILDTIME:date}\n" "$f" | cut -c 5-11,21-24`
  45. HEADERSIZE=`echo "$DESC" | wc -c`
  46. echo "-r--r--r-- 1 root root $HEADERSIZE $DATE HEADER"
  47. echo "-r-xr-xr-x 1 root root 39 $DATE INSTALL"
  48. echo "-r-xr-xr-x 1 root root 39 $DATE UPGRADE"
  49. echo "dr-xr-xr-x 3 root root 0 $DATE INFO"
  50. echo "$FILEPREF 0 $DATE INFO/NAME-VERSION-RELEASE"
  51. echo "$FILEPREF 0 $DATE INFO/GROUP"
  52. echo "$FILEPREF 0 $DATE INFO/BUILDHOST"
  53. echo "$FILEPREF 0 $DATE INFO/SOURCERPM"
  54. if test "$MCFASTRPM" = 0 ; then
  55. test "`$RPM -qp --qf \"%{DISTRIBUTION}\" \"$f\"`" = "(none)" ||
  56. echo "$FILEPREF 0 $DATE INFO/DISTRIBUTION"
  57. test "`$RPM -qp --qf \"%{VENDOR}\" \"$f\"`" = "(none)" ||
  58. echo "$FILEPREF 0 $DATE INFO/VENDOR"
  59. test "`$RPM -qp --qf \"%{DESCRIPTION}\" \"$f\"`" = "(none)" ||
  60. echo "$FILEPREF 0 $DATE INFO/DESCRIPTION"
  61. test "`$RPM -qp --qf \"%{SUMMARY}\" \"$f\"`" = "(none)" ||
  62. echo "$FILEPREF 0 $DATE INFO/SUMMARY"
  63. if test "`$RPM -qp --qf \"%{RPMTAG_PREIN}%{RPMTAG_POSTIN}%{RPMTAG_PREUN}%{RPMTAG_POSTUN}%{VERIFYSCRIPT}\" \"$f\"`" != "(none)(none)(none)(none)(none)"; then
  64. echo "dr-xr-xr-x 1 root root 0 $DATE INFO/SCRIPTS"
  65. test "`$RPM -qp --qf \"%{RPMTAG_PREIN}\" \"$f\"`" = '(none)' ||
  66. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREIN"
  67. test "`$RPM -qp --qf \"%{RPMTAG_POSTIN}\" \"$f\"`" = '(none)' ||
  68. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTIN"
  69. test "`$RPM -qp --qf \"%{RPMTAG_PREUN}\" \"$f\"`" = '(none)' ||
  70. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREUN"
  71. test "`$RPM -qp --qf \"%{RPMTAG_POSTUN}\" \"$f\"`" = '(none)' ||
  72. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTUN"
  73. test "`$RPM -qp --qf \"%{VERIFYSCRIPT}\" \"$f\"`" = '(none)' ||
  74. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/VERIFYSCRIPT"
  75. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/ALL"
  76. fi
  77. else
  78. echo "$FILEPREF 0 $DATE INFO/DISTRIBUTION"
  79. echo "$FILEPREF 0 $DATE INFO/VENDOR"
  80. echo "$FILEPREF 0 $DATE INFO/DESCRIPTION"
  81. echo "$FILEPREF 0 $DATE INFO/SUMMARY"
  82. echo "dr-xr-xr-x 1 root root 0 $DATE INFO/SCRIPTS"
  83. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREIN"
  84. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTIN"
  85. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREUN"
  86. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTUN"
  87. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/VERIFYSCRIPT"
  88. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/ALL"
  89. fi
  90. if test "$MCFASTRPM" = 0 ; then
  91. test "`$RPM -qp --qf \"%{PACKAGER}\" \"$f\"`" = "(none)" ||
  92. echo "$FILEPREF 0 $DATE INFO/PACKAGER"
  93. test "`$RPM -qp --qf \"%{URL}\" \"$f\"`" = "(none)" ||
  94. echo "$FILEPREF 0 $DATE INFO/URL"
  95. test "`$RPM -qp --qf \"%{EPOCH}\" \"$f\"`" = "(none)" ||
  96. echo "$FILEPREF 0 $DATE INFO/EPOCH"
  97. test "`$RPM -qp --qf \"%{LICENSE}\" \"$f\"`" = "(none)" ||
  98. echo "$FILEPREF 0 $DATE INFO/LICENSE"
  99. else
  100. echo "$FILEPREF 0 $DATE INFO/PACKAGER"
  101. echo "$FILEPREF 0 $DATE INFO/URL"
  102. echo "$FILEPREF 0 $DATE INFO/EPOCH"
  103. echo "$FILEPREF 0 $DATE INFO/LICENSE"
  104. fi
  105. echo "$FILEPREF 0 $DATE INFO/BUILDTIME"
  106. echo "$FILEPREF 0 $DATE INFO/RPMVERSION"
  107. echo "$FILEPREF 0 $DATE INFO/OS"
  108. echo "$FILEPREF 0 $DATE INFO/SIZE"
  109. if test "$MCFASTRPM" != 0 ; then
  110. $RPM -qp --qf "[%{REQUIRENAME}\n]" "$f" | grep "(none)" > /dev/null ||
  111. echo "$FILEPREF 0 $DATE INFO/REQUIRENAME"
  112. $RPM -qp --qf "[%{OBSOLETES}\n]" "$f" | grep "(none)" > /dev/null ||
  113. echo "$FILEPREF 0 $DATE INFO/OBSOLETES"
  114. $RPM -qp --qf "[%{PROVIDES}\n]" "$f" | grep "(none)" > /dev/null ||
  115. echo "$FILEPREF 0 $DATE INFO/PROVIDES"
  116. $RPM -qp --qf "[%{CONFLICTS}\n]" "$f" | grep "(none)" > /dev/null ||
  117. echo "$FILEPREF 0 $DATE INFO/CONFLICTS"
  118. test "`$RPM -qp --qf \"%{CHANGELOGTEXT}\" \"$f\"`" = "(none)" ||
  119. echo "$FILEPREF 0 $DATE INFO/CHANGELOG"
  120. else
  121. echo "$FILEPREF 0 $DATE INFO/REQUIRENAME"
  122. echo "$FILEPREF 0 $DATE INFO/OBSOLETES"
  123. echo "$FILEPREF 0 $DATE INFO/PROVIDES"
  124. echo "$FILEPREF 0 $DATE INFO/CONFLICTS"
  125. echo "$FILEPREF 0 $DATE INFO/CHANGELOG"
  126. fi
  127. echo "$FILEPREF 0 $DATE CONTENTS.cpio"
  128. }
  129. mcrpmfs_copyout ()
  130. {
  131. f="`echo "$1" | $SED "$SEDCMD"`"
  132. case "$2" in
  133. HEADER) $RPM -qip "$f" > "$3"; exit 0;;
  134. INSTALL) echo "# Run this to install this RPM package" > "$3"; exit 0;;
  135. UPGRADE) echo "# Run this to upgrade this RPM package" > "$3"; exit 0;;
  136. ERROR) $RPM -qip "$f" > /dev/null 2> "$3"; exit 0;;
  137. INFO/NAME-VERSION-RELEASE) $RPM -qp --qf "%{NAME}-%{VERSION}-%{RELEASE}\n" "$f" > "$3"; exit 0;;
  138. INFO/RELEASE) $RPM -qp --qf "%{RELEASE}\n" "$f" > "$3"; exit 0;;
  139. INFO/GROUP) $RPM -qp --qf "%{GROUP}\n" "$f" > "$3"; exit 0;;
  140. INFO/DISTRIBUTION) $RPM -qp --qf "%{DISTRIBUTION}\n" "$f" > "$3"; exit 0;;
  141. INFO/VENDOR) $RPM -qp --qf "%{VENDOR}\n" "$f" > "$3"; exit 0;;
  142. INFO/BUILDHOST) $RPM -qp --qf "%{BUILDHOST}\n" "$f" > "$3"; exit 0;;
  143. INFO/SOURCERPM) $RPM -qp --qf "%{SOURCERPM}\n" "$f" > "$3"; exit 0;;
  144. INFO/DESCRIPTION) $RPM -qp --qf "%{DESCRIPTION}\n" "$f" > "$3"; exit 0;;
  145. INFO/PACKAGER) $RPM -qp --qf "%{PACKAGER}\n" "$f" > "$3"; exit 0;;
  146. INFO/URL) $RPM -qp --qf "%{URL}\n" "$f" >"$3"; exit 0;;
  147. INFO/BUILDTIME) $RPM -qp --qf "%{BUILDTIME:date}\n" "$f" >"$3"; exit 0;;
  148. INFO/EPOCH) $RPM -qp --qf "%{EPOCH}\n" "$f" >"$3"; exit 0;;
  149. INFO/LICENSE) $RPM -qp --qf "%{LICENSE}\n" "$f" >"$3"; exit 0;;
  150. INFO/RPMVERSION) $RPM -qp --qf "%{RPMVERSION}\n" "$f" >"$3"; exit 0;;
  151. INFO/REQUIRENAME) $RPM -qp --qf "[%{REQUIRENAME} %{REQUIREFLAGS:depflags} %{REQUIREVERSION}\n]" "$f" >"$3"; exit 0;;
  152. INFO/PROVIDES) $RPM -qp --qf "[%{PROVIDES}\n]" "$f" >"$3"; exit 0;;
  153. INFO/SCRIPTS/PREIN) $RPM -qp --qf "%{RPMTAG_PREIN}\n" "$f" >"$3"; exit 0;;
  154. INFO/SCRIPTS/POSTIN) $RPM -qp --qf "%{RPMTAG_POSTIN}\n" "$f" >"$3"; exit 0;;
  155. INFO/SCRIPTS/PREUN) $RPM -qp --qf "%{RPMTAG_PREUN}\n" "$f" >"$3"; exit 0;;
  156. INFO/SCRIPTS/POSTUN) $RPM -qp --qf "%{RPMTAG_POSTUN}\n" "$f" >"$3"; exit 0;;
  157. INFO/SCRIPTS/VERIFYSCRIPT) $RPM -qp --qf "%{VERIFYSCRIPT}\n" "$f" >"$3"; exit 0;;
  158. INFO/SCRIPTS/ALL) $RPM -qp --scripts "$f" > "$3"; exit 0;;
  159. INFO/SUMMARY) $RPM -qp --qf "%{SUMMARY}\n" "$f" > "$3"; exit 0;;
  160. INFO/OS) $RPM -qp --qf "%{OS}\n" "$f" > "$3"; exit 0;;
  161. INFO/CHANGELOG) $RPM -qp --qf "[* %{CHANGELOGTIME:date} %{CHANGELOGNAME}\n%{CHANGELOGTEXT}\n\n]\n" "$f" > "$3"; exit 0;;
  162. INFO/SIZE) $RPM -qp --qf "%{SIZE} bytes\n" "$f" > "$3"; exit 0;;
  163. INFO/OBSOLETES) $RPM -qp --qf "[%{OBSOLETENAME} %|OBSOLETEFLAGS?{%{OBSOLETEFLAGS:depflags} %{OBSOLETEVERSION}}:{}|\n]" "$f" > "$3"; exit 0;;
  164. INFO/CONFLICTS) $RPM -qp --qf "[%{CONFLICTNAME} %{CONFLICTFLAGS:depflags} %{CONFLICTVERSION}\n]" "$f" >"$3"; exit 0;;
  165. CONTENTS.cpio) $RPM2CPIO "$1" > "$3"; exit 0;;
  166. *)
  167. ;;
  168. esac
  169. }
  170. mcrpmfs_run ()
  171. {
  172. f="`echo "$1" | $SED "$SEDCMD"`"
  173. case "$2" in
  174. INSTALL) echo "Installing \"\"$f\"\""; $RPM -ivh "$f"; exit 0;;
  175. UPGRADE) echo "Upgrading \"\"$f\"\""; $RPM -Uvh "$f"; exit 0;;
  176. esac
  177. }
  178. umask 077
  179. case "$1" in
  180. list) mcrpmfs_list "$2"; exit 0;;
  181. copyout) mcrpmfs_copyout "$2" "$3" "$4"; exit 0;;
  182. run) mcrpmfs_run "$2" "$3"; exit 1;;
  183. esac
  184. exit 1