You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

post-install 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. #!/bin/sh
  2. # To view the formatted manual page of this file, type:
  3. # POSTFIXSOURCE/mantools/srctoman - post-install | nroff -man
  4. #++
  5. # NAME
  6. # post-install
  7. # SUMMARY
  8. # Postfix post-installation script
  9. # SYNOPSIS
  10. # postfix post-install [name=value] command ...
  11. # DESCRIPTION
  12. # The post-install script performs the finishing touch of a Postfix
  13. # installation, after the executable programs and configuration
  14. # files are installed. Usage is one of the following:
  15. # .IP o
  16. # While installing Postfix from source code on the local machine, the
  17. # script is run by the postfix-install script to update selected file
  18. # or directory permissions and to update Postfix configuration files.
  19. # .IP o
  20. # While installing Postfix from a pre-built package, the script is run
  21. # by the package management procedure to set all file or directory
  22. # permissions and to update Postfix configuration files.
  23. # .IP o
  24. # The script can be used to change installation parameter settings such
  25. # as mail_owner or setgid_group after Postfix is already installed.
  26. # .IP o
  27. # The script can be used to upgrade configuration files and to upgrade
  28. # file/directory permissions of a secondary Postfix instance.
  29. # .IP o
  30. # At Postfix start-up time, the script is run from "postfix check" to
  31. # create missing queue directories.
  32. # .PP
  33. # The post-install script is controlled by installation parameters.
  34. # Specific parameters are described at the end of this document.
  35. # All installation parameters must be specified ahead of time via
  36. # one of the methods described below.
  37. #
  38. # Arguments
  39. # .IP create-missing
  40. # Create missing queue directories with ownerships and permissions
  41. # according to the contents of $daemon_directory/postfix-files
  42. # and optionally in $daemon_directory/postfix-files.d/*, using
  43. # the mail_owner and setgid_group parameter settings from the
  44. # command line, process environment or from the installed
  45. # main.cf file.
  46. #
  47. # This is required at Postfix start-up time.
  48. # .IP set-permissions
  49. # Set all file/directory ownerships and permissions according to the
  50. # contents of $daemon_directory/postfix-files and optionally
  51. # in $daemon_directory/postfix-files.d/*, using the mail_owner
  52. # and setgid_group parameter settings from the command line,
  53. # process environment or from the installed main.cf file.
  54. # Implies create-missing.
  55. #
  56. # This is required when installing Postfix from a pre-built package,
  57. # or when changing the mail_owner or setgid_group installation parameter
  58. # settings after Postfix is already installed.
  59. # .IP upgrade-permissions
  60. # Update ownership and permission of existing files/directories as
  61. # specified in $daemon_directory/postfix-files and optionally
  62. # in $daemon_directory/postfix-files.d/*, using the mail_owner
  63. # and setgid_group parameter settings from the command line,
  64. # process environment or from the installed main.cf file.
  65. # Implies create-missing.
  66. #
  67. # This is required when upgrading an existing Postfix instance.
  68. # .IP upgrade-configuration
  69. # Edit the installed main.cf and master.cf files, in order to account
  70. # for missing services and to fix deprecated parameter settings.
  71. #
  72. # This is required when upgrading an existing Postfix instance.
  73. # .IP upgrade-source
  74. # Short-hand for: upgrade-permissions upgrade-configuration.
  75. #
  76. # This is recommended when upgrading Postfix from source code.
  77. # .IP upgrade-package
  78. # Short-hand for: set-permissions upgrade-configuration.
  79. #
  80. # This is recommended when upgrading Postfix from a pre-built package.
  81. # .IP first-install-reminder
  82. # Remind the user that they still need to configure main.cf and the
  83. # aliases file, and that newaliases still needs to be run.
  84. #
  85. # This is recommended when Postfix is installed for the first time.
  86. # MULTIPLE POSTFIX INSTANCES
  87. # .ad
  88. # .fi
  89. # Multiple Postfix instances on the same machine can share command and
  90. # daemon program files but must have separate configuration and queue
  91. # directories.
  92. #
  93. # To create a secondary Postfix installation on the same machine,
  94. # copy the configuration files from the primary Postfix instance to
  95. # a secondary configuration directory and execute:
  96. #
  97. # postfix post-install config_directory=secondary-config-directory \e
  98. # .in +4
  99. # queue_directory=secondary-queue-directory \e
  100. # .br
  101. # create-missing
  102. # .PP
  103. # This creates secondary Postfix queue directories, sets their access
  104. # permissions, and saves the specified installation parameters to the
  105. # secondary main.cf file.
  106. #
  107. # Be sure to list the secondary configuration directory in the
  108. # alternate_config_directories parameter in the primary main.cf file.
  109. #
  110. # To upgrade a secondary Postfix installation on the same machine,
  111. # execute:
  112. #
  113. # postfix post-install config_directory=secondary-config-directory \e
  114. # .in +4
  115. # upgrade-permissions upgrade-configuration
  116. # INSTALLATION PARAMETER INPUT METHODS
  117. # .ad
  118. # .fi
  119. # Parameter settings can be specified through a variety of
  120. # mechanisms. In order of decreasing precedence these are:
  121. # .IP "command line"
  122. # Parameter settings can be given as name=value arguments on
  123. # the post-install command line. These have the highest precedence.
  124. # Settings that override the installed main.cf file are saved.
  125. # .IP "process environment"
  126. # Parameter settings can be given as name=value environment
  127. # variables.
  128. # Settings that override the installed main.cf file are saved.
  129. # .IP "installed configuration files"
  130. # If a parameter is not specified via the command line or via the
  131. # process environment, post-install will attempt to extract its
  132. # value from the already installed Postfix main.cf configuration file.
  133. # These settings have the lowest precedence.
  134. # INSTALLATION PARAMETER DESCRIPTION
  135. # .ad
  136. # .fi
  137. # The description of installation parameters is as follows:
  138. # .IP config_directory
  139. # The directory for Postfix configuration files.
  140. # .IP daemon_directory
  141. # The directory for Postfix daemon programs. This directory
  142. # should not be in the command search path of any users.
  143. # .IP command_directory
  144. # The directory for Postfix administrative commands. This
  145. # directory should be in the command search path of adminstrative users.
  146. # .IP queue_directory
  147. # The directory for Postfix queues.
  148. # .IP data_directory
  149. # The directory for Postfix writable data files (caches, etc.).
  150. # .IP sendmail_path
  151. # The full pathname for the Postfix sendmail command.
  152. # This is the Sendmail-compatible mail posting interface.
  153. # .IP newaliases_path
  154. # The full pathname for the Postfix newaliases command.
  155. # This is the Sendmail-compatible command to build alias databases
  156. # for the Postfix local delivery agent.
  157. # .IP mailq_path
  158. # The full pathname for the Postfix mailq command.
  159. # This is the Sendmail-compatible command to list the mail queue.
  160. # .IP mail_owner
  161. # The owner of the Postfix queue. Its numerical user ID and group ID
  162. # must not be used by any other accounts on the system.
  163. # .IP setgid_group
  164. # The group for mail submission and for queue management commands.
  165. # Its numerical group ID must not be used by any other accounts on the
  166. # system, not even by the mail_owner account.
  167. # .IP html_directory
  168. # The directory for the Postfix HTML files.
  169. # .IP manpage_directory
  170. # The directory for the Postfix on-line manual pages.
  171. # .IP sample_directory
  172. # The directory for the Postfix sample configuration files.
  173. # This feature is obsolete as of Postfix 2.1.
  174. # .IP readme_directory
  175. # The directory for the Postfix README files.
  176. # SEE ALSO
  177. # postfix-install(1) Postfix primary installation script.
  178. # FILES
  179. # $config_directory/main.cf, Postfix installation parameters.
  180. # $daemon_directory/postfix-files, installation control file.
  181. # $daemon_directory/postfix-files.d/*, optional control files.
  182. # $config_directory/install.cf, obsolete configuration file.
  183. # LICENSE
  184. # .ad
  185. # .fi
  186. # The Secure Mailer license must be distributed with this software.
  187. # AUTHOR(S)
  188. # Wietse Venema
  189. # IBM T.J. Watson Research
  190. # P.O. Box 704
  191. # Yorktown Heights, NY 10598, USA
  192. #--
  193. umask 022
  194. PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc:/usr/contrib/bin:/usr/gnu/bin:/usr/ucb:/usr/bsd
  195. SHELL=/bin/sh
  196. IFS="
  197. "
  198. BACKUP_IFS="$IFS"
  199. debug=:
  200. #debug=echo
  201. MOST_PARAMETERS="command_directory daemon_directory data_directory
  202. html_directory mail_owner mailq_path manpage_directory
  203. newaliases_path queue_directory readme_directory sample_directory
  204. sendmail_path setgid_group"
  205. NON_SHARED="config_directory queue_directory data_directory"
  206. USAGE="Usage: $0 [name=value] command
  207. create-missing Create missing queue directories.
  208. upgrade-source When installing or upgrading from source code.
  209. upgrade-package When installing or upgrading from pre-built package.
  210. first-install-reminder Remind of mandatory first-time configuration steps.
  211. name=value Specify an installation parameter".
  212. # Process command-line options and parameter settings. Work around
  213. # brain damaged shells. "IFS=value command" should not make the
  214. # IFS=value setting permanent. But some broken standard allows it.
  215. create=; set_perms=; upgrade_perms=; upgrade_conf=; first_install_reminder=
  216. obsolete=; keep_list=;
  217. for arg
  218. do
  219. case $arg in
  220. *=*) IFS= eval $arg; IFS="$BACKUP_IFS";;
  221. create-missing) create=1;;
  222. set-perm*) create=1; set_perms=1;;
  223. upgrade-perm*) create=1; upgrade_perms=1;;
  224. upgrade-conf*) upgrade_conf=1;;
  225. upgrade-source) create=1; upgrade_conf=1; upgrade_perms=1;;
  226. upgrade-package) create=1; upgrade_conf=1; set_perms=1;;
  227. first-install*) first_install_reminder=1;;
  228. *) echo "$0: Error: $USAGE" 1>&2; exit 1;;
  229. esac
  230. shift
  231. done
  232. # Sanity checks.
  233. test -n "$create$upgrade_conf$first_install_reminder" || {
  234. echo "$0: Error: $USAGE" 1>&2
  235. exit 1
  236. }
  237. # Bootstrapping problem.
  238. if [ -n "$command_directory" ]
  239. then
  240. POSTCONF="$command_directory/postconf"
  241. else
  242. POSTCONF="postconf"
  243. fi
  244. $POSTCONF -d mail_version >/dev/null 2>/dev/null || {
  245. echo $0: Error: no $POSTCONF command found. 1>&2
  246. echo Re-run this command as $0 command_directory=/some/where. 1>&2
  247. exit 1
  248. }
  249. # Also used to require license etc. files only in the default instance.
  250. def_config_directory=`$POSTCONF -d -h config_directory` || exit 1
  251. test -n "$config_directory" ||
  252. config_directory="$def_config_directory"
  253. test -d "$config_directory" || {
  254. echo $0: Error: $config_directory is not a directory. 1>&2
  255. exit 1
  256. }
  257. # If this is a secondary instance, don't touch shared files.
  258. # XXX Solaris does not have "test -e".
  259. instances=`test ! -f $def_config_directory/main.cf ||
  260. $POSTCONF -c $def_config_directory -h multi_instance_directories |
  261. sed 's/,/ /'` || exit 1
  262. update_shared_files=1
  263. for name in $instances
  264. do
  265. case "$name" in
  266. "$def_config_directory") ;;
  267. "$config_directory") update_shared_files=; break;;
  268. esac
  269. done
  270. test -f $daemon_directory/postfix-files || {
  271. echo $0: Error: $daemon_directory/postfix-files is not a file. 1>&2
  272. exit 1
  273. }
  274. # SunOS5 fmt(1) truncates lines > 1000 characters.
  275. fake_fmt() {
  276. sed '
  277. :top
  278. /^\( *\)\([^ ][^ ]*\) */{
  279. s//\1\2\
  280. \1/
  281. P
  282. D
  283. b top
  284. }
  285. ' | fmt
  286. }
  287. case `uname -s` in
  288. HP-UX*) FMT=cat;;
  289. SunOS*) FMT=fake_fmt;;
  290. *) FMT=fmt;;
  291. esac
  292. # If a parameter is not set via the command line or environment,
  293. # try to use settings from installed configuration files.
  294. # Extract parameter settings from the obsolete install.cf file, as
  295. # a transitional aid.
  296. grep setgid_group $config_directory/main.cf >/dev/null 2>&1 || {
  297. test -f $config_directory/install.cf && {
  298. for name in sendmail_path newaliases_path mailq_path setgid manpages
  299. do
  300. eval junk=\$$name
  301. case "$junk" in
  302. "") eval unset $name;;
  303. esac
  304. eval : \${$name="\`. $config_directory/install.cf; echo \$$name\`"} \
  305. || exit 1
  306. done
  307. : ${setgid_group=$setgid}
  308. : ${manpage_directory=$manpages}
  309. }
  310. }
  311. # Extract parameter settings from the installed main.cf file.
  312. test -f $config_directory/main.cf && {
  313. for name in $MOST_PARAMETERS
  314. do
  315. eval junk=\$$name
  316. case "$junk" in
  317. "") eval unset $name;;
  318. esac
  319. eval : \${$name=\`$POSTCONF -c $config_directory -h $name\`} || exit 1
  320. done
  321. }
  322. # Sanity checks
  323. case $manpage_directory in
  324. no) echo $0: Error: manpage_directory no longer accepts \"no\" values. 1>&2
  325. echo Try again with \"$0 manpage_directory=/pathname ...\". 1>&2; exit 1;;
  326. esac
  327. case $setgid_group in
  328. no) echo $0: Error: setgid_group no longer accepts \"no\" values. 1>&2
  329. echo Try again with \"$0 setgid_group=groupname ...\" 1>&2; exit 1;;
  330. esac
  331. for path in "$daemon_directory" "$command_directory" "$queue_directory" \
  332. "$sendmail_path" "$newaliases_path" "$mailq_path" "$manpage_directory"
  333. do
  334. case "$path" in
  335. /*) ;;
  336. *) echo $0: Error: \"$path\" should be an absolute path name. 1>&2; exit 1;;
  337. esac
  338. done
  339. for path in "$html_directory" "$readme_directory"
  340. do
  341. case "$path" in
  342. /*) ;;
  343. no) ;;
  344. *) echo $0: Error: \"$path\" should be \"no\" or an absolute path name. 1>&2; exit 1;;
  345. esac
  346. done
  347. # Find out what parameters were not specified via command line,
  348. # via environment, or via installed configuration files.
  349. missing=
  350. for name in $MOST_PARAMETERS
  351. do
  352. eval test -n \"\$$name\" || missing="$missing $name"
  353. done
  354. # All parameters must be specified at this point.
  355. test -n "$non_interactive" -a -n "$missing" && {
  356. cat <<EOF | ${FMT} 1>&2
  357. $0: Error: some required installation parameters are not defined.
  358. - Either the parameters need to be given in the $config_directory/main.cf
  359. file from a recent Postfix installation,
  360. - Or the parameters need to be specified through the process
  361. environment.
  362. - Or the parameters need to be specified as name=value arguments
  363. on the $0 command line,
  364. The following parameters were missing:
  365. $missing
  366. EOF
  367. exit 1
  368. }
  369. POSTCONF="$command_directory/postconf"
  370. # Save settings, allowing command line/environment override.
  371. override=
  372. for name in $MOST_PARAMETERS
  373. do
  374. eval test \"\$$name\" = \"`$POSTCONF -c $config_directory -h $name`\" || {
  375. override=1
  376. break
  377. }
  378. done
  379. test -n "$override" && {
  380. $POSTCONF -c $config_directory -e \
  381. "daemon_directory = $daemon_directory" \
  382. "command_directory = $command_directory" \
  383. "queue_directory = $queue_directory" \
  384. "data_directory = $data_directory" \
  385. "mail_owner = $mail_owner" \
  386. "setgid_group = $setgid_group" \
  387. "sendmail_path = $sendmail_path" \
  388. "mailq_path = $mailq_path" \
  389. "newaliases_path = $newaliases_path" \
  390. "html_directory = $html_directory" \
  391. "manpage_directory = $manpage_directory" \
  392. "sample_directory = $sample_directory" \
  393. "readme_directory = $readme_directory" \
  394. || exit 1
  395. }
  396. # Use file/directory status information in $daemon_directory/postfix-files.
  397. test -n "$create" && {
  398. postfix_files_d=$daemon_directory/postfix-files.d
  399. for postfix_file in $daemon_directory/postfix-files \
  400. `test -d $postfix_files_d && { find $postfix_files_d -type f | sort; }`
  401. do
  402. exec <$postfix_file || exit 1
  403. while IFS=: read path type owner group mode flags junk
  404. do
  405. IFS="$BACKUP_IFS"
  406. set_permission=
  407. # Skip comments. Skip shared files, if updating a secondary instance.
  408. case $path in
  409. [$]*) case "$update_shared_files" in
  410. 1) $debug keep non-shared or shared $path;;
  411. *) non_shared=
  412. for name in $NON_SHARED
  413. do
  414. case $path in
  415. "\$$name"*) non_shared=1; break;;
  416. esac
  417. done
  418. case "$non_shared" in
  419. 1) $debug keep non-shared $path;;
  420. *) $debug skip shared $path; continue;;
  421. esac;;
  422. esac;;
  423. *) continue;;
  424. esac
  425. # Skip hard links and symbolic links.
  426. case $type in
  427. [hl]) continue;;
  428. [df]) ;;
  429. *) echo unknown type $type for $path in $postfix_file 1>&2; exit 1;;
  430. esac
  431. # Expand $name, and canonicalize null fields.
  432. for name in path owner group flags
  433. do
  434. eval junk=\${$name}
  435. case $junk in
  436. [$]*) eval $name=$junk;;
  437. -) eval $name=;;
  438. *) ;;
  439. esac
  440. done
  441. # Skip uninstalled files.
  442. case $path in
  443. no|no/*) continue;;
  444. esac
  445. # Pick up the flags.
  446. case $flags in *u*) upgrade_flag=1;; *) upgrade_flag=;; esac
  447. case $flags in *c*) create_flag=1;; *) create_flag=;; esac
  448. case $flags in *r*) recursive="-R";; *) recursive=;; esac
  449. case $flags in *o*) obsolete_flag=1;; *) obsolete_flag=;; esac
  450. case $flags in *[1i]*) test ! -r "$path" -a "$config_directory" != \
  451. "$def_config_directory" && continue;; esac
  452. # Flag obsolete objects. XXX Solaris 2..9 does not have "test -e".
  453. if [ -n "$obsolete_flag" ]
  454. then
  455. test -r $path -a "$type" != "d" && obsolete="$obsolete $path"
  456. continue;
  457. else
  458. keep_list="$keep_list $path"
  459. fi
  460. # Create missing directories with proper owner/group/mode settings.
  461. if [ -n "$create" -a "$type" = "d" -a -n "$create_flag" -a ! -d "$path" ]
  462. then
  463. mkdir $path || exit 1
  464. set_permission=1
  465. # Update all owner/group/mode settings.
  466. elif [ -n "$set_perms" ]
  467. then
  468. set_permission=1
  469. # Update obsolete owner/group/mode settings.
  470. elif [ -n "$upgrade_perms" -a -n "$upgrade_flag" ]
  471. then
  472. set_permission=1
  473. fi
  474. test -n "$set_permission" && {
  475. chown $recursive $owner $path || exit 1
  476. test -z "$group" || chgrp $recursive $group $path || exit 1
  477. # Don't "chmod -R"; queue file status is encoded in mode bits.
  478. if [ "$type" = "d" -a -n "$recursive" ]
  479. then
  480. find $path -type d -exec chmod $mode "{}" ";"
  481. else
  482. chmod $mode $path
  483. fi || exit 1
  484. }
  485. done
  486. IFS="$BACKUP_IFS"
  487. done
  488. }
  489. # Upgrade existing Postfix configuration files if necessary.
  490. test -n "$upgrade_conf" && {
  491. # Postfix 2.0.
  492. # Add missing relay service to master.cf.
  493. grep '^relay' $config_directory/master.cf >/dev/null || {
  494. echo Editing $config_directory/master.cf, adding missing entry for relay service
  495. cat >>$config_directory/master.cf <<EOF || exit 1
  496. relay unix - - n - - smtp
  497. EOF
  498. }
  499. # Postfix 1.1.
  500. # Add missing flush service to master.cf.
  501. grep '^flush.*flush' $config_directory/master.cf >/dev/null || {
  502. echo Editing $config_directory/master.cf, adding missing entry for flush service
  503. cat >>$config_directory/master.cf <<EOF || exit 1
  504. flush unix - - n 1000? 0 flush
  505. EOF
  506. }
  507. # Postfix 2.1.
  508. # Add missing trace service to master.cf.
  509. grep 'trace.*bounce' $config_directory/master.cf >/dev/null || {
  510. echo Editing $config_directory/master.cf, adding missing entry for trace service
  511. cat >>$config_directory/master.cf <<EOF || exit 1
  512. trace unix - - n - 0 bounce
  513. EOF
  514. }
  515. # Postfix 2.1.
  516. # Add missing verify service to master.cf.
  517. grep '^verify.*verify' $config_directory/master.cf >/dev/null || {
  518. echo Editing $config_directory/master.cf, adding missing entry for verify service
  519. cat >>$config_directory/master.cf <<EOF || exit 1
  520. verify unix - - n - 1 verify
  521. EOF
  522. }
  523. # Postfix 2.1.
  524. # Fix verify service process limit.
  525. grep '^verify.*[ ]0[ ]*verify' \
  526. $config_directory/master.cf >/dev/null && {
  527. echo Editing $config_directory/master.cf, setting verify process limit to 1
  528. ed $config_directory/master.cf <<EOF || exit 1
  529. /^verify.*[ ]0[ ]*verify/
  530. s/\([ ]\)0\([ ]\)/\11\2/
  531. p
  532. w
  533. q
  534. EOF
  535. }
  536. # Postfix 1.1.
  537. # Change privileged pickup service into unprivileged.
  538. grep "^pickup[ ]*fifo[ ]*n[ ]*n" \
  539. $config_directory/master.cf >/dev/null && {
  540. echo Editing $config_directory/master.cf, making the pickup service unprivileged
  541. ed $config_directory/master.cf <<EOF || exit 1
  542. /^pickup[ ]*fifo[ ]*n[ ]*n/
  543. s/\(n[ ]*\)n/\1-/
  544. p
  545. w
  546. q
  547. EOF
  548. }
  549. # Postfix 1.1.
  550. # Change private cleanup and flush services into public.
  551. for name in cleanup flush
  552. do
  553. grep "^$name[ ]*unix[ ]*[-y]" \
  554. $config_directory/master.cf >/dev/null && {
  555. echo Editing $config_directory/master.cf, making the $name service public
  556. ed $config_directory/master.cf <<EOF || exit 1
  557. /^$name[ ]*unix[ ]*[-y]/
  558. s/[-y]/n/
  559. p
  560. w
  561. q
  562. EOF
  563. }
  564. done
  565. # Postfix 2.2.
  566. # File systems have improved since Postfix came out, and all we
  567. # require now is that defer and deferred are hashed because those
  568. # can contain lots of files.
  569. found=`$POSTCONF -c $config_directory -h hash_queue_names`
  570. missing=
  571. (echo "$found" | grep defer >/dev/null) || missing="$missing defer"
  572. (echo "$found" | grep deferred>/dev/null)|| missing="$missing deferred"
  573. test -n "$missing" && {
  574. echo fixing main.cf hash_queue_names for missing $missing
  575. $POSTCONF -c $config_directory -e hash_queue_names="$found$missing" ||
  576. exit 1
  577. }
  578. # Turn on safety nets for new features that could bounce mail that
  579. # would be accepted by a previous Postfix version.
  580. # [The "unknown_local_recipient_reject_code = 450" safety net,
  581. # introduced with Postfix 2.0 and deleted after Postfix 2.3.]
  582. # Postfix 2.0.
  583. # Add missing proxymap service to master.cf.
  584. grep '^proxymap.*proxymap' $config_directory/master.cf >/dev/null || {
  585. echo Editing $config_directory/master.cf, adding missing entry for proxymap service
  586. cat >>$config_directory/master.cf <<EOF || exit 1
  587. proxymap unix - - n - - proxymap
  588. EOF
  589. }
  590. # Postfix 2.1.
  591. # Add missing anvil service to master.cf.
  592. grep '^anvil.*anvil' $config_directory/master.cf >/dev/null || {
  593. echo Editing $config_directory/master.cf, adding missing entry for anvil service
  594. cat >>$config_directory/master.cf <<EOF || exit 1
  595. anvil unix - - n - 1 anvil
  596. EOF
  597. }
  598. # Postfix 2.2.
  599. # Add missing scache service to master.cf.
  600. grep '^scache.*scache' $config_directory/master.cf >/dev/null || {
  601. echo Editing $config_directory/master.cf, adding missing entry for scache service
  602. cat >>$config_directory/master.cf <<EOF || exit 1
  603. scache unix - - n - 1 scache
  604. EOF
  605. }
  606. # Postfix 2.2.
  607. # Add missing discard service to master.cf.
  608. grep '^discard.*discard' $config_directory/master.cf >/dev/null || {
  609. echo Editing $config_directory/master.cf, adding missing entry for discard service
  610. cat >>$config_directory/master.cf <<EOF || exit 1
  611. discard unix - - n - - discard
  612. EOF
  613. }
  614. # Postfix 2.2.
  615. # Update the tlsmgr fifo->unix service.
  616. grep "^tlsmgr[ ]*fifo[ ]" \
  617. $config_directory/master.cf >/dev/null && {
  618. echo Editing $config_directory/master.cf, updating the tlsmgr from fifo to unix service
  619. ed $config_directory/master.cf <<EOF || exit 1
  620. /^tlsmgr[ ]*fifo[ ]/
  621. s/fifo/unix/
  622. s/[0-9][0-9]*/&?/
  623. p
  624. w
  625. q
  626. EOF
  627. }
  628. # Postfix 2.2.
  629. # Add missing tlsmgr service to master.cf.
  630. grep '^tlsmgr.*tlsmgr' $config_directory/master.cf >/dev/null || {
  631. echo Editing $config_directory/master.cf, adding missing entry for tlsmgr service
  632. cat >>$config_directory/master.cf <<EOF || exit 1
  633. tlsmgr unix - - n 1000? 1 tlsmgr
  634. EOF
  635. }
  636. # Postfix 2.2.
  637. # Add missing retry service to master.cf.
  638. grep '^retry.*error' $config_directory/master.cf >/dev/null || {
  639. echo Editing $config_directory/master.cf, adding missing entry for retry service
  640. cat >>$config_directory/master.cf <<EOF || exit 1
  641. retry unix - - n - - error
  642. EOF
  643. }
  644. # Postfix 2.5.
  645. # Add missing proxywrite service to master.cf.
  646. grep '^proxywrite.*proxymap' $config_directory/master.cf >/dev/null || {
  647. echo Editing $config_directory/master.cf, adding missing entry for proxywrite service
  648. cat >>$config_directory/master.cf <<EOF || exit 1
  649. proxywrite unix - - n - 1 proxymap
  650. EOF
  651. }
  652. # Postfix 2.5.
  653. # Fix a typo in the default master.cf proxywrite entry.
  654. grep '^proxywrite.*-[ ]*proxymap' $config_directory/master.cf >/dev/null && {
  655. echo Editing $config_directory/master.cf, setting proxywrite process limit to 1
  656. ed $config_directory/master.cf <<EOF || exit 1
  657. /^proxywrite.*-[ ]*proxymap/
  658. s/-\([ ]*proxymap\)/1\1/
  659. p
  660. w
  661. q
  662. EOF
  663. }
  664. # Postfix 2.8.
  665. # Add missing postscreen service to master.cf.
  666. grep '^#*smtp.*postscreen' $config_directory/master.cf >/dev/null || {
  667. echo Editing $config_directory/master.cf, adding missing entry for postscreen TCP service
  668. cat >>$config_directory/master.cf <<EOF || exit 1
  669. #smtp inet n - n - 1 postscreen
  670. EOF
  671. }
  672. # Postfix 2.8.
  673. # Add missing smtpd (unix-domain) service to master.cf.
  674. grep '^#*smtpd.*smtpd' $config_directory/master.cf >/dev/null || {
  675. echo Editing $config_directory/master.cf, adding missing entry for smtpd unix-domain service
  676. cat >>$config_directory/master.cf <<EOF || exit 1
  677. #smtpd pass - - n - - smtpd
  678. EOF
  679. }
  680. # Postfix 2.8.
  681. # Add temporary dnsblog (unix-domain) service to master.cf.
  682. grep '^#*dnsblog.*dnsblog' $config_directory/master.cf >/dev/null || {
  683. echo Editing $config_directory/master.cf, adding missing entry for dnsblog unix-domain service
  684. cat >>$config_directory/master.cf <<EOF || exit 1
  685. #dnsblog unix - - n - 0 dnsblog
  686. EOF
  687. }
  688. # Postfix 2.8.
  689. # Add tlsproxy (unix-domain) service to master.cf.
  690. grep '^#*tlsproxy.*tlsproxy' $config_directory/master.cf >/dev/null || {
  691. echo Editing $config_directory/master.cf, adding missing entry for tlsproxy unix-domain service
  692. cat >>$config_directory/master.cf <<EOF || exit 1
  693. #tlsproxy unix - - n - 0 tlsproxy
  694. EOF
  695. }
  696. # Report (but do not remove) obsolete files.
  697. test -n "$obsolete" && {
  698. cat <<EOF | ${FMT}
  699. Note: the following files or directories still exist but are
  700. no longer part of Postfix:
  701. $obsolete
  702. EOF
  703. }
  704. # Postfix 2.9.
  705. # Safety net for incompatible changes in IPv6 defaults.
  706. # PLEASE DO NOT REMOVE THIS CODE. ITS PURPOSE IS TO AVOID AN
  707. # UNEXPECTED DROP IN PERFORMANCE AFTER UPGRADING FROM POSTFIX
  708. # BEFORE 2.9.
  709. # This code assumes that the default is "inet_protocols = ipv4"
  710. # when IPv6 support is not compiled in. See util/sys_defs.h.
  711. test "`$POSTCONF -dh inet_protocols`" = "ipv4" ||
  712. test -n "`$POSTCONF -c $config_directory -n inet_protocols`" || {
  713. cat <<EOF | ${FMT}
  714. COMPATIBILITY: editing $config_directory/main.cf, setting
  715. inet_protocols=ipv4. Specify inet_protocols explicitly if you
  716. want to enable IPv6.
  717. In a future release IPv6 will be enabled by default.
  718. EOF
  719. $POSTCONF -c $config_directory inet_protocols=ipv4 || exit 1
  720. }
  721. # Disabled because unhelpful down-stream maintainers disable the safety net.
  722. # # Postfix 2.10.
  723. # # Safety net for incompatible changes due to the introduction
  724. # # of the smtpd_relay_restrictions feature to separate the
  725. # # mail relay policy from the spam blocking policy.
  726. # # PLEASE DO NOT REMOVE THIS CODE. ITS PURPOSE IS TO PREVENT
  727. # # INBOUND MAIL FROM UNEXPECTEDLY BOUNCING AFTER UPGRADING FROM
  728. # # POSTFIX BEFORE 2.10.
  729. # test -n "`$POSTCONF -c $config_directory -n smtpd_relay_restrictions`" || {
  730. # cat <<EOF | ${FMT}
  731. # COMPATIBILITY: editing $config_directory/main.cf, overriding
  732. # smtpd_relay_restrictions to prevent inbound mail from
  733. # unexpectedly bouncing.
  734. # Specify an empty smtpd_relay_restrictions value to keep using
  735. # smtpd_recipient_restrictions as before.
  736. #EOF
  737. # $POSTCONF -c $config_directory "smtpd_relay_restrictions = \
  738. # permit_mynetworks permit_sasl_authenticated \
  739. # defer_unauth_destination" || exit 1
  740. # }
  741. }
  742. # A reminder if this is the first time Postfix is being installed.
  743. test -n "$first_install_reminder" && {
  744. ALIASES=`$POSTCONF -c $config_directory -h alias_database | sed 's/^[^:]*://'`
  745. NEWALIASES_PATH=`$POSTCONF -c $config_directory -h newaliases_path`
  746. cat <<EOF | ${FMT}
  747. Warning: you still need to edit myorigin/mydestination/mynetworks
  748. parameter settings in $config_directory/main.cf.
  749. See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html
  750. for information about dialup sites or about sites inside a
  751. firewalled network.
  752. BTW: Check your $ALIASES file and be sure to set up aliases
  753. that send mail for root and postmaster to a real person, then
  754. run $NEWALIASES_PATH.
  755. EOF
  756. }
  757. exit 0