post_install() {
    if ! getent group prosody &>/dev/null; then
        groupadd -g 412 prosody >/dev/null
    fi
    if ! getent passwd prosody &>/dev/null; then
        useradd -u 412 -d /var/lib/prosody -g prosody -s /bin/nologin prosody >/dev/null
    fi

    chown prosody:prosody /var/lib/prosody

    install -d -m750 /var/log/prosody
    chown prosody:prosody /var/log/prosody

    prosody_shell=$(getent passwd prosody | cut -d: -f7)
    if [ "$prosody_shell" != '/bin/nologin' ]; then
        chsh -s /bin/nologin prosody &>/dev/null
    fi

    echo ">> Documentation: http://wiki.archlinux.org/index.php/Prosody"
    echo ">> gpasswd -a <your-user> prosody"
}

post_upgrade() {
    post_install
}

post_remove() {
    if getent passwd prosody &>/dev/null; then
        userdel prosody >/dev/null
    fi
    if getent group prosody &>/dev/null; then
        groupdel prosody >/dev/null
    fi

    paths=(/etc/prosody /var/lib/prosody /var/log/prosody
           /var/log/old/prosody)

    first=true
    for path in ${paths[@]}; do
        if [ -d $path ]; then
            if $first; then
                first=false
                echo "==> Leftover Paths:"
            fi
            echo "==> $path"
        fi
    done
}
