forked from cmatthew/Lind-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_includes.sh
More file actions
executable file
·33 lines (28 loc) · 887 Bytes
/
check_includes.sh
File metadata and controls
executable file
·33 lines (28 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# Given a repy file with preprocessor directives, check they are all valid
# get basename and dirname
file_name="${1##*/}"
file_path="${1%%$file_name}"
# handle no directory parts in pathname and strip trailing '/'
if [[ -z "$file_path" ]]; then
file_path="."
else
file_path="${file_path##/}"
fi
# build path set
paths+=("$file_path/")
paths+=("$file_path/fs/")
paths+=("$file_path/net/")
paths+=("$file_path/sys/")
paths+=("$file_path/lind/")
paths+=("$file_path/xmplrpc/")
paths+=("$file_path/librepy/")
# build the list of files to include
mapfile -t files < <(awk '/^include/{print $2}' "$1")
# map includes over path set and abort if not found in any of the paths
for file in "${files[@]}"; do
if [[ -z "$(find "${paths[@]}" -type f -name "$file" 2>/dev/null)" ]]; then
printf 'Error: include %s is missing in %s.\n' "$file" "$file_name" >&2
exit 1
fi
done