#!/bin/bash
# ---------------------------------------------------------------------
# An Openbox pipemenu for use with LibreOffice and CrunchBang Linux.
# Written for CrunchBang Linux <http://crunchbang.org/>
# by Philip Newborough (aka corenominal) <mail@philipnewborough.co.uk>
# Ported to #!++ <https://crunchbangplusplus.org>
# by Ben Young <computermouth@crunchbangplusplus.org>
# Ported to Manjaro <https://manjaro.github.io/>
# by Daniel Napora <napcok@gmail.com>
# ---------------------------------------------------------------------

if ! . mabox-include.cfg 2> /dev/null; then
    echo '  Failed to locate mabox-include.cfg in PATH' >&2
    exit 1
fi

if [[ $1 = '--install' ]]; then
    terminator --title='Install LibreOffice' --command='mabox-libreoffice-pipemenu --install-lo'

elif [[ $1 = '--install-lo' ]]; then
    promptInstall 'LIBREOFFICE' 'LibreOffice' 'libreoffice-still'

else
    # Pipemenu
    menuStart

    tools=('writer' 'calc' 'impress' 'draw' 'base')

    for curTool in "${tools[@]}"; do
        if type "lo$curTool" &> /dev/null; then
            INSTALLED=true
            menuItem "${curTool^}" "lo$curTool"
        fi
    done

    [[ ! $INSTALLED ]] &&
        menuItem 'Install LibreOffice' 'mabox-libreoffice-pipemenu --install'

    menuEnd
fi
exit 0
