forked from hackademix/nscl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinclude.sh
More file actions
executable file
·58 lines (50 loc) · 1.61 KB
/
include.sh
File metadata and controls
executable file
·58 lines (50 loc) · 1.61 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Copyright (C) 2021 Giorgio Maone <https://maone.net>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# This script includes in the $TARGET/nscl directory
# any nscl JS file referenced by $TARGET/manifest.json
# or any *.js file found under $TARGET, plus those
# referenced by the nscl files included in the first pass
TARGET="$1"
if [[ -z "$TARGET" ]];then
echo 1>&2 "Target directory not specified!"
exit 1
fi
TARGET="$(realpath "$TARGET")"
BASE="$(dirname "$0")"
SRC="$(realpath "$(dirname "$BASE")")"
if ! [[ -d "$TARGET" ]]; then
echo 1>&2 "Target directory '$TARGET' not found!"
exit 1
fi
[[ -d "$TARGET/nscl" ]] && rm -rf "$TARGET"/nscl/**
filter_inclusions() {
echo "Processing inclusions referenced by $@..."
pushd >/dev/null 2>&1 "$1"
shift
shopt -s globstar nullglob
for f in $(grep -E 'nscl/[0-9a-zA-Z_/-]+\.js' **/*.{js,html} "$@" | \
tr "'\"" "\n" | \
sed -re 's/.*(nscl\/[0-9a-zA-Z_\/-]+\.js).*/\1/' | \
grep -E '^nscl/[0-9a-zA-Z_/-]+\.js' | sort | uniq); do
if ! [[ -f "$TARGET/$f" ]]; then
nscl_curdir="$TARGET/$(dirname "$f")"
mkdir -p "$nscl_curdir"
cp -p "$SRC/$f" "$nscl_curdir"
echo "Including $f. in $nscl_curdir"
else
echo >&2 "$TARGET/$f exists!"
fi
done
popd >/dev/null 2>&1
}
filter_inclusions "$TARGET" manifest.json
# include also references from nscl scripts already included
[[ -d "$TARGET/nscl" ]] && filter_inclusions "$TARGET/nscl/"
# auto-update TLDs if included
TLDJS="$TARGET/nscl/common/tld.js"
if [[ -f "$TLDJS" ]] && node "$BASE/TLD/update.js" "$TLDJS"; then
echo "Updated TLDs"
fi
exit 0