-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotp.update.installs
executable file
·199 lines (184 loc) · 5.84 KB
/
otp.update.installs
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash -e
# ========================================================================
# Copyright (c) 2015-2019 T. R. Burghart
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# ========================================================================
readonly rdir="$(pwd)"
readonly sdir="$(cd "$(dirname "$0")" && pwd)"
readonly sname="${0##*/}"
readonly spath="$sdir/$sname"
declare -r otp_source_repo='https://github.com/erlang/otp.git'
declare -r otp_dest_repos="${OTP_UPDATE_REPOS}"
declare -i otp_vsn_min="${OTP_UPDATE_MIN_VSN}"
usage_exit()
{
echo 'Usage:' "$sname" '[options]' >&2
echo 'Options:' >&2
# keep options in sync with 'otp.replace.as'
echo ' -h{0|1|2} 0=without HiPE, 1=with HiPE, 2=both, default auto' >&2
echo ' -d{0|1} 0=force docs off, 1=force docs on, default auto' >&2
echo ' -p{0|1} 0=force PLT off, 1=force PLT on, default auto' >&2
exit 1
}
declare -a replace_flags
for opt in "$@"
do
case "$opt" in
-d[01])
replace_flags[0]="$opt" ;;
-h[012])
replace_flags[1]="$opt" ;;
-p[01])
replace_flags[2]="$opt" ;;
*) echo "$sname: error: illegal option '$opt'" >&2
usage_exit ;;
esac
done
readonly replace_flags
[[ -n "$GIT" && -f "$GIT" && -x "$GIT" ]] || GIT="$(type -P git)"
if [[ -z "$GIT" ]]
then
echo "$sname: error: git executable not found." >&2
exit 1
fi
export GIT
if [[ -n "$network_restrict" ]]
then
ipcfg='/usr/sbin/ipconfig'
if_match=false
for tmp in $network_restrict
do
case "$tmp" in
*:*)
if_name="${tmp%%:*}"
if_patt="${tmp#*:}"
if [[ "$("$ipcfg" getifaddr "$if_name")" == $if_patt ]]
then
if_match=true
break
fi
;;
*)
if [[ -z "$if_list" ]]
then
if_cnt="$("$ipcfg" ifcount)"
if_cur=0
while [[ $if_cur -lt $if_cnt ]]
do
if_list+=" $("$ipcfg" getifaddr en$if_cur || true) "
let 'if_cur += 1'
done
fi
if [[ "$if_list" == *" $tmp "* ]]
then
if_match=true
break
fi
;;
esac
done
if ! $if_match
then
echo "$sname: skipping, not on a suitable network." >&2
exit 0
fi
unset ipcfg if_match if_name if_patt if_cnt if_cur if_list
fi
. "$LOCAL_ENV_DIR/os.type" || exit $?
. "$LOCAL_ENV_DIR/otp.install.base" || exit $?
readonly work="$(mktemp -d /tmp/otp.XXXXXXX)"
trap "/bin/rm -rf $work" EXIT
typeset -i vsn
typeset ext log otp ref rel tmp
typeset branch='master'
echo "==> $GIT clone --quiet '$otp_source_repo' '$work'"
$GIT clone --quiet "$otp_source_repo" "$work"
cd "$work"
ref="$($GIT branch --list | sed -En \
's/^[[:space:]]*\*[[:space:]]+([^[:space:]]+)[[:space:]]*$/\1/p')"
if [[ "$ref" != "$branch" && -n "$otp_dest_repos" ]]
then
for tmp in $otp_dest_repos
do
echo "==> $GIT push --quiet '$tmp' '$ref'"
$GIT push --quiet "$tmp" "$ref"
done
fi
# if not initialized, set otp_vsn_min to capture last 3 GAs
if [[ -z "$otp_vsn_min" || $otp_vsn_min -eq 0 ]]
then
tmp="$(<OTP_VERSION)"
vsn="${tmp%%.*}"
let 'otp_vsn_min = (vsn - 3)'
fi
readonly otp_vsn_min
# work down from the version in $branch to $otp_vsn_min
while true
do
echo "==> $GIT checkout --force --quiet '$branch'"
$GIT checkout --force --quiet "$branch"
tmp="$(<OTP_VERSION)"
vsn="${tmp%%.*}"
rel="${tmp##*-}"
case "$rel" in
"$tmp")
rel=ga
;;
rc[0-9]*|RC[0-9]*)
rel='rc'
;;
*)
;;
esac
otp="otp-$vsn-$rel"
ext="$os_type.$otp.txt"
log="$otp_install_base/$otp/build.$ext"
if [[ -f "$log" && "$(head "$log" | sed -En \
's/^commit:[[:space:]]*([^[:space:]]+)[[:space:]]*$/\1/p')" \
== "$($GIT show-ref --heads --hash "refs/heads/$branch")" ]]
then
echo "Skipping '$otp_install_base/$otp' - up to date"
else
if [[ -n "$otp_dest_repos" ]]
then
for tmp in $otp_dest_repos
do
echo "==> $GIT push --quiet '$tmp' '$branch'"
$GIT push --quiet "$tmp" "$branch"
done
fi
cd "$rdir"
echo '==>' "$sdir/otp.apply.patches" "$work"
if "$sdir/otp.apply.patches" "$work"
then
echo '==>' "$sdir/otp.replace.as" "${replace_flags[@]}" "$work" "$otp"
if "$sdir/otp.replace.as" "${replace_flags[@]}" "$work" "$otp"
then
/bin/rm -rf /tmp/*."$ext"
elif /bin/mv $work/*.$ext /tmp 2>/dev/null
then
echo "!!! error log(s) saved as /tmp/*.$ext"
fi
fi
cd "$work"
fi
[[ $vsn -gt $otp_vsn_min ]] || break
if [[ "$branch" == "maint-$vsn" ]] \
|| ! $GIT checkout --force --quiet "maint-$vsn" 2>/dev/null
then
let 'vsn -= 1'
fi
branch="maint-$vsn"
done
cd "$rdir"