#!/bin/bash
# Kategorie: server
# invis-Server helper script. It shows all invis-server scripts including a short description

# Copyright (C) 2017 Dimitri Asarowski
# Copyright (C) 2017 Stefan Schäfer -- invis-server.org

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# Konfigurationsdaten
conffile="/etc/invis/invis.conf"

usage(){
echo "invis-server help
Copyright (C) 2017 Dimitri Asarowski
Copyright (C) 2017 Stefan Schäfer

Usage: invis-server [OPTION]

Options:
    all		all commands
    server	commands for server control 
    portal	commands for web portal
    apps	commands for applications
    setup	commands for setup script sine
    help    display this help and exit

Report bugs to <dimitri@invis-server.org>."
}

# Werte aus Konfigurationsdatendatei extrahieren
# $1 = Konfigurationsdatei, $2 = Parameter, $3 Wert (Feld)
getconfdata() {
    cat $1 |grep "$2" | cut -d ":" -f $3
}

printline(){

/bin/rpm -ql $VER | grep $PATH >/tmp/invis-server.lst

while read line
do
    Name=`echo $line | cut -d'/' -f4`
    Group=`head -n 2 $line | tail -n 1 | cut -d' ' -f3`
    Description=`head -n 3 $line | tail -n 1 | cut -c3-`
    if [[ $1 = "all" ]]; then
        echo $Name [$Group] - $Description
    fi
    if [[ $1 = $Group ]]; then
        echo $Name - $Description
    fi
#
done </tmp/invis-server.lst
}

# get invis version number
versionnumber=`getconfdata "$conffile" "invisVersion" "2"|cut -d "." -f1`
VER="invisAD-setup-$versionnumber"
PATH='/usr/bin'

if test $# -eq 0; then
  usage
  exit 1
fi

case $1 in
help)  usage;;
all)   printline $1 ;;
server) printline $1;;
portal) printline $1;;
apps) printline $1;;
setup) printline $1;;
esac
