shell dot on steroids https://pagure.io/shellfu

yummy.sh 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. #!/bin/bash
  2. ffoo import core
  3. guess_pkgnames() {
  4. #
  5. # Guess interesting names from a folder of RPMs
  6. #
  7. ls "$1" \
  8. | grep rpm\$ \
  9. | sed -e 's/-[0-9].*$//' \
  10. | sort \
  11. | uniq
  12. }
  13. guess_rtag() {
  14. #
  15. # Guess release tag from uname
  16. #
  17. uname -r | sed -e 's/^[.0-9-]*//; s/\..*$//'
  18. }
  19. guess_rtag_word() {
  20. #
  21. # Guess "word" part of release tag from uname
  22. #
  23. # Use guess_rtag and parse out the "word" part,
  24. # e.g. el from el6 or fc from fc18
  25. #
  26. echo $(guess_rtag) | sed -e 's/[0-9]*$//'
  27. }
  28. guess_rtag_num() {
  29. #
  30. # Guess "numeric" part of release tag from uname
  31. #
  32. # Use guess_rtag and parse out the "numeric" part,
  33. # e.g. 6 from el6 or 18 from fc18
  34. #
  35. echo $(guess_rtag) | sed -e 's/^[a-z]*//'
  36. }
  37. installed_versions() {
  38. #
  39. # For every prefix, print installed versions
  40. #
  41. cat - \
  42. | while read name;
  43. do rpm -qa "$name*";
  44. done \
  45. | sort \
  46. | uniq
  47. }
  48. nvc_parse() {
  49. #
  50. # Parse NVC and print element they asked for
  51. #
  52. local what="$1"
  53. local nvc="$2"
  54. test -n "$nvc" || what=USAGE # just provoke the * case
  55. local arch="${nvc##*.}"
  56. local rest="${nvc%%.$arch}"
  57. local release="${rest##*-}"
  58. local rest="${rest%%-$release}"
  59. local version="${rest##*-}"
  60. local name="${rest%-*}"
  61. case $what in
  62. arch)
  63. echo $arch
  64. ;;
  65. release)
  66. echo $release
  67. ;;
  68. version)
  69. echo $version
  70. ;;
  71. name)
  72. echo $name
  73. ;;
  74. *)
  75. usage_is "arch|release|version|name NVC"
  76. return 1
  77. esac
  78. }
  79. save_repo_for() {
  80. #
  81. # Fetch a repo for given target/release
  82. #
  83. # Find out release, take target and from repo_uris.ini,
  84. # choose correct repo URI, finally saving the repo file
  85. # to /etc/yum.repos.d
  86. #
  87. local target=$1
  88. local rtag_word=$(guess_rtag_word)
  89. local uri=$(iniread -s $rtag_word -k $target repo_uris.ini)
  90. think "adding repo for $target"
  91. debug -v target rtag_word uri
  92. case "$uri" in
  93. INCLUDED)
  94. ;;
  95. NONE)
  96. warn "no repo available for $target"
  97. return 1
  98. ;;
  99. *)
  100. pushd /etc/yum.repos.d/ >/dev/null
  101. wget -q "$uri"
  102. popd >/dev/null
  103. ;;
  104. esac
  105. }
  106. yum_preerase() {
  107. #
  108. # Read package names from stdin and pre-erase them
  109. #
  110. local pkg
  111. for pkg in "$@";
  112. do
  113. if rpm -q "$pkg" &> /dev/null;
  114. then
  115. think "pre-erasing $pkg"
  116. yum -q -y erase "$pkg"
  117. fi
  118. done
  119. }
  120. yum_install() {
  121. #
  122. # Mindlessly and silently install anything
  123. #
  124. yum -q -y install "$@" 2>&1 | mute_known yum
  125. }
  126. yum_install_if_needed() {
  127. #
  128. # yum_install unless it's already installed
  129. #
  130. local pkgs="$(select_args word $@)"
  131. local opts="$(select_args opt $@)"
  132. local pkg
  133. debug -v pkgs opts
  134. for pkg in $pkgs;
  135. do
  136. rpm -q $pkg >& /dev/null || yum_install $opts $pkg;
  137. done
  138. }
  139. yum_update() {
  140. #
  141. # Mindlessly and silently update anything
  142. #
  143. yum -q -y update "$@" 2>&1 | mute_known yum
  144. }