webmin-1.791.ebuild 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. EAPI="5"
  4. inherit eutils pam ssl-cert systemd
  5. DESCRIPTION="A web-based Unix systems administration interface"
  6. HOMEPAGE="http://www.webmin.com/"
  7. SRC_URI="minimal? ( mirror://sourceforge/webadmin/${P}-minimal.tar.gz )
  8. !minimal? ( mirror://sourceforge/webadmin/${P}.tar.gz )"
  9. LICENSE="BSD GPL-2"
  10. SLOT="0"
  11. KEYWORDS="~amd64 ~x86"
  12. # NOTE: The ssl flag auto added by ssl-cert eclass is not used actually
  13. # because openssl is forced by dev-perl/Net-SSLeay
  14. IUSE="minimal +ssl mysql postgres ldap"
  15. REQUIRED_USE="minimal? ( !mysql !postgres !ldap )"
  16. # All the required perl modules can be found easily using (in Webmin's root src dir):
  17. # find . -name cpan_modules.pl -exec grep "::" {} \;
  18. # NOTE: If Webmin doesn't find the required perl modules, it offers(runtime) the user
  19. # to install them using the in-built cpan module, and this will mess up perl on the system
  20. # That's why some modules are forced without a use flag
  21. # NOTE: pam, ssl and dnssec-tools deps are forced for security and Gentoo compliance installation reasons
  22. DEPEND="virtual/perl-MIME-Base64
  23. virtual/perl-Socket
  24. virtual/perl-Sys-Syslog
  25. virtual/perl-Time-HiRes
  26. virtual/perl-Time-Local
  27. dev-perl/Authen-Libwrap
  28. dev-perl/IO-Tty
  29. dev-perl/MD5
  30. dev-perl/Net-SSLeay
  31. dev-perl/Authen-PAM
  32. dev-perl/Sys-Hostname-Long
  33. >=net-dns/dnssec-tools-1.13
  34. !minimal? (
  35. mysql? ( dev-perl/DBD-mysql )
  36. postgres? ( dev-perl/DBD-Pg )
  37. ldap? ( dev-perl/perl-ldap )
  38. dev-perl/XML-Generator
  39. dev-perl/XML-Parser
  40. )"
  41. RDEPEND="${DEPEND}"
  42. src_prepare() {
  43. local perl="$( which perl )"
  44. # Remove the unnecessary and incompatible files
  45. rm -rf acl/Authen-SolarisRBAC-0.1*
  46. if ! use minimal ; then
  47. rm -rf {format,{bsd,hpux,sgi}exports,zones,rbac}
  48. rm -f mount/{free,net,open}bsd-mounts*
  49. rm -f mount/macos-mounts*
  50. fi
  51. # For security reasons remove the SSL certificate that comes with Webmin
  52. # We will create our own later
  53. rm -f miniserv.pem
  54. # Remove the Webmin setup scripts to avoid Webmin in runtime to mess up config
  55. # We will use our own later
  56. rm -f setup.{sh,pl}
  57. # Set the installation type/mode to Gentoo
  58. echo "gentoo" > install-type
  59. # Fix the permissions of the install files
  60. chmod -R og-w "${S}"
  61. # Since we should not modify any files after install
  62. # we set the perl path in all cgi and pl files here using Webmin's routines
  63. # The pl file is Prefix safe and works only on provided input, no other filesystem files
  64. ebegin "Fixing perl path in source files"
  65. (find "${S}" -name '*.cgi' -print ; find "${S}" -name '*.pl' -print) | $perl "${S}"/perlpath.pl $perl -
  66. eend $?
  67. }
  68. src_install() {
  69. # Create config dir and keep
  70. diropts -m0755
  71. dodir /etc/webmin
  72. keepdir /etc/webmin
  73. # Create install dir
  74. # Third party modules installed through Webmin go here too, so keep
  75. dodir /usr/libexec/webmin
  76. keepdir /usr/libexec/webmin
  77. # Copy our own setup script to installation folder
  78. insinto /usr/libexec/webmin
  79. newins "${FILESDIR}"/gentoo-setup-${PV} gentoo-setup.sh
  80. fperms 0744 /usr/libexec/webmin/gentoo-setup.sh
  81. # This is here if we ever want in future ebuilds to add some specific
  82. # config values in the /etc/webmin/miniserv.conf
  83. # The format of this file should be the same as the one of miniserv.conf:
  84. # var=value
  85. #
  86. # Uncomment it if you use such file. Before that check if upstream
  87. # has this file in root dir too.
  88. #newins "${FILESDIR}/miniserv-conf" miniserv-conf
  89. # Create the log dir and keep
  90. diropts -m0700
  91. dodir /var/log/webmin
  92. keepdir /var/log/webmin
  93. # Create the init.d file and put the neccessary variables there
  94. newinitd "${FILESDIR}"/init.d.webmin webmin
  95. sed -i \
  96. -e "s:%exe%:${EROOT}usr/libexec/webmin/miniserv.pl:" \
  97. -e "s:%pid%:${EROOT}var/run/webmin.pid:" \
  98. -e "s:%conf%:${EROOT}etc/webmin/miniserv.conf:" \
  99. -e "s:%config%:${EROOT}etc/webmin/config:" \
  100. -e "s:%perllib%:${EROOT}usr/libexec/webmin:" \
  101. "${ED}etc/init.d/webmin" \
  102. || die "Failed to patch the webmin init file"
  103. # Create the systemd service file and put the neccessary variables there
  104. systemd_newunit "${FILESDIR}"/webmin.service webmin.service
  105. sed -i \
  106. -e "s:%exe%:${EROOT}usr/libexec/webmin/miniserv.pl:" \
  107. -e "s:%pid%:${EROOT}var/run/webmin.pid:" \
  108. -e "s:%conf%:${EROOT}etc/webmin/miniserv.conf:" \
  109. -e "s:%config%:${EROOT}etc/webmin/config:" \
  110. -e "s:%perllib%:${EROOT}usr/libexec/webmin:" \
  111. "${ED}$(_systemd_get_systemunitdir)/webmin.service" \
  112. || die "Failed to patch the webmin systemd service file"
  113. # Setup pam
  114. pamd_mimic system-auth webmin auth account session
  115. # Copy files to installation folder
  116. ebegin "Copying install files to destination"
  117. cp -pPR "${S}"/* "${ED}usr/libexec/webmin"
  118. eend $?
  119. }
  120. pkg_preinst() {
  121. # First stop service if running so Webmin to not messup our config
  122. ebegin "Stopping any running Webmin instance prior merging"
  123. if systemd_is_booted ; then
  124. systemctl stop webmin.service 2>/dev/null
  125. else
  126. rc-service --ifexists -- webmin --ifstarted stop
  127. fi
  128. eend $?
  129. }
  130. pkg_postinst() {
  131. # Run pkg_config phase first - non interactively
  132. export INTERACTIVE="no"
  133. pkg_config
  134. # Every next time pkg_config should be interactive
  135. INTERACTIVE="yes"
  136. ewarn
  137. ewarn "Bare in mind that not all Webmin modules are Gentoo tweaked and may have some issues."
  138. ewarn "Always be careful when using modules that modify init entries, do update of webmin, install CPAN modules etc."
  139. ewarn "To avoid problems, please before using any module, look at its configuration options first."
  140. ewarn "(Usually there is a link at top in the right pane of Webmin for configuring the module.)"
  141. ewarn
  142. if systemd_is_booted ; then
  143. elog "- To make Webmin start at boot time, run: 'systemctl enable webmin.service'"
  144. else
  145. elog "- To make Webmin start at boot time, run: 'rc-update add webmin default'"
  146. fi
  147. elog "- The default URL to connect to Webmin is: https://localhost:10000"
  148. elog "- The default user that can login is: root"
  149. elog "- To reconfigure Webmin in case of problems run 'emerge --config app-admin/webmin'"
  150. }
  151. pkg_prerm() {
  152. # First stop service if running - we do not want Webmin to mess up config
  153. ebegin "Stopping any running Webmin instance prior unmerging"
  154. if systemd_is_booted ; then
  155. systemctl stop webmin.service 2>/dev/null
  156. else
  157. rc-service --ifexists -- webmin --ifstarted stop
  158. fi
  159. eend $?
  160. }
  161. pkg_postrm() {
  162. # If removing webmin completely, remind the user for the Webmin's own cron jobs.
  163. if [[ ! ${REPLACED_BY_VERSION} ]]; then
  164. ewarn
  165. ewarn "You have uninstalled Webmin, so have in mind that all cron jobs scheduled"
  166. ewarn "by Webmin for its own modules, are left active and they will fail when Webmin is missing."
  167. ewarn "To fix this just disable them if you intend to use Webmin again,"
  168. ewarn "OR delete them if not."
  169. ewarn
  170. fi
  171. }
  172. pkg_config(){
  173. # First stop service if running
  174. ebegin "Stopping any running Webmin instance"
  175. if systemd_is_booted ; then
  176. systemctl stop webmin.service 2>/dev/null
  177. else
  178. rc-service --ifexists -- webmin --ifstarted stop
  179. fi
  180. eend $?
  181. # Next set the default reset variable to 'none'
  182. # reset/_reset can be:
  183. # 'none' - does not reset anything, just upgrades if a conf is present
  184. # OR installs new conf if a conf is missing
  185. # 'soft' - deletes only $config_dir/config file and thus resetting most
  186. # conf values to their defaults. Keeps the specific Webmin cron jobs
  187. # 'hard' - deletes all files in $config_dir (keeping the .keep_* Gentoo file)
  188. # and thus resetting all Webmin. Deletes the specific Webmin cron jobs too.
  189. local _reset="none"
  190. # If in interactive mode ask user what should we do
  191. if [[ "${INTERACTIVE}" = "yes" ]]; then
  192. einfo
  193. einfo "Please enter the number of the action you would like to perform?"
  194. einfo
  195. einfo "1. Update configuration"
  196. einfo " (keeps old config options and adds the new ones)"
  197. einfo "2. Soft reset configuration"
  198. einfo " (keeps some old config options, the other options are set to default)"
  199. ewarn " All Webmin users will be reset"
  200. einfo "3. Hard reset configuration"
  201. einfo " (all options including module options are set to default)"
  202. ewarn " You will lose all Webmin configuration options you have done till now"
  203. einfo "4. Exit this configuration utility (default)"
  204. while [ "$correct" != "true" ] ; do
  205. read answer
  206. if [[ "$answer" = "1" ]] ; then
  207. _reset="none"
  208. correct="true"
  209. elif [[ "$answer" = "2" ]] ; then
  210. _reset="soft"
  211. correct="true"
  212. elif [[ "$answer" = "3" ]] ; then
  213. _reset="hard"
  214. correct="true"
  215. elif [ "$answer" = "4" -o "$answer" = "" ] ; then
  216. die "User aborted configuration."
  217. else
  218. echo "Answer not recognized. Enter a number from 1 to 4"
  219. fi
  220. done
  221. if [[ "$_reset" = "hard" ]]; then
  222. while [ "$sure" != "true" ] ; do
  223. ewarn "You will lose all Webmin configuration options you have done till now."
  224. ewarn "Are you sure you want to do this? (y/n)"
  225. read answer
  226. if [[ $answer =~ ^[Yy]([Ee][Ss])?$ ]] ; then
  227. sure="true"
  228. elif [[ $answer =~ ^[Nn]([Oo])?$ ]] ; then
  229. die "User aborted configuration."
  230. else
  231. echo "Answer not recognized. Enter 'y' or 'n'"
  232. fi
  233. done
  234. fi
  235. fi
  236. export reset=$_reset
  237. # Create ssl certificate for Webmin if there is not one in the proper place
  238. if [[ ! -e "${EROOT}etc/ssl/webmin/server.pem" ]]; then
  239. SSL_ORGANIZATION="${SSL_ORGANIZATION:-Webmin Server}"
  240. SSL_COMMONNAME="${SSL_COMMONNAME:-*}"
  241. install_cert "${EROOT}/etc/ssl/webmin/server"
  242. fi
  243. # Ensure all paths passed to the setup script use EROOT
  244. export wadir="${EROOT}usr/libexec/webmin"
  245. export config_dir="${EROOT}etc/webmin"
  246. export var_dir="${EROOT}var/log/webmin"
  247. export tempdir="${T}"
  248. export pidfile="${EROOT}var/run/webmin.pid"
  249. export perl="$( which perl )"
  250. export os_type='gentoo-linux'
  251. export os_version='*'
  252. export real_os_type='Gentoo Linux'
  253. export real_os_version='Any version'
  254. # Forcing 'ssl', 'no_ssl2', 'no_ssl3', 'ssl_redirect', 'no_sslcompression',
  255. # 'ssl_honorcipherorder', 'no_tls1' and 'no_tls1_1' for tightening security
  256. export ssl=1
  257. export no_ssl2=1
  258. export no_ssl3=1
  259. export ssl_redirect=1
  260. export ssl_honorcipherorder=1
  261. export no_sslcompression=1
  262. export no_tls1=1
  263. export no_tls1_1=1
  264. export keyfile="${EROOT}etc/ssl/webmin/server.pem"
  265. export port=10000
  266. export atboot=0
  267. einfo "Executing Webmin's configure script"
  268. $wadir/gentoo-setup.sh
  269. einfo "Configuration of Webmin done"
  270. }