1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4cd Documentation/
5
6# Check entries that should be removed
7
8obsolete=""
9for i in $(tail -n +12 00-INDEX |grep -E '^[a-zA-Z0-9]+'); do
10	if [ ! -e $i ]; then
11		obsolete="$obsolete $i"
12	fi
13done
14
15# Check directory entries that should be added
16search=""
17dir=""
18for i in $(find . -maxdepth 1 -type d); do
19	if [ "$i" != "." ]; then
20		new=$(echo $i|perl -ne 's,./(.*),$1/,; print $_')
21		search="$search $new"
22	fi
23done
24
25for i in $search; do
26	if [ "$(grep -P "^$i" 00-INDEX)" == "" ]; then
27		dir="$dir $i"
28	fi
29done
30
31# Check file entries that should be added
32search=""
33file=""
34for i in $(find . -maxdepth 1 -type f); do
35	if [ "$i" != "./.gitignore" ]; then
36		new=$(echo $i|perl -ne 's,./(.*),$1,; print $_')
37		search="$search $new"
38	fi
39done
40
41for i in $search; do
42	if [ "$(grep -P "^$i\$" 00-INDEX)" == "" ]; then
43		file="$file $i"
44	fi
45done
46
47# Output its findings
48
49echo -e "Documentation/00-INDEX check results:\n"
50
51if [ "$obsolete" != "" ]; then
52	echo -e "- Should remove those entries:\n\t$obsolete\n"
53else
54	echo -e "- No obsolete entries\n"
55fi
56
57if [ "$dir" != "" ]; then
58	echo -e "- Should document those directories:\n\t$dir\n"
59else
60	echo -e "- No new directories to add\n"
61fi
62
63if [ "$file" != "" ]; then
64	echo -e "- Should document those files:\n\t$file"
65else
66	echo "- No new files to add"
67fi
68