-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
121 lines (92 loc) · 1.85 KB
/
bootstrap.sh
File metadata and controls
121 lines (92 loc) · 1.85 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
# shellcheck shell=bash disable=SC2059
function :printf () {
printf -- "$1" "${@:2}"
}
function :vprintf () {
printf -v "$1" -- "$2" "${@:3}"
}
function :printfln () {
:printf "${1}\n" "${@:2}"
}
function :vprintfln () {
:vprintf "$1" "${2}\n" "${@:3}"
}
function :print () {
:printf '%s' "$@"
}
function :vprint () {
:vprintf "$1" '%s' "${@:2}"
}
function :println () {
:printfln '%s' "$@"
}
function :vprintln () {
:vprintfln "$1" '%s' "${@:2}"
}
function :define () {
IFS=$'\n' read -r -d '' "$1" || true
}
function :definef () {
:define REPLY
:vprintf "$1" "$2" "$REPLY"
}
function :readline () {
IFS= read -r "$1" || [[ "${!1:+"x"}" ]]
}
function :readlinef () {
:readline REPLY || return $?
:vprintf "$1" "$2" "$REPLY"
}
function :replace () {
:println "${1/"$2"/"$3"}"
}
function :replace:all () {
:println "${1//"$2"/"$3"}"
}
function :split () {
local separator="$1" string="$2"
local -i limit="${3:-"0"}"
local -a pieces=("$string")
if [[ "${separator:+"x"}" ]]
then
while [[ ! $limit -gt 0 || ${#pieces[@]} -lt $limit ]] && [[ "${pieces[-1]}" == *"$separator"* ]]
do
local new="${pieces[-1]#*"$separator"}"
pieces[-1]="${pieces[-1]%%"$separator"*}"
pieces+=("$new")
done
else
if ! [[ $limit -le ${#string} && $limit -gt 0 ]]
then limit=${#string}
fi
while [[ ! $limit -gt 0 || ${#pieces[@]} -lt $limit ]]
do
local new="${pieces[-1]:1}"
pieces[-1]="${pieces[-1]:0:1}"
pieces+=("$new")
done
fi
:println "${pieces[@]}"
}
function :join () {
:replace:all "$(:println "${@:2}")" $'\n' "$1"
}
function :in () {
local needle="$1"
shift
while [[ $# -gt 0 ]]
do
if [[ "$1" == "$needle" ]]
then return 0
fi
shift
done
return 1
}
function :log () {
:println "$@" 1>&2
}
function :die () {
:log "$@"
exit 1
}