generate-psi-plugins-ebuilds.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/bin/bash
  2. die() {
  3. echo "${1}"
  4. exit 1
  5. }
  6. [ ! -d "net-im" ] && die "Please start this script in the overlay root"
  7. list_plugins() {
  8. wget -O- https://github.com/psi-im/plugins/tree/master/$1 2>/dev/null | grep -oE '>\w+plugin<' | while read -r v; do echo ${v:1:-7}; done
  9. }
  10. PLUGINS_GENERIC=`list_plugins generic`
  11. PLUGINS_UNIX=`list_plugins unix`
  12. NEW_PLUGINS=""
  13. for p in $PLUGINS_GENERIC $PLUGINS_UNIX; do
  14. pn=${p/plugin\//}
  15. [ ! -d "net-im/psi-${pn}" ] && NEW_PLUGINS="${NEW_PLUGINS} ${pn}"
  16. done
  17. [ "${NEW_PLUGINS}" == "" ] && {
  18. echo "no new plugins found."
  19. exit 0
  20. }
  21. echo "Found next new plugins:${NEW_PLUGINS}"
  22. echo -ne "Do you want to generate ebuilds for them? [\033[4mY\033[0m/n]"
  23. read -n 1 act
  24. echo
  25. case $act in
  26. n|N) echo "ok. nothing is left to do"; exit 0 ;;
  27. *) echo "Generating ebuilds.." ;;
  28. esac
  29. for pn in $NEW_PLUGINS; do
  30. echo "Creating ebuild for ${pn} plugin."
  31. echo -n "Enter DESCRIPTION ebuild's field: "
  32. read desc
  33. [ "${desc}" == "" ] && {
  34. echo "You must enter at least 1 symbol. skipping plugin"
  35. continue
  36. }
  37. echo -n "Enter long desciption for metadata: "
  38. read longdesc
  39. mkdir "net-im/psi-${pn}" || die "failed to create plugin's dir"
  40. echo "$(cat <<METACONTENT
  41. <?xml version="1.0" encoding="UTF-8"?>
  42. <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
  43. <pkgmetadata>
  44. <maintainer type="person">
  45. <email>rion4ik@gmail.com</email>
  46. <name>rion</name>
  47. </maintainer>
  48. <longdescription lang="en">
  49. ${longdesc}
  50. </longdescription>
  51. </pkgmetadata>
  52. METACONTENT
  53. )" > "net-im/psi-${pn}/metadata.xml"
  54. arch=generic
  55. for pu in $PLUGINS_UNIX; do [ "$pu" = "${pn}plugin" ] && arch=unix; done
  56. dirvar=""
  57. [ "$arch" != "generic" ] && dirvar="PLUGIN_DIR=\"${arch}\"
  58. "
  59. echo "$(cat <<EBUILDCONTENT
  60. # Copyright 1999-$(date +%Y) Gentoo Authors
  61. # Distributed under the terms of the GNU General Public License v2
  62. # \$Header: \$
  63. EAPI=8
  64. ${dirvar}inherit psi-plugin
  65. DESCRIPTION="${desc}"
  66. EBUILDCONTENT
  67. )" >> "net-im/psi-${pn}/psi-${pn}-9999.ebuild"
  68. ebuild "net-im/psi-${pn}/psi-${pn}-9999.ebuild" digest
  69. git add "net-im/psi-${pn}"
  70. done
  71. ####### Add new ebuild to package.keywords and set #######
  72. ALL_PLUGINS="$(grep psi-plugin -lr net-im/ --include '*ebuild' | cut -d '/' -f -2 | sort -u)"
  73. (
  74. echo "net-im/psi::rion **"
  75. echo "net-im/psimedia::rion **"
  76. echo "$ALL_PLUGINS" | awk '{print $1."::rion **"}'
  77. ) > Documentation/package.keywords/psi/psi.accept_keywords
  78. (
  79. echo "net-im/psi"
  80. echo "net-im/psimedia"
  81. echo "$ALL_PLUGINS"
  82. ) > sets/psiplus
  83. ##########################################################
  84. plugin_names=""
  85. plugin_flags=""
  86. for atom in $ALL_PLUGINS; do
  87. ebuild=$(ls $atom/*ebuild | head -n1)
  88. desc=$( . $ebuild 2>/dev/null; echo $DESCRIPTION; )
  89. plugin="$(echo "$atom" | cut -d '-' -f 3)"
  90. plugin_flags="$plugin_flags
  91. <flag name=\"${plugin}\">Enable ${desc}</flag>"
  92. plugin_names="$plugin_names $plugin"
  93. done
  94. echo "$(cat <<EBUILDCONTENT
  95. # Copyright 1999-$(date +%Y) Gentoo Authors
  96. # Distributed under the terms of the GNU General Public License v2
  97. # \$Header: \$
  98. EAPI=8
  99. DESCRIPTION="Meta package for net-im/psi plugins"
  100. HOMEPAGE="https://github.com/psi-im"
  101. LICENSE="GPL-2"
  102. SLOT="0"
  103. KEYWORDS=""
  104. IUSE="$(echo $plugin_names)"
  105. RDEPEND=""
  106. for plugin in \${IUSE}; do
  107. RDEPEND+=" \${plugin}? ( >=net-im/psi-\${plugin}-\${PV} )"
  108. done
  109. EBUILDCONTENT
  110. )" > "net-im/psi-plugins-meta/psi-plugins-meta-9999.ebuild"
  111. echo "$(cat <<METACONTENT
  112. <?xml version="1.0" encoding="UTF-8"?>
  113. <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
  114. <pkgmetadata>
  115. <maintainer type="person">
  116. <email>rion4ik@gmail.com</email>
  117. <name>Sergey Ilinykh</name>
  118. </maintainer>
  119. <longdescription lang="en">Meta package for Psi plugins.
  120. Just set USE flag corresponding to needed for you plugins
  121. and emerge this package
  122. </longdescription>
  123. <use>${plugin_flags}
  124. </use>
  125. </pkgmetadata>
  126. METACONTENT
  127. )" > "net-im/psi-plugins-meta/metadata.xml"
  128. echo
  129. echo "New ebuilds are ready for commit! :-)"