forked from bee-software/shipper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild_bundle.sh
executable file
·39 lines (31 loc) · 935 Bytes
/
build_bundle.sh
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
#!/bin/bash
set -eux
OUTPUT="$1"
dump_header() {
local first_source_line_number=$1
head -n $((first_source_line_number - 1)) ship.sh
}
last_header_line_number() {
local first_source_line_number
first_source_line_number=$(grep -n '^source' ship.sh | cut -f1 -d':' | head -n1)
echo $((first_source_line_number - 1))
}
dump_scripts() {
grep '^source' ship.sh | sed 's#^source \$(dirname \$0)/##g' | while IFS= read -r script; do
echo ""
cat "$script"
echo ""
done
}
first_footer_line_number() {
local last_source_line_number
last_source_line_number=$(grep -n '^source' ship.sh | cut -f1 -d':' | tail -n1)
echo $((last_source_line_number + 1))
}
dump_footer() {
local last_source_line_number=$1
awk "{if(NR>=$((last_source_line_number + 1))) print \$0}" ship.sh
}
dump_header "$(last_header_line_number)" >"$OUTPUT"
dump_scripts >>"$OUTPUT"
dump_footer "$(first_footer_line_number)" >>"$OUTPUT"