From b4bd21c722da92de409962d8b0032760bd39b35b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 25 Mar 2017 09:01:25 +0200 Subject: Configure email --- init | 51 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) (limited to 'init') diff --git a/init b/init index 28ec293..a725372 100755 --- a/init +++ b/init @@ -52,10 +52,35 @@ SYSTEMD_LOG_LEVEL=info /lib/systemd/systemd-udevd --daemon --resolve-names=never udevadm trigger --action=add udevadm settle || true -# Parse command line. +# Parse the kernel command line. This is complicated by the fact that the +# values can be quoted, for example: # -cmdline="$(cat /proc/cmdline)" -info "boot cmdline: $cmdline" +# foo='foo fox' +# bar="bar 'box'" +# +# First we separete quoted variables and arguments with newlines (giving +# priority to assignments). Then we replace whitespaces with newline on +# lines that don't contain quites. Finally, clean up by removing blank +# lines. +# +readarray -t cmdline < <(cat /proc/cmdline | \ + sed -r -e "s/([^ ]+=)?('[^']*'|\"[^\"]*\")/\n\1\2\n/g" | \ + sed -r -e "/['\"]/!s/ /\n/g" | + sed -r -e '/^\s*$/d') + +# Enter all buildos variables as bash variables. +# +info "command line:" +for v in "${cmdline[@]}"; do + var="$(sed -r -n -e 's/^buildos\.([^=]+)=.*$/\1/p' <<<"$v")" # Extract name. + + if [ -n "$var" ]; then + val="$(sed -r -e 's/^[^=]+=(.*)$/\1/' <<<"$v")" # Extract value. + val="$(sed -r -e "s/^('(.*)'|\"(.*)\")$/\2\3/" <<<"$val")" # Strip quoted. + info " $var=$val" + declare "$var=$val" + fi +done # Figure out network configuration and generate the corresponding # /etc/network/interfaces. @@ -200,6 +225,26 @@ bind-interfaces dhcp-range=${priv_netbase}.10,${priv_netbase}.250,12h EOF +# Configure Postfix. +# +cat <<<"$hname" >/etc/mailname + +sed -r -i \ + -e "s%^(myhostname).*%\1 = $hname%" \ + -e 's%^(mydestination).*%\1 = $myhostname, localhost.localdomain, localhost%' \ + -e 's%^(mynetworks).*%\1 = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128%' \ + -e "s%^(relayhost).*%\1 = $smtp_relay%" \ + /etc/postfix/main.cf + +# Make admin alias for buildos.admin_email, redirect root to admin. +# +cat <>/etc/aliases +admin: $admin_email +root: admin +EOF + +newaliases + /bin/bash # Hand off to systemd. But first arrange to keep console output (which -- cgit v1.1