forked from ayehandsum/ayehandsum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalize-ayehandsum.sh
More file actions
executable file
·130 lines (91 loc) · 3.16 KB
/
Copy pathnormalize-ayehandsum.sh
File metadata and controls
executable file
·130 lines (91 loc) · 3.16 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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
set -euo pipefail
ROOT="${1:-.}"
echo "Normalizing repository under: $ROOT"
find "$ROOT" -type f \( -name "*.sh" -o -name "*.manifest" -o -name "*.bash" \) | while read -r f
do
echo "Processing $f"
perl -0777 -i -pe '
# ----------------------------------------------------------
# Remove duplicated AYESEC statutory header blocks
# ----------------------------------------------------------
s/
\#\s*AYESEC:POST_SHS.*?
\#\s*AYESEC:STATUTORY_HEADER.*?
\#\s*AYESEC:STATUTORY_HEADER_COMPLETED.*?
\#\s*AYESEC:PREV_SHS.*?\n+
//gsx;
# ----------------------------------------------------------
# Rename source -> source
# ----------------------------------------------------------
s/\bayevdi_sourcefrom\b/ayevdi_source/g;
s/\bsourcefrom\b/source/g;
# ----------------------------------------------------------
# Remove remote bootstrap commands
# ----------------------------------------------------------
s/^.*\bgh\s+repo\s+clone\b.*\n//mg;
s/^.*\bgit\s+clone\b.*\n//mg;
s/^.*\bgit\s+pull\b.*\n//mg;
s/^.*\bwget\b.*\n//mg;
s/^.*\bcurl\b.*\n//mg;
# ----------------------------------------------------------
# Remove GitHub raw URLs
# ----------------------------------------------------------
s#https://raw\.githubusercontent\.com/[^\s"]+##g;
s#https://github\.com/[^\s"]+##g;
# ----------------------------------------------------------
# Collapse blank lines
# ----------------------------------------------------------
s/\n{3,}/\n\n/gs;
' "$f"
done
###############################################################################
# Seed standard repository files
###############################################################################
create_if_missing()
{
local file="$1"
if [ ! -f "$ROOT/$file" ]
then
echo "Creating $file"
cat >"$ROOT/$file"
fi
}
create_if_missing LICENSE <<'LICENSE'
Copyright (c) Abhishek Choudhary
See CONTRACT.md for usage conditions.
LICENSE
create_if_missing NOTICE <<'NOTICE'
This repository is self-contained.
No network access is required after cloning.
NOTICE
create_if_missing CONTRACT.md <<'CONTRACT'
# CONTRACT
This repository follows the one-shot execution model.
All dependencies are expected to exist locally.
Scripts shall not download external resources during execution.
Remote repositories are distribution mechanisms only.
CONTRACT
create_if_missing CONTEXT.md <<'CONTEXT'
# CONTEXT
This repository is intended to be executable immediately after cloning.
Design principles
- one-shot
- deterministic
- offline
- reproducible
- self-contained
CONTEXT
create_if_missing CHANGELOG.md <<'CHANGELOG'
# Changelog
CHANGELOG
create_if_missing CONTRIBUTING.md <<'CONTRIBUTING'
# Contributing
Please keep the repository self-contained.
Do not introduce network dependencies.
CONTRIBUTING
echo
echo "=========================================="
echo "Normalization complete."
echo "=========================================="
SELF="$(readlink -f "$0")"