postfix-install 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. # $OpenBSD: postfix-install,v 1.6 2014/07/03 16:02:23 brad Exp $
  3. #
  4. # Post-installation setup of postfix
  5. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  6. CONFIG_DIR=${SYSCONFDIR}/postfix
  7. SAMPLE_CONFIG_DIR=${PREFIX}/share/examples/postfix
  8. SPOOL_DIR=/var/spool/postfix
  9. DATA_DIR=/var/postfix
  10. # Function: set up the postfix spool dir / chroot area
  11. #
  12. do_spooldir()
  13. {
  14. echo "-> Creating Postfix spool directory and chroot area under $SPOOL_DIR"
  15. [ -d $SPOOL_DIR ] || install -d -o root -g wheel -m 755 $SPOOL_DIR
  16. [ -d $SPOOL_DIR/etc ] || install -d -o root -g wheel -m 755 $SPOOL_DIR/etc
  17. [ -d $SPOOL_DIR/dev ] || install -d -o root -g wheel -m 755 $SPOOL_DIR/dev
  18. for file in hosts localtime resolv.conf services ; do
  19. install -o root -g wheel -m 644 /etc/$file $SPOOL_DIR/etc
  20. done
  21. echo "-> Creating Postfix data directory under $DATA_DIR"
  22. [ -d $DATA_DIR ] || install -d -o _postfix -g wheel -m 700 $DATA_DIR
  23. }
  24. # Function: replace sendmail binaries with postfix
  25. #
  26. do_mailwrapper()
  27. {
  28. echo "-> Creating /etc/mailer.conf.postfix"
  29. cat <<MAILER | sed "s@y0y0y0@$PREFIX@g" >/etc/mailer.conf.postfix
  30. sendmail y0y0y0/sbin/sendmail
  31. send-mail y0y0y0/sbin/sendmail
  32. mailq y0y0y0/sbin/sendmail
  33. newaliases y0y0y0/sbin/sendmail
  34. MAILER
  35. chown root:wheel /etc/mailer.conf.postfix
  36. chmod 644 /etc/mailer.conf.postfix
  37. }
  38. # Function: install the postfix configuration files from the samples
  39. #
  40. do_configs()
  41. {
  42. POSTFIX="${PREFIX}/sbin/postfix"
  43. if [ -d $CONFIG_DIR ]; then
  44. if [ ! -d $CONFIG_DIR/postfix-files.d ]; then
  45. install -d -o root -g wheel -m 755 $CONFIG_DIR/postfix-files.d
  46. fi
  47. for file in main.cf.proto master.cf.proto postfix-files ; do
  48. if [ ! -f $CONFIG_DIR/$file ]; then
  49. install -o root -g wheel -m 644 $SAMPLE_CONFIG_DIR/$file $CONFIG_DIR
  50. fi
  51. done
  52. echo ""
  53. $POSTFIX upgrade-configuration
  54. echo ""
  55. echo "+---------------"
  56. echo "| The existing configuration files in $CONFIG_DIR have been preserved."
  57. echo "| You may want to compare them to the current sample files,"
  58. echo "| $SAMPLE_CONFIG_DIR, and update your configuration as needed."
  59. echo "+---------------"
  60. echo ""
  61. else
  62. install -d -o root -g wheel -m 755 $CONFIG_DIR
  63. install -d -o root -g wheel -m 755 $CONFIG_DIR/postfix-files.d
  64. install -o root -g wheel -m 644 $SAMPLE_CONFIG_DIR/* $CONFIG_DIR
  65. echo "+---------------"
  66. echo "| Configuration files have been installed in $CONFIG_DIR."
  67. echo "| Please update these files to meet your needs."
  68. echo "+---------------"
  69. fi
  70. $POSTFIX set-permissions
  71. $POSTFIX check
  72. }
  73. if [ "$1" = "install" ]; then
  74. do_mailwrapper
  75. do_spooldir
  76. fi
  77. do_configs