# -*- coding: utf-8 -*-

# set default upload host
/^[[:space:]]*default_host_main[[:space:]]*=/ {
    s/=.*$/= elho/
}

# insert elho section as last section

# temporarily store blank lines in hold space, to be able
# to insert section before them, if needed
/^[[:space:]]*$/ {
    H
    d
}

# insert elho section as last section, before local variables
/^[[:space:]]*#[[:space:]]*Local variables:/ {
    i \
\
[elho]\
method			= scp\
fqdn			= zephyr.elho.net\
incoming		= /var/www/elho.net/debian/mini-dinstall/incoming\
run_dinstall		= 0

    # append blank lines from hold space
    x
    # strip extra newline added by appending empty line
    s/^\n//
    p
    x
    b done
}

# re-insert blank lines from hold space, if non-blank line is encountered
/^$/! {
    # test whether hold space contains blank line(s)
    x
    /^\n/ {
	# strip extra newline added by appending empty line
	s/^\n//
	p
	# clear (what will become) hold space, once printed
	s/.*//
    }
    x
}

# handle elho section that already is present
/^\[elho\]/ {
    # skip over method line to fqdn
    n;n
    # update hostname, if necessary
    s@^\(fqdn[[:space:]]\+=[[:space:]]\+\)psycho\(\.elho\.net\)$@\1zephyr\2@
    n
    # update incoming path, if necessary
    s@^\(incoming[[:space:]]\+=[[:space:]]\+/var/www/\)\(debian/mini-dinstall/incoming\)$@\1elho.net/\2@

    # copy remaining file unchanged
    : done
    n
    b done
}
