b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #!/bin/sh /etc/rc.common |
| 2 | |
| 3 | START=90 |
| 4 | |
| 5 | USE_PROCD=1 |
| 6 | PROG=/usr/bin/emailrelay |
| 7 | NAME=emailrelay |
| 8 | |
| 9 | |
| 10 | emailrelay_instance() |
| 11 | { |
| 12 | local enabled mode port remote_clients server_tls server_auth extra_cmdline smarthost client_tls client_auth address_verifier domain anonymous |
| 13 | |
| 14 | config_get_bool enabled "$1" enabled |
| 15 | config_get mode "$1" mode |
| 16 | config_get port "$1" port |
| 17 | config_get_bool remote_clients "$1" remote_clients |
| 18 | config_get server_tls "$1" server_tls |
| 19 | config_get server_auth "$1" server_auth |
| 20 | config_get extra_cmdline "$1" extra_cmdline |
| 21 | config_get smarthost "$1" smarthost |
| 22 | config_get_bool client_tls "$1" client_tls |
| 23 | config_get client_auth "$1" client_auth |
| 24 | config_get address_verifier "$1" address_verifier |
| 25 | config_get domain "$1" domain |
| 26 | config_get_bool anonymous "$1" anonymous |
| 27 | |
| 28 | [ "$enabled" = 0 ] && return 1 |
| 29 | |
| 30 | procd_open_instance |
| 31 | procd_set_param command "$PROG" --no-daemon |
| 32 | |
| 33 | case "$mode" in |
| 34 | "server"|\ |
| 35 | "proxy") |
| 36 | procd_append_param command "--as-${mode}" |
| 37 | [ -n "$smarthost" ] && procd_append_param command "$smarthost" |
| 38 | [ -n "$port" ] && procd_append_param command --port "$port" |
| 39 | [ "$remote_clients" = 1 ] && procd_append_param command --remote-clients |
| 40 | [ -n "$server_tls" ] && procd_append_param command --server-tls "$server_tls" |
| 41 | [ -n "$server_auth" ] && procd_append_param command --server-auth "$server_auth" |
| 42 | [ "$client_tls" = 1 ] && procd_append_param command --client-tls |
| 43 | [ -n "$client_auth" ] && procd_append_param command --client-auth "$client_auth" |
| 44 | [ -n "$address_verifier" ] && procd_append_param command --address-verifier "$address_verifier" |
| 45 | [ -n "$domain" ] && procd_append_param command --domain "$domain" |
| 46 | [ "$anonymous" = 1 ] && procd_append_param command --anonymous |
| 47 | ;; |
| 48 | "cmdline") |
| 49 | # empty by intention (just append extra_cmdline) |
| 50 | ;; |
| 51 | *) |
| 52 | echo "no mode specified" |
| 53 | return 1 |
| 54 | ;; |
| 55 | esac |
| 56 | |
| 57 | [ -n "$extra_cmdline" ] && procd_append_param command $extra_cmdline |
| 58 | |
| 59 | procd_set_param respawn |
| 60 | |
| 61 | procd_close_instance |
| 62 | } |
| 63 | |
| 64 | |
| 65 | start_service() |
| 66 | { |
| 67 | [ ! -d /var/spool/emailrelay ] && mkdir -p /var/spool/emailrelay |
| 68 | |
| 69 | config_load "${NAME}" |
| 70 | config_foreach emailrelay_instance emailrelay |
| 71 | } |