rpm 10 KB

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