# Warning: This file has syntactically significant, mixed whitespace.
# The heredoc bodies are indented with tabs up to the block level.
# The tabs are for block indentation in the source code.
# The spaces following the tabs are for indentation of the printed output.

## arg 1:  the new package version
post_install() {
    if [[ ! -e /var/lib/ergochat/ircd.db ]]; then
        cat <<-EOF
			==> ergochat needs to initialize the database and have
			    certificates made available prior to use.
		EOF
        mkcert_howto
    fi

    oragono_rename_info
}

## arg 1:  the new package version
## arg 2:  the old package version
post_upgrade() {
    if (("$(vercmp "$2" 2.1.0)" < 0)); then
        cat <<-EOF
			==> The tls certificate filenames in the default config have changed.
			    In /var/lib/ergochat/:
			        tls.crt -> fullchain.pem
			        tls.key -> privkey.pem

			To generate new self-signed certificates:
		EOF
        mkcert_howto
    fi

    if (("$(vercmp "$2" 2.9.1)" < 0)); then
        cat <<-EOF
			==> The default config and systemd service unit file have changed to realign with upstream.
			    /etc/ergochat.conf -> /etc/ergochat/ircd.yaml

			Please check and adjust your config file to complete the upgrade.
		EOF
    fi

    if (("$(vercmp "$2" 2.7.0)" < 0)); then
        oragono_rename_info
    fi
}

mkcert_howto() {
    cat <<-EOF
		    cd /var/lib/ergochat
		    sudo -u ergochat /usr/bin/ergochat mkcerts --conf /etc/ergochat/ircd.yaml
		    sudo -u ergochat /usr/bin/ergochat initdb --conf /etc/ergochat/ircd.yaml
	EOF
}

oragono_rename_info() {
    cat <<-EOF
		==> The oragono project has been renamed to ergo (here on the AUR, ergochat, due to a name collision). The package name, filenames, paths, and system service user have changed.
		    /etc/oragono.conf -> /etc/ergochat.conf
		    /var/lib/oragono/ -> /var/lib/ergochat/
		    sysuser oragono -> ergochat
		    etc...

		Please take care to migrate your config and data.
	EOF
}
