rpm 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. #! /bin/sh
  2. # VFS-wrapper for RPM (and src.rpm) files
  3. #
  4. # Copyright (C) 1996-2004,2009
  5. # Free Software Foundation, Inc.
  6. #
  7. # Written by
  8. # Erik Troan <ewt@redhat.com> 1996
  9. # Jakub Jelinek <jj@sunsite.mff.cuni.cz> 1996, 2004
  10. # Tomasz Kłoczko <kloczek@rudy.mif.pg.gda.pl> 1997
  11. # Wojtek Pilorz <wpilorz@bdk.lublin.pl>
  12. # 1997: minor changes
  13. # Michele Marziani <marziani@fe.infn.it>
  14. # 1997: minor changes
  15. # Marc Merlin <marcsoft@merlins.org> 1998
  16. # 1998: bug files
  17. # Michal Svec <rebel@penguin.cz> 2000
  18. # 2000: locale bugfix
  19. # Andrew V. Samoilov <sav@bcs.zp.ua>
  20. # 2004: Whitespace(s) & single quote(s) in filename workaround
  21. # https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=64007
  22. # Slava Zanko <slavazanko@gmail.com>
  23. # 2009: Totally rewritten.
  24. #
  25. # This file is part of the Midnight Commander.
  26. #
  27. # The Midnight Commander is free software; you can redistribute it
  28. # and/or modify it under the terms of the GNU General Public License as
  29. # published by the Free Software Foundation; either version 2 of the
  30. # License, or (at your option) any later version.
  31. #
  32. # The Midnight Commander is distributed in the hope that it will be
  33. # useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  34. # of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  35. # General Public License for more details.
  36. #
  37. # You should have received a copy of the GNU General Public License
  38. # along with this program; if not, write to the Free Software
  39. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  40. # MA 02110-1301, USA.
  41. # override any locale for dates
  42. unset LC_ALL
  43. LC_TIME=C
  44. export LC_TIME
  45. if rpmbuild --version >/dev/null 2>&1; then
  46. RPMBUILD="rpmbuild"
  47. else
  48. RPMBUILD="rpm"
  49. fi
  50. if rpm --nosignature --version >/dev/null 2>&1; then
  51. RPM="rpm --nosignature"
  52. RPMBUILD="$RPMBUILD --nosignature"
  53. else
  54. RPM="rpm"
  55. fi
  56. RPM2CPIO="rpm2cpio"
  57. SED="sed"
  58. # Surround the whole filename with single quotes and handle specially
  59. # \', ' and \ at the end of the string.
  60. SEDCMD="s/ /\\\\ /g;s/'/\\\\'/g;s/\"/\\\\\"/g"
  61. param=$1; shift
  62. rpm_filename=$1; shift
  63. FILEPREF="-r--r--r-- 1 root root "
  64. mcrpmfs_getSupportedTags()
  65. {
  66. rpm --querytags
  67. }
  68. mcrpmfs_getDesription()
  69. {
  70. $RPM -qip "`echo ${rpm_filename}| $SED "${SEDCMD}"`"
  71. }
  72. mcrpmfs_getAllNeededTags()
  73. {
  74. supportedTags=`mcrpmfs_getSupportedTags`
  75. if test "`echo supportedTags | grep -c CONFLICTS`" -eq 1; then
  76. tag_CONFLICTS="|CONFLICTS=%{CONFLICTS}"
  77. else
  78. tag_CONFLICTS=""
  79. fi
  80. $RPM -qp --qf \
  81. "|NAME=%{NAME}"\
  82. "|VERSION=%{VERSION}"\
  83. "|RELEASE=%{RELEASE}"\
  84. "|DISTRIBUTION=%{DISTRIBUTION}"\
  85. "|VENDOR=%{VENDOR}"\
  86. "|DESCRIPTION=%{DESCRIPTION}"\
  87. "|SUMMARY=%{SUMMARY}"\
  88. "|URL=%{URL}"\
  89. "|EPOCH=%{EPOCH}"\
  90. "|LICENSE=%{LICENSE}"\
  91. "|REQUIRENAME=%{REQUIRENAME}"\
  92. "|OBSOLETES=%{OBSOLETES}"\
  93. "|PROVIDES=%{PROVIDES}"\
  94. ${tag_CONFLICTS}\
  95. "|PACKAGER=%{PACKAGER}" \
  96. "`echo ${rpm_filename}| $SED "${SEDCMD}"`"
  97. }
  98. mcrpmfs_getRawOneTag()
  99. {
  100. $RPM -qp --qf "$1" "`echo ${rpm_filename}| $SED "${SEDCMD}"`"
  101. }
  102. mcrpmfs_getOneTag()
  103. {
  104. echo $AllTAGS | sed "s/.*|${1}=//" | cut -d '|' -f 1
  105. }
  106. AllTAGS=`mcrpmfs_getAllNeededTags "$1"`
  107. mcrpmfs_printOneMetaInfo()
  108. {
  109. if test "$3" = "raw"; then
  110. metaInfo=`mcrpmfs_getRawOneTag "%{$2}"`
  111. else
  112. metaInfo=`mcrpmfs_getOneTag "$2"`
  113. fi
  114. if test -n "${metaInfo}" -a "${metaInfo}" != "(none)"; then
  115. echo "${FILEPREF} 0 ${DATE} ${1}"
  116. return 0
  117. fi
  118. return 1
  119. }
  120. mcrpmfs_list_fastRPM ()
  121. {
  122. echo "$FILEPREF 0 $DATE INFO/DISTRIBUTION"
  123. echo "$FILEPREF 0 $DATE INFO/VENDOR"
  124. echo "$FILEPREF 0 $DATE INFO/DESCRIPTION"
  125. echo "$FILEPREF 0 $DATE INFO/SUMMARY"
  126. echo "dr-xr-xr-x 1 root root 0 $DATE INFO/SCRIPTS"
  127. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREIN"
  128. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTIN"
  129. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/PREUN"
  130. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/POSTUN"
  131. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/VERIFYSCRIPT"
  132. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/ALL"
  133. echo "$FILEPREF 0 $DATE INFO/PACKAGER"
  134. echo "$FILEPREF 0 $DATE INFO/URL"
  135. echo "$FILEPREF 0 $DATE INFO/EPOCH"
  136. echo "$FILEPREF 0 $DATE INFO/LICENSE"
  137. echo "$FILEPREF 0 $DATE INFO/REQUIRENAME"
  138. echo "$FILEPREF 0 $DATE INFO/OBSOLETES"
  139. echo "$FILEPREF 0 $DATE INFO/PROVIDES"
  140. echo "$FILEPREF 0 $DATE INFO/CONFLICTS"
  141. echo "$FILEPREF 0 $DATE INFO/CHANGELOG"
  142. }
  143. mcrpmfs_list_fullRPM ()
  144. {
  145. mcrpmfs_printOneMetaInfo "INFO/DISTRIBUTION" "DISTRIBUTION"
  146. mcrpmfs_printOneMetaInfo "INFO/VENDOR" "VENDOR"
  147. mcrpmfs_printOneMetaInfo "INFO/DESCRIPTION" "DESCRIPTION"
  148. mcrpmfs_printOneMetaInfo "INFO/SUMMARY" "SUMMARY"
  149. if test "`mcrpmfs_getRawOneTag \"%{RPMTAG_PREIN}%{RPMTAG_POSTIN}%{RPMTAG_PREUN}%{RPMTAG_POSTUN}%{VERIFYSCRIPT}\"`" != "(none)(none)(none)(none)(none)"; then
  150. mcrpmfs_printOneMetaInfo "INFO/SCRIPTS/PREIN" "RPMTAG_PREIN" "raw"
  151. mcrpmfs_printOneMetaInfo "INFO/SCRIPTS/POSTIN" "RPMTAG_POSTIN" "raw"
  152. mcrpmfs_printOneMetaInfo "INFO/SCRIPTS/PREUN" "RPMTAG_PREUN" "raw"
  153. mcrpmfs_printOneMetaInfo "INFO/SCRIPTS/POSTUN" "RPMTAG_POSTUN" "raw"
  154. mcrpmfs_printOneMetaInfo "INFO/SCRIPTS/VERIFYSCRIPT" "VERIFYSCRIPT" "raw"
  155. echo "$FILEPREF 0 $DATE INFO/SCRIPTS/ALL"
  156. fi
  157. mcrpmfs_printOneMetaInfo "INFO/PACKAGER" "PACKAGER"
  158. mcrpmfs_printOneMetaInfo "INFO/URL" "URL"
  159. mcrpmfs_printOneMetaInfo "INFO/EPOCH" "EPOCH"
  160. mcrpmfs_printOneMetaInfo "INFO/LICENSE" "LICENSE"
  161. mcrpmfs_printOneMetaInfo "INFO/REQUIRENAME" "REQUIRENAME"
  162. mcrpmfs_printOneMetaInfo "INFO/OBSOLETES" "OBSOLETES"
  163. mcrpmfs_printOneMetaInfo "INFO/PROVIDES" "PROVIDES"
  164. mcrpmfs_printOneMetaInfo "INFO/CONFLICTS" "CONFLICTS"
  165. mcrpmfs_printOneMetaInfo "INFO/CHANGELOG" "CHANGELOGTEXT" "raw"
  166. }
  167. mcrpmfs_list ()
  168. {
  169. # set MCFASTRPM_DFLT to 1 for faster rpm files handling by default, to 0 for
  170. # slower handling
  171. MCFASTRPM_DFLT=0
  172. if test -z "$MCFASTRPM"; then
  173. MCFASTRPM=$MCFASTRPM_DFLT
  174. fi
  175. DESC=`mcrpmfs_getDesription 2>/dev/null` || {
  176. echo "$FILEPREF 0 "`date +"%b %d %H:%M"`" ERROR"
  177. exit 1
  178. }
  179. DATE=`mcrpmfs_getRawOneTag "%{BUILDTIME:date}\n" | cut -c 5-11,21-24`
  180. HEADERSIZE=`echo "$DESC" | wc -c`
  181. printf '%s %s %s HEADER\n' "${FILEPREF}" "${HEADERSIZE}" "${DATE}"
  182. echo "-r-xr-xr-x 1 root root 39 $DATE INSTALL"
  183. case "${rpm_filename}" in
  184. *.src.rpm)
  185. echo "-r-xr-xr-x 1 root root 39 $DATE REBUILD"
  186. ;;
  187. *)
  188. echo "-r-xr-xr-x 1 root root 39 $DATE UPGRADE"
  189. ;;
  190. esac
  191. echo "dr-xr-xr-x 3 root root 0 $DATE INFO"
  192. echo "$FILEPREF 0 $DATE INFO/NAME-VERSION-RELEASE"
  193. echo "$FILEPREF 0 $DATE INFO/GROUP"
  194. echo "$FILEPREF 0 $DATE INFO/BUILDHOST"
  195. echo "$FILEPREF 0 $DATE INFO/SOURCERPM"
  196. echo "$FILEPREF 0 $DATE INFO/BUILDTIME"
  197. echo "$FILEPREF 0 $DATE INFO/RPMVERSION"
  198. echo "$FILEPREF 0 $DATE INFO/OS"
  199. echo "$FILEPREF 0 $DATE INFO/SIZE"
  200. if test "$MCFASTRPM" = 0 ; then
  201. mcrpmfs_list_fullRPM
  202. else
  203. mcrpmfs_list_fastRPM
  204. fi
  205. echo "$FILEPREF 0 $DATE CONTENTS.cpio"
  206. }
  207. mcrpmfs_copyout ()
  208. {
  209. case "$1" in
  210. HEADER) mcrpmfs_getDesription > "$2"; exit 0;;
  211. INSTALL)
  212. echo "# Run this script to install this RPM package" > "$2"
  213. echo $RPM -ivh "`echo ${rpm_filename}| $SED "${SEDCMD}"`" >> "$2"
  214. exit 0
  215. ;;
  216. UPGRADE)
  217. echo "# Run this to upgrade this RPM package" > "$2"
  218. echo $RPM -Uvh "`echo ${rpm_filename}| $SED "${SEDCMD}"`" >> "$2"
  219. exit 0
  220. ;;
  221. REBUILD)
  222. echo "# Run this to rebuild this RPM package" > "$2"
  223. echo $RPMBUILD --rebuild "`echo ${rpm_filename}| $SED "${SEDCMD}"`" >> "$2"
  224. exit 0
  225. ;;
  226. ERROR) mcrpmfs_getDesription > /dev/null 2> "$2"; exit 0;;
  227. INFO/NAME-VERSION-RELEASE)
  228. echo `mcrpmfs_getOneTag "NAME"`-`mcrpmfs_getOneTag "VERSION"`-`mcrpmfs_getOneTag "RELEASE"` > "$2"
  229. exit 0
  230. ;;
  231. INFO/RELEASE) mcrpmfs_getOneTag "RELEASE" > "$2"; exit 0;;
  232. INFO/GROUP) mcrpmfs_getRawOneTag "%{GROUP}\n" > "$2"; exit 0;;
  233. INFO/DISTRIBUTION) mcrpmfs_getOneTag "DISTRIBUTION" > "$2"; exit 0;;
  234. INFO/VENDOR) mcrpmfs_getOneTag "VENDOR" > "$2"; exit 0;;
  235. INFO/BUILDHOST) mcrpmfs_getRawOneTag "%{BUILDHOST}\n" > "$2"; exit 0;;
  236. INFO/SOURCERPM) mcrpmfs_getRawOneTag "%{SOURCERPM}\n" > "$2"; exit 0;;
  237. INFO/DESCRIPTION) mcrpmfs_getRawOneTag "%{DESCRIPTION}\n" > "$2"; exit 0;;
  238. INFO/PACKAGER) mcrpmfs_getOneTag "PACKAGER" > "$2"; exit 0;;
  239. INFO/URL) mcrpmfs_getOneTag "URL" >"$2"; exit 0;;
  240. INFO/BUILDTIME) mcrpmfs_getRawOneTag "%{BUILDTIME:date}\n" >"$2"; exit 0;;
  241. INFO/EPOCH) mcrpmfs_getOneTag "EPOCH" >"$2"; exit 0;;
  242. INFO/LICENSE) mcrpmfs_getOneTag "LICENSE" >"$2"; exit 0;;
  243. INFO/RPMVERSION) mcrpmfs_getRawOneTag "%{RPMVERSION}\n" >"$2"; exit 0;;
  244. INFO/REQUIRENAME) mcrpmfs_getRawOneTag "[%{REQUIRENAME} %{REQUIREFLAGS:depflags} %{REQUIREVERSION}\n]" >"$2"; exit 0;;
  245. INFO/PROVIDES) mcrpmfs_getRawOneTag "[%{PROVIDES}\n]" >"$2"; exit 0;;
  246. INFO/SCRIPTS/PREIN) mcrpmfs_getRawOneTag "%{RPMTAG_PREIN}\n" >"$2"; exit 0;;
  247. INFO/SCRIPTS/POSTIN) mcrpmfs_getRawOneTag "%{RPMTAG_POSTIN}\n" >"$2"; exit 0;;
  248. INFO/SCRIPTS/PREUN) mcrpmfs_getRawOneTag "%{RPMTAG_PREUN}\n" >"$2"; exit 0;;
  249. INFO/SCRIPTS/POSTUN) mcrpmfs_getRawOneTag "%{RPMTAG_POSTUN}\n" >"$2"; exit 0;;
  250. INFO/SCRIPTS/VERIFYSCRIPT) mcrpmfs_getRawOneTag "%{VERIFYSCRIPT}\n" > "$2"; exit 0;;
  251. INFO/SCRIPTS/ALL) $RPM -qp --scripts "`echo ${rpm_filename}| $SED "${SEDCMD}"`" > "$2"; exit 0;;
  252. INFO/SUMMARY) mcrpmfs_getRawOneTag "%{SUMMARY}\n" > "$2"; exit 0;;
  253. INFO/OS) mcrpmfs_getRawOneTag "%{OS}\n" > "$2"; exit 0;;
  254. INFO/CHANGELOG) mcrpmfs_getRawOneTag "[* %{CHANGELOGTIME:date} %{CHANGELOGNAME}\n%{CHANGELOGTEXT}\n\n]\n" > "$2"; exit 0;;
  255. INFO/SIZE) mcrpmfs_getRawOneTag "%{SIZE} bytes\n" > "$2"; exit 0;;
  256. INFO/OBSOLETES) mcrpmfs_getRawOneTag "[%{OBSOLETENAME} %|OBSOLETEFLAGS?{%{OBSOLETEFLAGS:depflags} %{OBSOLETEVERSION}}:{}|\n]" > "$2"; exit 0;;
  257. INFO/CONFLICTS) mcrpmfs_getRawOneTag "[%{CONFLICTNAME} %{CONFLICTFLAGS:depflags} %{CONFLICTVERSION}\n]" >"$2"; exit 0;;
  258. CONTENTS.cpio) $RPM2CPIO "`echo ${rpm_filename}| $SED "${SEDCMD}"`" > "$2"; exit 0;;
  259. *)
  260. ;;
  261. esac
  262. }
  263. mcrpmfs_run ()
  264. {
  265. case "$1" in
  266. INSTALL) echo "Installing \"\"$f\"\""; $RPM -ivh "`echo ${rpm_filename}| $SED "${SEDCMD}"`"; exit 0;;
  267. UPGRADE) echo "Upgrading \"\"$f\"\""; $RPM -Uvh "`echo ${rpm_filename}| $SED "${SEDCMD}"`"; exit 0;;
  268. REBUILD) echo "Rebuilding \"${rpm_filename}\""; $RPMBUILD --rebuild "`echo ${rpm_filename}| $SED "${SEDCMD}"`"; exit 0;;
  269. esac
  270. }
  271. umask 077
  272. case "${param}" in
  273. list) mcrpmfs_list; exit 0;;
  274. copyout) mcrpmfs_copyout "$1" "$2"; exit 0;;
  275. run) mcrpmfs_run "$1"; exit 1;;
  276. esac
  277. exit 1