gentoo-setup-1.791 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. #!/bin/sh
  2. # gentoo-setup.sh
  3. #
  4. # Version 1.2
  5. #
  6. # A modified original Webmin setup.sh script to comply with Gentoo specifics
  7. #
  8. # Modification done by: PhobosK <phobosk@kbfx.net>
  9. #
  10. # This script runs after the webmin archive is installed, and in the pkg_config() phase.
  11. # It does setup the various config files of Webmin depending on if it is
  12. # a new install, an upgrade or a reset.
  13. LANG=
  14. export LANG
  15. if [ -z ${wadir} ]; then
  16. echo "You can't run this script outside of the 'emerge --config app-admin/webmin' command."
  17. exit 1
  18. fi
  19. # All things we do is from the Webmin install dir - $wadir
  20. cd $wadir
  21. # Are we hard resetting everything?
  22. # If yes, we do:
  23. # 1. Run the specific Webmin $wadir/run-uninstalls.pl
  24. # It runs all uninstall.pl files in every module's folder.
  25. # They delete all the set specific Webmin cron jobs.
  26. # If bumping you should go through these files using the command:
  27. # find . -name uninstall.pl -exec cat {} \; -print
  28. # 2. Delete the whole /etc/webmin content, keeping only the gentoo .keep_* files
  29. if [ "$reset" = "hard" ]; then
  30. echo "Running Webmin's specific uninstall procedures.. (Please ignore any possible errors)"
  31. (WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir LANG= "$wadir/run-uninstalls.pl")
  32. echo "..done"
  33. echo ""
  34. echo "Deleting the content of user's config folder: $config_dir .."
  35. find $config_dir ! -name '.keep_*' -delete 2>/dev/null
  36. echo "..done"
  37. echo ""
  38. fi
  39. # Are we soft resetting?
  40. # If yes we do:
  41. # - Delete the $config_dir/config file so we get new config values
  42. if [ "$reset" = "soft" ]; then
  43. echo "Deleting the user's $config_dir/config file.."
  44. if [ -f "$config_dir/config" ]; then
  45. rm -f "$config_dir/config"
  46. fi
  47. echo "..done"
  48. echo ""
  49. fi
  50. # Get all available modules of this version
  51. allmods=`echo */module.info | sed -e 's/\/module.info//g'`
  52. # Get current Webmin version
  53. ver=`cat "$wadir/version"`
  54. if [ -r "$config_dir/config" ]; then
  55. upgrading=1
  56. fi
  57. # Check if upgrading from an old version
  58. if [ "$upgrading" = 1 ]; then
  59. echo "Updating existant Webmin's config files.."
  60. # Get current var path
  61. if [ -r "$config_dir/var-path" ]; then
  62. _var_dir=`cat $config_dir/var-path`
  63. if [ -n ${_var_dir} ]; then
  64. var_dir=${_var_dir}
  65. fi
  66. fi
  67. # Get current perl path
  68. if [ -r "$config_dir/perl-path" ]; then
  69. _perl=`cat $config_dir/perl-path`
  70. if [ -n ${_perl} ]; then
  71. perl=${_perl}
  72. fi
  73. fi
  74. # Get old os name and version
  75. os_type=`grep "^os_type=" $config_dir/config | sed -e 's/os_type=//g'`
  76. os_version=`grep "^os_version=" $config_dir/config | sed -e 's/os_version=//g'`
  77. real_os_type=`grep "^real_os_type=" $config_dir/config | sed -e 's/real_os_type=//g'`
  78. real_os_version=`grep "^real_os_version=" $config_dir/config | sed -e 's/real_os_version=//g'`
  79. # Get port, ssl, no_ssl2, no_ssl3, ssl_redirect, no_sslcompression, ssl_honorcipherorder, no_tls1, no_tls1_1 and keyfile
  80. port=`grep "^port=" $config_dir/miniserv.conf | sed -e 's/port=//g'`
  81. ssl=`grep "^ssl=" $config_dir/miniserv.conf | sed -e 's/ssl=//g'`
  82. no_ssl2=`grep "^no_ssl2=" $config_dir/miniserv.conf | sed -e 's/no_ssl2=//g'`
  83. no_ssl3=`grep "^no_ssl3=" $config_dir/miniserv.conf | sed -e 's/no_ssl3=//g'`
  84. ssl_redirect=`grep "^ssl_redirect=" $config_dir/miniserv.conf | sed -e 's/ssl_redirect=//g'`
  85. ssl_honorcipherorder=`grep "^ssl_honorcipherorder=" $config_dir/miniserv.conf | sed -e 's/ssl_honorcipherorder=//g'`
  86. no_sslcompression=`grep "^no_sslcompression=" $config_dir/miniserv.conf | sed -e 's/no_sslcompression=//g'`
  87. no_tls1=`grep "^no_tls1=" $config_dir/miniserv.conf | sed -e 's/no_tls1=//g'`
  88. no_tls1_1=`grep "^no_tls1_1=" $config_dir/miniserv.conf | sed -e 's/no_tls1_1=//g'`
  89. keyfile=`grep "^keyfile=" $config_dir/miniserv.conf | sed -e 's/keyfile=//g'`
  90. # Update ACLs
  91. $perl "$wadir/newmods.pl" $config_dir $allmods
  92. # Update miniserv.conf with new root directory, mime types file and server info
  93. grep -v "^root=" $config_dir/miniserv.conf | grep -v "^mimetypes=" | grep -v "^server=" >$tempdir/$$.miniserv.conf
  94. mv $tempdir/$$.miniserv.conf $config_dir/miniserv.conf
  95. echo "root=$wadir" >> $config_dir/miniserv.conf
  96. echo "mimetypes=$wadir/mime.types" >> $config_dir/miniserv.conf
  97. echo "server=MiniServ/$ver" >> $config_dir/miniserv.conf
  98. grep logout= $config_dir/miniserv.conf >/dev/null
  99. if [ $? != "0" ]; then
  100. echo "logout=$config_dir/logout-flag" >> $config_dir/miniserv.conf
  101. fi
  102. # Remove old cache of module infos
  103. rm -f $config_dir/module.infos.cache
  104. echo "..done"
  105. echo ""
  106. else
  107. # Create webserver's new config files
  108. echo "Creating Webmin's new config files.."
  109. echo $perl > $config_dir/perl-path
  110. echo $var_dir > $config_dir/var-path
  111. # Create a totally new conf file
  112. cfile=$config_dir/miniserv.conf
  113. echo "port=$port" > $cfile
  114. echo "root=$wadir" >> $cfile
  115. echo "mimetypes=$wadir/mime.types" >> $cfile
  116. echo "addtype_cgi=internal/cgi" >> $cfile
  117. echo "realm=Webmin Server" >> $cfile
  118. echo "logfile=$var_dir/miniserv.log" >> $cfile
  119. echo "errorlog=$var_dir/miniserv.error" >> $cfile
  120. echo "pidfile=$pidfile" >> $cfile
  121. echo "logtime=168" >> $cfile
  122. echo "ppath=$ppath" >> $cfile
  123. echo "ssl=$ssl" >> $cfile
  124. echo "no_ssl2=$no_ssl2" >> $cfile
  125. echo "no_ssl3=$no_ssl3" >> $cfile
  126. echo "ssl_redirect=$ssl_redirect" >> $cfile
  127. echo "ssl_honorcipherorder=$ssl_honorcipherorder" >> $cfile
  128. echo "no_sslcompression=$no_sslcompression" >> $cfile
  129. echo "no_tls1=$no_tls1" >> $cfile
  130. echo "no_tls1_1=$no_tls1_1" >> $cfile
  131. echo "keyfile=$keyfile" >> $cfile
  132. echo "env_WEBMIN_CONFIG=$config_dir" >> $cfile
  133. echo "env_WEBMIN_VAR=$var_dir" >> $cfile
  134. echo "atboot=$atboot" >> $cfile
  135. echo "logout=$config_dir/logout-flag" >> $cfile
  136. echo "listen=10000" >> $cfile
  137. echo "denyfile=\\.pl\$" >> $cfile
  138. echo "log=1" >> $cfile
  139. echo "blockhost_failures=5" >> $cfile
  140. echo "blockhost_time=60" >> $cfile
  141. echo "syslog=1" >> $cfile
  142. echo "session=1" >> $cfile
  143. echo "premodules=WebminCore" >> $cfile
  144. echo "server=MiniServ/$ver" >> $cfile
  145. # Append package-specific info to config file.
  146. # miniserv-conf can be created by upstream or by us in src_install phase (see there).
  147. if [ -f "$wadir/miniserv-conf" ]; then
  148. cat "$wadir/miniserv-conf" >>$cfile
  149. fi
  150. # Create the default user allowed to login - root only
  151. login="root"
  152. if [ -r /etc/shadow ]; then
  153. #crypt=`grep "^root:" /etc/shadow | cut -f 2 -d :`
  154. crypt=x
  155. else
  156. crypt=`grep "^root:" /etc/passwd | cut -f 2 -d :`
  157. fi
  158. ufile=$config_dir/miniserv.users
  159. echo "$login:$crypt:0" > $ufile
  160. chmod 600 $ufile
  161. echo "userfile=$ufile" >> $cfile
  162. chmod 600 $cfile
  163. echo "..done"
  164. echo ""
  165. echo "Creating access control file.."
  166. afile=$config_dir/webmin.acl
  167. echo "$login: $allmods" > $afile
  168. chmod 600 $afile
  169. echo "..done"
  170. echo ""
  171. fi
  172. # Create start, stop, restart and reload Gentoo compliant Webmin scripts
  173. # We use sys-apps/openrc functions which is already pulled by sys-apps/baselayout
  174. # or systemctl if we run under systemd
  175. echo "Creating start and stop scripts.."
  176. rm -f $config_dir/{start,stop,restart,reload}
  177. # The start script in /etc/webmin (Gentoo compliant)
  178. cat <<END >>"$config_dir/start"
  179. #!/bin/sh
  180. if [ ! -f "${pidfile}" ]; then
  181. if [[ -d /run/systemd/system ]] ; then
  182. systemctl start webmin.service
  183. else
  184. rc-service --ifexists -- webmin start
  185. fi
  186. fi
  187. END
  188. # The stop script in /etc/webmin (Gentoo compliant)
  189. cat <<END >>"$config_dir/stop"
  190. #!/bin/sh
  191. if [[ -d /run/systemd/system ]] ; then
  192. systemctl stop webmin.service
  193. else
  194. rc-service --ifexists -- webmin --ifstarted stop
  195. fi
  196. END
  197. # The restart script in /etc/webmin (Gentoo compliant)
  198. cat <<END >>"$config_dir/restart"
  199. #!/bin/sh
  200. if [[ -d /run/systemd/system ]] ; then
  201. systemctl try-restart webmin.service
  202. else
  203. rc-service --ifexists -- webmin --ifstarted restart
  204. fi
  205. END
  206. # The reload script in /etc/webmin (Gentoo compliant)
  207. cat <<END >>"$config_dir/reload"
  208. #!/bin/sh
  209. if [[ -d /run/systemd/system ]] ; then
  210. systemctl reload-or-try-restart webmin.service
  211. else
  212. rc-service --ifexists -- webmin --ifstarted reload
  213. fi
  214. END
  215. chmod 755 $config_dir/{start,stop,restart,reload}
  216. echo "..done"
  217. echo ""
  218. if [ "$upgrading" = 1 ]; then
  219. echo "Updating other config files.."
  220. else
  221. echo "Copying other config files.."
  222. fi
  223. # This just copies and merges the Webmin's release config files, with user's in the /etc/webmin folder
  224. newmods=`$perl "$wadir/copyconfig.pl" "$os_type/$real_os_type" "$os_version/$real_os_version" "$wadir" $config_dir "" $allmods`
  225. if [ "$upgrading" != 1 ]; then
  226. # Store the OS and version
  227. echo "os_type=$os_type" >> $config_dir/config
  228. echo "os_version=$os_version" >> $config_dir/config
  229. echo "real_os_type=$real_os_type" >> $config_dir/config
  230. echo "real_os_version=$real_os_version" >> $config_dir/config
  231. # Turn on logging by default
  232. echo "log=1" >> $config_dir/config
  233. # Disallow unknown referers by default
  234. echo "referers_none=1" >>$config_dir/config
  235. else
  236. # one-off hack to set log variable in config from miniserv.conf
  237. grep log= $config_dir/config >/dev/null
  238. if [ "$?" = "1" ]; then
  239. grep log= $config_dir/miniserv.conf >> $config_dir/config
  240. grep logtime= $config_dir/miniserv.conf >> $config_dir/config
  241. grep logclear= $config_dir/miniserv.conf >> $config_dir/config
  242. fi
  243. # Disallow unknown referers if not set
  244. grep referers_none= $config_dir/config >/dev/null
  245. if [ "$?" != "0" ]; then
  246. echo "referers_none=1" >>$config_dir/config
  247. fi
  248. fi
  249. echo $ver > $config_dir/version
  250. echo "..done"
  251. echo ""
  252. # Set passwd_ fields in miniserv.conf from global config
  253. for field in passwd_file passwd_uindex passwd_pindex passwd_cindex passwd_mindex; do
  254. grep $field= $config_dir/miniserv.conf >/dev/null
  255. if [ "$?" != "0" ]; then
  256. grep $field= $config_dir/config >> $config_dir/miniserv.conf
  257. fi
  258. done
  259. grep passwd_mode= $config_dir/miniserv.conf >/dev/null
  260. if [ "$?" != "0" ]; then
  261. echo passwd_mode=0 >> $config_dir/miniserv.conf
  262. fi
  263. grep ssl_honorcipherorder= $config_dir/miniserv.conf >/dev/null
  264. if [ "$?" != "0" ]; then
  265. echo ssl_honorcipherorder=1 >> $config_dir/miniserv.conf
  266. fi
  267. # Disable SSL compression to defeat BEAST attack
  268. grep no_sslcompression= $config_dir/miniserv.conf >/dev/null
  269. if [ "$?" != "0" ]; then
  270. echo no_sslcompression=1 >> $config_dir/miniserv.conf
  271. fi
  272. # Tighten SSL security
  273. grep no_ssl2= $config_dir/miniserv.conf >/dev/null
  274. if [ "$?" != "0" ]; then
  275. echo no_ssl2=1 >> $config_dir/miniserv.conf
  276. fi
  277. grep no_ssl3= $config_dir/miniserv.conf >/dev/null
  278. if [ "$?" != "0" ]; then
  279. echo no_ssl3=1 >> $config_dir/miniserv.conf
  280. fi
  281. grep no_tls1= $config_dir/miniserv.conf >/dev/null
  282. if [ "$?" != "0" ]; then
  283. echo no_tls1=1 >> $config_dir/miniserv.conf
  284. fi
  285. grep no_tls1_1= $config_dir/miniserv.conf >/dev/null
  286. if [ "$?" != "0" ]; then
  287. echo no_tls1_1=1 >> $config_dir/miniserv.conf
  288. fi
  289. # Make Perl crypt MD5 the default
  290. grep md5pass= $config_dir/config >/dev/null
  291. if [ "$?" != "0" ]; then
  292. echo md5pass=1 >> $config_dir/config
  293. fi
  294. # Set a special theme if none was set before
  295. if [ "$theme" = "" ]; then
  296. theme=`cat "$wadir/defaulttheme" 2>/dev/null`
  297. fi
  298. oldthemeline=`grep "^theme=" $config_dir/config`
  299. oldtheme=`echo $oldthemeline | sed -e 's/theme=//g'`
  300. if [ "$theme" != "" ] && [ "$oldthemeline" = "" ] && [ -d "$wadir/$theme" ]; then
  301. themelist=$theme
  302. fi
  303. # Set a special overlay if none was set before
  304. if [ "$overlay" = "" ]; then
  305. overlay=`cat "$wadir/defaultoverlay" 2>/dev/null`
  306. fi
  307. if [ "$overlay" != "" ] && [ "$theme" != "" ] && [ -d "$wadir/$overlay" ]; then
  308. themelist="$themelist $overlay"
  309. fi
  310. # Apply the theme and maybe overlay
  311. if [ "$themelist" != "" ]; then
  312. echo "theme=$themelist" >> $config_dir/config
  313. echo "preroot=$themelist" >> $config_dir/miniserv.conf
  314. fi
  315. # If the old blue-theme is still in use, change it (new in 1.730)
  316. oldtheme=`grep "^theme=" $config_dir/config | sed -e 's/theme=//g'`
  317. if [ "$oldtheme" = "blue-theme" ]; then
  318. sed -i -e 's/theme=blue-theme/theme=gray-theme/g' $config_dir/config
  319. sed -i -e 's/preroot=blue-theme/preroot=gray-theme/g' $config_dir/miniserv.conf
  320. fi
  321. # Set the product field in the global config
  322. grep product= $config_dir/config >/dev/null
  323. if [ "$?" != "0" ]; then
  324. echo product=webmin >> $config_dir/config
  325. fi
  326. # If password delays are not specifically disabled, enable them
  327. grep passdelay= $config_dir/miniserv.conf >/dev/null
  328. if [ "$?" != "0" ]; then
  329. echo passdelay=1 >> $config_dir/miniserv.conf
  330. fi
  331. echo "Changing ownership and permissions.."
  332. # Make all config dirs non-world-readable
  333. for m in $newmods; do
  334. chown -R root:root $config_dir/$m
  335. chmod -R og-rw $config_dir/$m
  336. done
  337. # Make miniserv config files non-world-readable
  338. for f in miniserv.conf miniserv.users; do
  339. chown -R root:root $config_dir/$f
  340. chmod -R og-rw $config_dir/$f
  341. done
  342. chmod +r $config_dir/version
  343. # Fix up bad permissions from some older installs
  344. for m in ldap-client ldap-server ldap-useradmin mailboxes mysql postgresql servers virtual-server; do
  345. if [ -d "$config_dir/$m" ]; then
  346. chown root:root $config_dir/$m
  347. chmod og-rw $config_dir/$m
  348. chmod og-rw $config_dir/$m/config 2>/dev/null
  349. fi
  350. done
  351. echo "..done"
  352. echo ""
  353. # This executes all postinstall.pl for every module
  354. # If you do bump, you should look at the specific changes they do with this command in root folder:
  355. # find . -name postinstall.pl -exec cat {} \; -print
  356. # Generally they are safe to run 'cause they change only user's config in /etc/webmin
  357. # or setup some cron jobs
  358. if [ "$nopostinstall" = "" ]; then
  359. echo "Running postinstall scripts.. (Please ignore any possible errors)"
  360. (cd "$wadir" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/run-postinstalls.pl")
  361. echo "..done"
  362. echo ""
  363. fi
  364. # Enable background collection
  365. if [ "$upgrading" != 1 -a -r $config_dir/system-status/enable-collection.pl ]; then
  366. echo "Enabling background status collection.. (Please ignore any possible errors)"
  367. $config_dir/system-status/enable-collection.pl 5
  368. echo "..done"
  369. echo ""
  370. fi