#!/bin/bash

# COPYRIGHT
#   Copyright (C) 2008 Christophe Jarry <christophe.jarry@ouvaton.org>
#
#
# LICENSE
#   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, see <http://www.gnu.org/licenses/>.
#
#
# USAGE (command-line)
# cd to directory of kernel files you are currently working on.
# $ ./PathToTableFormat.sh/TableFormat.sh > MyOutputFile
#
# Don't copy the script in the directory you're working on, the calculation would include
# the 'TableFormat.sh' file which is not part of the Kernel
#
# You can then copy and paste from the MyOutputFile file to the wiki page. Don't forget to
# delete it after use !
#
# Note:
# [1] If the script is located in the current directory, it will create an entry for it. This 
# should be deleted.
# [2] Before you run this script, be sure to update all the required variables


##### Those variables may require updates #####

LINUX_FOLDER_NAME="linux-ubuntu-modules-2.6.24-2.6.24"	#the complete name of the kernel folder

NAME="NEEDS ADOPTING"		#if adopted by lee797, replace "NEEDS ADOPTING" with [[~lee797]]

DATE="?"			#if today, replace "?" with $(date +"%d %b %y")
				#if adopted earlier than today, replace "?" with, say, 
				#"18 Feb 08"


##### Those variables shouldn't require updates #####

LINUX_VERSION=$(echo $LINUX_FOLDER_NAME | sed -e "s/linux-ubuntu-modules-//" | sed -e "s/[\.\_]/-/g")

ABSOLUTE_PATH=$(pwd)

RELATIVE_PATH=$(echo $ABSOLUTE_PATH | sed -e "s/^.*$LINUX_FOLDER_NAME//" | sed -e "s/\//--/g")
				#Determine the children path of the folder $LINUX_FOLDER_NAME
				#And replace '/' by '--' in this path


##### Error Checking #####

if [[ ! $ABSOLUTE_PATH =~ $LINUX_FOLDER_NAME\($\|/\) ]]; then
    echo "ERROR: Current directory does not seem to be within a $LINUX_FOLDER_NAME kernel tree"
    exit 1
fi

##### Table generation #####

echo "|| border=1"
echo "||!Section||!Owner||!Date adopted (DD MMM YY)||!Total number of files in section (including README's etc.)||!Percentage of section completed||!Percentage of section certified free (updated weekly by section owner- include date (DD MMM YY)||!All suspected non-free software reported (Yes/ No or N/A if none to report)||!Date of summary (DD MMM YY)||"

for DIR_ENTRY in `ls`; do

NB_FILES=$(find $DIR_ENTRY -type f | wc -l)	#count the files present in the current 
						#file or folder DIR_ENTRY recursively

NEW_DIR_ENTRY=$(echo $DIR_ENTRY | sed -e "s/[\.\_]/-/g")	#Replace '.' and '_' by '-' in the name of $DIR_ENTRY

echo "||[[wiki:Main/Linux-ubuntu-modules-"$LINUX_VERSION$RELATIVE_PATH"--"$NEW_DIR_ENTRY"|"$DIR_ENTRY"]]||"$NAME"||"$DATE"||"$NB_FILES"||0%||0%||N/A||"$DATE"||"
done

exit 0
