#!/bin/bash
########################################################################
# MuGLIn - MuGLIn GNU/Linux Installation		                       #
#                                                                      #
# Copyright (C) 2010 Jakob Gurnhofer <jakob.gurnhofer@gmail.com>       #
# Copyricht (C) 2010 Srdjan Markovic <smark2ki@htl.moedling.at>        #
#                                                                      #
# This file is part of MuGLIn source code.                             #
#                                                                      #
# MuGLIn 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.                                  #
#                                                                      #
# MuGLIn 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 MuGLIn. If not, see <http://www.gnu.org/licenses/>.       #
########################################################################


if [ "$1" = "-show" ]; then
	 file=$2;
  if [ "$3" = "-php" ]; then
	  PHP=1
  fi
elif [ "$0" = "show_iif" ]; then
	echo "Missing -show option. Aborting!"
	exit -1
fi
INAME=`grep Name $file | cut -d"=" -f2`
ICREATOR=`grep Creator $file | cut -d"=" -f2`
ISIZE=`grep Size $file | cut -d"=" -f2`
ICOMMENT=`grep Comment $file | cut -d"=" -f2`
IARCH=`grep Arch $file | cut -d"=" -f2`
ITYPE=`grep Type $file | cut -d"=" -f2`

begin=`grep -n "\[Description]" $file | cut -d":" -f1`
end=`grep -n "\[EndDescription]" $file | cut -d":" -f1`
IDESC=`cat $file | head -n $(($end-1)) | tail -n $(($end-$begin-1))`

begin=`grep -n "\[ChangeLog]" $file | cut -d":" -f1`
end=`grep -n "\[EndChangeLog]" $file | cut -d":" -f1`
ICHLOG=`cat $file | head -n $(($end-1)) | tail -n $(($end-$begin-1))`

echo "Name: 		$INAME"
echo "Creatad by:	$ICREATOR"
echo "Size:		$ISIZE"
echo "Comment:		$ICOMMENT"
echo "Architecture:	$IARCH"
echo "Type:		$ITYPE"

if [ "$PHP" = "" ];then
	echo "Show description? (y/N)"
	input=N
	read input
else
	input=y
	echo ""
	echo "Description"
fi
if [ "$input" = "y" ]; then printf "$IDESC\n"; fi

if [ "$PHP" = "" ];then
	echo "Show change log? (y/N)"
	input=N
	read input
else
	input=y
	echo ""
	echo "Changelog:"
fi
if [ "$input" = "y" ]; then printf "$ICHLOG\n";fi
input="";
