forked from NIEM/NIEM.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun
executable file
·104 lines (94 loc) · 2.96 KB
/
run
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
#HELP:COMMAND_NAME: run supporting utilities for the website
set -o nounset -o errexit -o pipefail
unset CDPATH
root_dir=$(cd "$(dirname "$0")" && pwd)
command_path=$root_dir/$(basename "$0")
command_name=$(basename "$0")
#HELP:Options:
print_help () {
(( $# == 0 )) || fail "function $FUNCNAME must have 0 arguments (got $#)"
sed -e "s/.*#""HELP://p;d" "$command_path" | m4 -P -DCOMMAND_NAME="$command_name"
}
#HELP: --help | -h: Print this help
opt_help () {
(( $# == 0 )) || fail "function $FUNCNAME must have 0 arguments (got $#)"
print_help
exit 0
}
fail () {
printf "%s: Error: %s\n" "$command_name" "$*" >&2
exit 1
}
OPTIND=1
while getopts :h-: option
do case $option in
h ) opt_help;;
- ) case "$OPTARG" in
help ) opt_help;;
help=* ) fail "Long option \"${OPTARG%%=*}\" has unexpected argument";;
* ) fail "Unknown long option \"${OPTARG%%=*}\"";;
esac;;
'?' ) fail "Unknown short option \"$OPTARG\"";;
: ) fail "Short option \"$OPTARG\" missing argument";;
* ) fail_assert "Bad state in getopts (OPTARG=\"$OPTARG\")";;
esac
done
shift $((OPTIND-1))
#HELP:Commands:
if (( $# == 0 ))
then fail no args
else command=$1
shift
fi
case $command in
#HELP: help: Print this help
help )
opt_help
;;
#HELP: serve: Run a local Jekyll server
serve )
cd "$root_dir"
bundle exec jekyll serve --baseurl ''
;;
#HELP: serve: Run a local Jekyll server
serve-incremental )
cd "$root_dir"
bundle exec jekyll serve --incremental --baseurl ''
;;
#HELP: build: Build the Jekyll site to a temporary directory (~/tmp/site)
build )
cd "$root_dir"
rm -rf "$HOME"/tmp/site
bundle exec jekyll build --verbose --destination "$HOME"/tmp/site
;;
#HELP: valid: Identify orphaned hrefs (requires URL argument)
valid )
if (( $# != 1 ))
then printf "valid needs one arg, a URL (got $#)\n"
exit 1
fi
if ! curl --silent --output /dev/null "$@"
then printf 'Nothing running at %s\n' "$@" >&2
exit 1
fi
wget --no-parent --no-directories --no-config --no-verbose --spider --recursive --page-requisites "$@"
;;
#HELP: valid-page $local-path...: Identify orphaned refs on a single page
valid-page )
for path in "$@"
do wget --no-parent --no-directories --span-hosts --no-config --no-verbose --spider --page-requisites "$url/$path"
done
;;
#HELP: remove-trailing-newline $file...: remove trailing newline from file
remove-trailing-newline )
for file in "$@"
do
temp=$(mktemp)
awk '{q=p;p=$0}NR>1{print q}END{ORS = ""; print p}' "$file" > "$temp"
cat "$temp" > "$file"
rm -f "$temp"
done
;;
* ) fail Unknown command: "$command";;
esac