-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup
executable file
·289 lines (237 loc) · 5.83 KB
/
setup
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/ksh -e
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
# Copyright 2022 OmniOS Community Edition (OmniOSce) Association.
# Setup utility for creating an OmniOS build environment.
mydir=`dirname "$_"`
ips=https://pkg.omniosce.org
github=https://github.com
role=1
export LC_ALL=C
# Determine the running OmniOS release.
osid=`awk -F= '$1 == "ID" { print $2 }' /etc/os-release`
version=`awk -F= '$1 == "VERSION" { print $2 }' /etc/os-release`
relnum="${version//[a-z]/}"
if [ "$osid" != omnios ]; then
echo "This does not appear to be an OmniOS system."
exit 1
fi
if (( relnum % 2 == 0 )); then
release="r$relnum"
branch="r$relnum"
else
release=bloody
branch=master
fi
ask()
{
typeset a=
echo "$* (y/n) \\c"
while [[ "$a" != [yYnN] ]]; do
read -r a
done
[[ "$a" = [yY] ]]
}
determine_role()
{
role=1
cat << EOM
-- If you intend to contribute to OmniOS development, then additional
-- commands can be enabled to assist with the process.
EOM
ask "--- Enable these additional commands" && role=2
echo
if [ "$role" -eq 2 ]; then
cat << EOM
-- Additionally, if you have write access to the omniosorg organisation at
-- GitHub, then the remote upstream branches can be automatically kept
-- up-to-date. This access is NOT necessary in order to develop since
-- all integrations are via pull requests.
EOM
ask "--- Do you have commit access to github/omniosorg?" \
&& role=3
echo
fi
}
install_pkg()
{
sudo pkg install "$1"
}
check_pkg()
{
typeset pkg="$1"
echo "--- checking that $pkg is installed"
if ! pkg list -q "$pkg"; then
echo
echo "The $pkg package is not installed on this system."
if ask "Install?"; then
echo
install_pkg "$pkg"
else
echo "Aborting setup."
exit 1
fi
fi
}
check_publisher()
{
echo "--- checking that extra.omnios publisher is set"
if ! pkg publisher -H | egrep -s '^extra.omnios '; then
echo
echo "The extra.omnios publisher is not present."
if ask "Add it?"; then
echo
sudo pkg set-publisher \
-g $ips/$release/extra extra.omnios || exit 1
pkg publisher
else
echo "Aborting setup."
exit 1
fi
fi
}
gitclone()
{
typeset repo=$1
typeset user=${2:-$gituser}
echo "--- Cloning $repo from ${github}/$user"
[ -d "$wd/$repo/.git" ] && return
git clone -b "$branch" "${github}/$user/$repo.git" "$wd/$repo"
(
cd "$wd/$repo"
git remote add upstream "${github}/omniosorg/$repo"
if [ "$repo:$branch" = "illumos-omnios:master" ]; then
git remote add upstream_gate \
"${github}/illumos/illumos-gate"
git remote add upstream_joyent \
"${github}/joyent/illumos-joyent"
fi
)
}
install_config()
{
echo "--- Installing configuration file"
cat << EOM > "$HOME/.omni"
github=${github}
gituser=$gituser
release=$release
branch=$branch
wd=$wd
# 1 user, 2 developer, 3 guardian (commit access)
role=$role
EOM
}
install_env()
{
echo "--- Install omnios.env"
if [ "$relnum" -lt 151031 ]; then
template="template-gcc4.env"
elif [ "$relnum" -lt 151041 ]; then
template="template-gcc7.env"
else
template="template-gcc10.env"
fi
sed "
s^__WORKINGTREE__^$wd^
s^__BUILDNUM__^$relnum^
" < "$mydir/etc/$template" > "$wd/omnios.env"
# Translate the GCC root variable back when building old versions
if [ "$relnum" -lt 151027 ]; then
sed -i 's/GNUC_ROOT/GCC_ROOT/g' "$wd/omnios.env"
fi
# Enable the shadow compiler from r151029
if [ "$relnum" -ge 151029 ]; then
sed -i '/CW_NO_SHADOW/d' "$wd/omnios.env"
fi
}
install_site()
{
echo "--- Install site.sh"
cat << EOM >> "$wd/omnios-build/lib/site.sh"
# Settings added by omni setup
PREBUILT_ILLUMOS=$wd/illumos-omnios
PKGSRVR=file://$wd/repo
TMPDIR=$wd/tmp
DTMPDIR=\$TMPDIR
if [ \`id -u\` = '0' ]; then
ROOT_OK=1
export FORCE_UNSAFE_CONFIGURE=1
fi
#SKIP_KAYAK_KERNEL=1
EOM
}
install_hooks()
{
echo "--- Install hooks"
cp "$mydir/etc/prepare-commit-msg"* "$wd/illumos-omnios/.git/hooks/"
chmod 755 "$wd/illumos-omnios/.git/hooks/prepare-commit-msg"
}
echo "This system is running OmniOS $release"
if [ "$1" = "-ssh" ]; then
echo "Using SSH for GitHub access"
shift
fi
wd="$1"
gituser="$2"
[ -z "$gituser" ] && gituser=omniosorg
if [ -z "$wd" ]; then
echo "Syntax: setup [-ssh] <working directory> [git username]"
exit 1
fi
if [[ "$gituser" != "omniosorg" && "$github" != git@* ]]; then
cat << EOM
-- By default, HTTPS will be used to access GitHub.
-- If you have configured SSH keys on GitHub you can use SSH instead.
EOM
if ask "Do you want to use SSH instead?"; then
fi
echo
fi
if [ -d "$wd" ]; then
if [ "`find "$wd" | wc -l`" -ne 1 ]; then
echo "$wd is not empty. Aborting setup."
exit 1
fi
fi
if ! mkdir -p "$wd"; then
echo "Could not create $wd directory."
exit 1
else
echo "--- Using $wd for installation."
fi
[ "$gituser" != omniosorg ] && determine_role
check_publisher
check_pkg developer/illumos-tools
check_pkg developer/omnios-build-tools
check_pkg ooce/omnios-build-tools
gitclone illumos-omnios
gitclone omnios-build
[ $role -gt 1 -a "$branch" = "master" ] && gitclone lx-port-data omniosorg
gitclone kayak
install_config
install_env
install_site
install_hooks
echo
if [[ $mydir = */ooce/* ]]; then
cat << EOM
Setup is complete.
Invoke the utility by typing '/opt/ooce/bin/omni'
or add /opt/ooce/bin to your \$PATH
EOM
elif [ "`id -u`" = 0 ] && ask "Create symlink as /usr/bin/omni?"; then
[ -h /usr/bin/omni ] && rm -f /usr/bin/omni
ln -s "`pwd`/bin/omni" /usr/bin/omni
echo
echo "Invoke the utility by typing 'omni'"
else
echo "Invoke the utility by typing '`pwd`/bin/omni'"
fi