meillo@0: #!/bin/sh -e meillo@0: meillo@0: # source debconf library meillo@0: . /usr/share/debconf/confmodule meillo@0: meillo@0: CONFIGFILE=/etc/masqmail/masqmail.conf meillo@0: WORKTMP=$CONFIGFILE.tmp meillo@0: DEBCONFTMP=$CONFIGFILE.debconf meillo@0: meillo@0: DEFAULTSFILE=/etc/default/masqmail meillo@0: DEBDEFTMP=$DEFAULTSFILE.debconf meillo@0: meillo@0: create_db_conf (){ meillo@0: rm -f $WORKTMP $DEBCONFTMP meillo@0: meillo@0: cat >> $DEBCONFTMP << EOF meillo@0: ### BEGIN DEBCONF SECTION meillo@0: # Do not edit within this region if you want your changes to be preserved by meillo@0: # debconf. Instead, make changes after the "### END DEBCONF SECTION" line. meillo@0: EOF meillo@0: meillo@0: db_get masqmail/host_name || true meillo@0: echo "host_name=\"$RET\"" >> $DEBCONFTMP meillo@0: db_get masqmail/local_hosts || true meillo@0: echo "local_hosts=\"$RET\"" >> $DEBCONFTMP meillo@0: db_get masqmail/local_nets || true meillo@0: echo "local_nets=\"$RET\"" >> $DEBCONFTMP meillo@0: db_get masqmail/listen_addresses || true meillo@0: echo "listen_addresses=\"$RET\"" >> $DEBCONFTMP meillo@0: meillo@0: echo "spool_dir=\"/var/spool/masqmail\"" >> $DEBCONFTMP meillo@0: echo "mail_dir=\"/var/mail\"" >> $DEBCONFTMP meillo@0: echo "log_dir=\"/var/log/masqmail\"" >> $DEBCONFTMP meillo@0: echo "do_queue=false" >> $DEBCONFTMP meillo@0: meillo@0: db_get masqmail/use_syslog || true meillo@0: echo "use_syslog=$RET" >> $DEBCONFTMP meillo@0: meillo@0: db_get masqmail/online_detect || true meillo@0: echo "online_detect=$RET" >> $DEBCONFTMP meillo@0: if [ "$RET" = "file" ] ; then meillo@0: db_get masqmail/online_file || true meillo@0: echo "online_file=\"$RET\"" >> $DEBCONFTMP meillo@0: else meillo@0: db_get masqmail/online_pipe || true meillo@0: echo "online_pipe=\"$RET\"" >> $DEBCONFTMP meillo@0: fi meillo@0: meillo@0: db_get masqmail/mbox_default || true meillo@0: echo "mbox_default=$RET" >> $DEBCONFTMP meillo@0: db_get masqmail/mda || true meillo@0: echo "mda=\"$RET\"" >> $DEBCONFTMP meillo@0: meillo@0: echo "alias_file=/etc/aliases" >> $DEBCONFTMP meillo@0: db_get masqmail/alias_local_caseless || true meillo@0: echo "alias_local_caseless=\"$RET\"" >> $DEBCONFTMP meillo@0: meillo@0: cat >> $DEBCONFTMP << EOF meillo@0: ### END DEBCONF SECTION meillo@0: EOF meillo@0: } meillo@0: meillo@0: write_db_conf (){ meillo@0: meillo@0: if [ -e $CONFIGFILE ]; then meillo@0: # does the file have debconf markers in it? meillo@0: if egrep -q '^### BEGIN DEBCONF SECTION' $CONFIGFILE && \ meillo@0: egrep -q '^### END DEBCONF SECTION' $CONFIGFILE; then meillo@0: # see if the beginning of the file was left alone; sed cannot backtrack in meillo@0: # an address range meillo@0: if ! head -1 $CONFIGFILE | egrep -q '^### BEGIN DEBCONF SECTION'; then meillo@0: # sick, sick, sick meillo@0: LINES=$(sed -n '1,/^### BEGIN DEBCONF SECTION/p' < $CONFIGFILE | wc -l) meillo@0: sed -n 1,$(( $LINES - 1 ))p < $CONFIGFILE > $WORKTMP meillo@0: fi meillo@0: cat $DEBCONFTMP >> $WORKTMP meillo@0: sed -n '/^### END DEBCONF SECTION/,$p' < $CONFIGFILE | tail +2 >> $WORKTMP meillo@0: else meillo@0: echo "Existing $CONFIGFILE has missing or half-open debconf region;" >&2; meillo@0: echo "not writing masqmail configuration file." >&2; meillo@0: exit 1 meillo@0: fi meillo@0: else meillo@0: cat >> $DEBCONFTMP << EOF meillo@0: # meillo@0: # include the locations of your route and get configurations here. meillo@0: # Examples: meillo@0: # online_routes.default = "/etc/masqmail/default.route" meillo@0: # online_gets.default = "/etc/masqmail/default.get" meillo@0: # You can have more of those, with '.default' replaced with other meillo@0: # names. See man 8 masqmail.conf. meillo@0: # meillo@0: EOF meillo@0: cp $DEBCONFTMP $WORKTMP meillo@0: fi meillo@0: meillo@0: mv $WORKTMP $CONFIGFILE meillo@0: meillo@0: # rm -f $WORKTMP $DEBCONFTMP meillo@0: } meillo@0: meillo@0: create_db_defaults () { meillo@0: cat >> $DEBDEFTMP << EOF meillo@0: # meillo@0: # better use 'dpkg-reconfigure masqmail' meillo@0: # instead of editing by hand meillo@0: # meillo@0: EOF meillo@0: meillo@0: db_get masqmail/init_smtp_daemon || true meillo@0: echo "INIT_SMTP_DAEMON=\"$RET\"" >> $DEBDEFTMP meillo@0: db_get masqmail/init_queue_daemon || true meillo@0: echo "INIT_QUEUE_DAEMON=\"$RET\"" >> $DEBDEFTMP meillo@0: db_get masqmail/init_fetch_daemon || true meillo@0: echo "INIT_FETCH_DAEMON=\"$RET\"" >> $DEBDEFTMP meillo@0: meillo@0: echo "#" >> $DEBDEFTMP meillo@0: meillo@0: db_get masqmail/queue_daemon_ival || true meillo@0: echo "QUEUE_DAEMON_IVAL=\"$RET\"" >> $DEBDEFTMP meillo@0: db_get masqmail/fetch_daemon_ival || true meillo@0: echo "FETCH_DAEMON_IVAL=\"$RET\"" >> $DEBDEFTMP meillo@0: meillo@0: echo "#" >> $DEBDEFTMP meillo@0: meillo@0: db_get masqmail/ipup_runqueue || true meillo@0: echo "IPUP_RUNQUEUE=\"$RET\"" >> $DEBDEFTMP meillo@0: db_get masqmail/ipup_fetch || true meillo@0: echo "IPUP_FETCH=\"$RET\"" >> $DEBDEFTMP meillo@0: meillo@0: db_get masqmail/ifup_ifaces || true meillo@0: echo "IFUP_IFACES=\"$RET\"" >> $DEBDEFTMP meillo@0: } meillo@0: meillo@0: write_db_defaults () { meillo@0: mv $DEBDEFTMP $DEFAULTSFILE meillo@0: } meillo@0: meillo@0: case "$1" in meillo@0: configure) meillo@0: meillo@0: # Create spool and log directories meillo@0: install -d -omail -gmail /var/log/masqmail meillo@0: install -d -omail -gmail /var/spool/masqmail meillo@0: install -d -omail -gmail /var/spool/masqmail/input meillo@0: install -d -omail -gmail /var/spool/masqmail/lock meillo@0: install -d -omail -gmail /var/spool/masqmail/popuidl meillo@0: meillo@0: db_get masqmail/manage_config_with_debconf || true meillo@0: if [ "$RET" = "true" ]; then meillo@0: db_get masqmail/move_existing_nondebconf_config || true meillo@0: if [ "$RET" = "true" ]; then meillo@0: create_db_conf meillo@0: write_db_conf meillo@0: fi meillo@0: create_db_defaults meillo@0: write_db_defaults meillo@0: fi meillo@0: meillo@0: ;; meillo@0: meillo@0: abort-upgrade|abort-remove|abort-deconfigure) meillo@0: ;; meillo@0: esac meillo@0: meillo@0: #DEBHELPER#