forked from redox-os/redox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
543 lines (504 loc) · 16.4 KB
/
bootstrap.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
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
#! /bin/bash
##########################################################
# This function is simply a banner to introduce the script
##########################################################
banner()
{
echo "|------------------------------------------|"
echo "|----- Welcome to the redox bootstrap -----|"
echo "|------------------------------------------|"
}
###################################################################################
# This function takes care of installing a dependency via package manager of choice
# for building redox on MacOS.
# @params: $1 package manager
# $2 package name
# $3 binary name (optional)
###################################################################################
install_macos_pkg()
{
PKG_MANAGER=$1
PKG_NAME=$2
BIN_NAME=$3
if [ -z "$BIN_NAME" ]; then
BIN_NAME=$PKG_NAME
fi
BIN_LOCATION=$(which $BIN_NAME)
if [ -z "$BIN_LOCATION" ]; then
echo "$PKG_MANAGER install $PKG_NAME"
$PKG_MANAGER install "$PKG_NAME"
else
echo "$BIN_NAME already exists at $BIN_LOCATION, no need to install $PKG_NAME..."
fi
}
install_macports_pkg()
{
install_macos_pkg "sudo port" "$1" "$2"
}
install_brew_pkg()
{
install_macos_pkg "brew" $@
}
install_brew_cask_pkg()
{
install_macos_pkg "brew cask" $@
}
###############################################################################
# This function checks which of the supported package managers
# is available on the OSX Host.
# If a support package manager is found, it delegates the installing work to
# the relevant function.
# Otherwise this function will exit this script with an error.
###############################################################################
osx()
{
echo "Detected OSX!"
if [ ! -z "$(which brew)" ]; then
osx_homebrew $@
elif [ ! -z "$(which port)" ]; then
osx_macports $@
else
echo "Please install either Hombrew or MacPorts, if you wish to use this script"
echo "Re-run this script once you installed one of those package managers"
echo "Will not install, now exiting..."
exit 1
fi
}
###############################################################################
# This function takes care of installing all dependencies using MacPorts
# for building redox on Mac OSX
# @params: $1 the emulator to install, virtualbox or qemu
###############################################################################
osx_macports()
{
echo "Macports detected! Now updating..."
sudo port -v selfupdate
echo "Installing missing packages..."
install_macports_pkg "git"
if [ "$1" == "qemu" ]; then
install_macports_pkg "qemu" "qemu-system-x86_64"
else
install_macports_pkg "virtualbox"
fi
install_macports_pkg "gcc49" "gcc-4.9"
install_macports_pkg "nasm"
install_macports_pkg "pkgconfig"
install_macports_pkg "osxfuse"
install_macports_pkg "x86_64-elf-gcc"
}
###############################################################################
# This function takes care of installing all dependencies using Hombrew
# for building redox on Mac OSX
# @params: $1 the emulator to install, virtualbox or qemu
###############################################################################
osx_homebrew()
{
echo "Homebrew detected! Now updating..."
brew update
echo "Tapping required taps..."
brew tap homebrew/versions
brew tap glendc/gcc_cross_compilers
echo "Installing missing packages..."
install_brew_pkg "git"
if [ "$1" == "qemu" ]; then
install_brew_pkg "qemu" "qemu-system-x86_64"
else
install_brew_pkg "virtualbox"
fi
install_brew_pkg "gcc49" "gcc-4.9"
install_brew_pkg "nasm"
install_brew_pkg "pkg-config"
install_brew_cask_pkg "osxfuse"
install_brew_pkg "glendc/gcc_cross_compilers/x64-elf-binutils" "x86_64-elf-gcc"
install_brew_pkg "glendc/gcc_cross_compilers/x64-elf-gcc" "x86_64-elf-gcc"
}
###############################################################################
# This function takes care of installing all dependencies for building redox on
# Arch linux
# @params: $1 the emulator to install, virtualbox or qemu
###############################################################################
archLinux()
{
echo "Detected Arch Linux"
echo "Updating system..."
sudo pacman -Syu
if [ -z "$(which nasm)" ]; then
echo "Installing nasm..."
sudo pacman -S nasm
fi
if [ -z "$(which git)" ]; then
echo "Installing git..."
sudo pacman -S git
fi
if [ "$1" == "qemu" ]; then
if [ -z "$(which qemu-system-i386)" ]; then
echo "Installing QEMU..."
sudo pacman -S qemu
else
echo "QEMU already installed!"
fi
fi
echo "Installing fuse..."
sudo pacman -S fuse
}
###############################################################################
# This function takes care of installing all dependencies for building redox on
# debian based linux
# @params: $1 the emulator to install, virtualbox or qemu
# $2 the package manager to use
###############################################################################
ubuntu()
{
echo "Detected Ubuntu/Debian"
echo "Updating system..."
sudo "$2" update
echo "Installing required packages..."
sudo "$2" install build-essential libc6-dev-i386 nasm curl file git libfuse-dev
if [ "$1" == "qemu" ]; then
if [ -z "$(which qemu-system-i386)" ]; then
echo "Installing QEMU..."
sudo "$2" install qemu-system-x86 qemu-kvm
else
echo "QEMU already installed!"
fi
else
if [ -z "$(which virtualbox)" ]; then
echo "Installing Virtualbox..."
sudo "$2" install virtualbox
else
echo "Virtualbox already installed!"
fi
fi
}
###############################################################################
# This function takes care of installing all dependencies for building redox on
# fedora linux
# @params: $1 the emulator to install, virtualbox or qemu
###############################################################################
fedora()
{
echo "Detected Fedora"
if [ -z "$(which git)" ]; then
echo "Installing git..."
sudo dnf install git-all
fi
if [ "$1" == "qemu" ]; then
if [ -z "$(which qemu-system-i386)" ]; then
echo "Installing QEMU..."
sudo dnf install qemu-system-x86 qemu-kvm
else
echo "QEMU already installed!"
fi
else
if [ -z "$(which virtualbox)" ]; then
echo "Installing virtualbox..."
sudo dnf install virtualbox
else
echo "Virtualbox already installed!"
fi
fi
# Use rpm -q <package> to check if it's already installed
PKGS=$(for pkg in gcc gcc-c++ glibc-devel.i686 nasm make fuse-devel; do rpm -q $pkg > /dev/null; [ $? -ne 0 ] && echo $pkg; done)
# If the list of packages is not empty, install missing
COUNT=$(echo $PKGS | wc -w)
if [ $COUNT -ne 0 ]; then
echo "Installing necessary build tools..."
sudo dnf install $PKGS
fi
}
###############################################################################
# This function takes care of installing all dependencies for building redox on
# *suse linux
# @params: $1 the emulator to install, virtualbox or qemu
###############################################################################
suse()
{
echo "Detected a suse"
if [ -z "$(which git)" ]; then
echo "Installing git..."
zypper install git
fi
if [ "$1" == "qemu" ]; then
if [ -z "$(which qemu-system-i386)" ]; then
echo "Installing QEMU..."
sudo zypper install qemu-x86 qemu-kvm
else
echo "QEMU already installed!"
fi
else
if [ -z "$(which virtualbox)" ]; then
echo "Please install Virtualbox and re-run this script,"
echo "or run with -e qemu"
exit
else
echo "Virtualbox already installed!"
fi
fi
echo "Installing necessary build tools..."
sudo zypper install gcc gcc-c++ glibc-devel-32bit nasm make libfuse
}
##############################################################################
# This function takes care of installing all dependencies for builing redox on
# gentoo linux
# @params: $1 the emulator to install, virtualbox or qemu
##############################################################################
gentoo()
{
echo "Detected Gentoo Linux"
if [ -z "$(which nasm)" ]; then
echo "Installing nasm..."
sudo emerge dev-lang/nasm
fi
if [ -z "$(which git)" ]; then
echo "Installing git..."
sudo emerge dev-vcs/git
fi
echo "Installing fuse..."
sudo emerge sys-fs/fuse
if [ "$2" == "qemu" ]; then
if [ -z "$(which qemu-system-i386)" ]; then
echo "Please install QEMU and re-run this script"
echo "Step1. Add QEMU_SOFTMMU_TARGETS=\"i386\" to /etc/portage/make.conf"
echo "Step2. Execute \"sudo emerge app-emulation/qemu\""
else
echo "QEMU already installed!"
fi
fi
}
##############################################################################
# This function takes care of installing all dependencies for builing redox on
# SolusOS
# @params: $1 the emulator to install, virtualbox or qemu
##############################################################################
solus()
{
echo "Detected SolusOS"
if [ -z "$(which nasm)" ]; then
echo "Installing nasm..."
sudo eopkg it nasm
fi
if [ -z "$(which git)" ]; then
echo "Installing git..."
sudo eopkg it git
fi
echo "Installing fuse..."
sudo eopkg it fuse-devel
if [ "$1" == "qemu" ]; then
if [ -z "$(which qemu-system-i386)" ]; then
sudo eopkg it qemu
else
echo "QEMU already installed!"
fi
else
if [ -z "$(which virtualbox)" ]; then
echo "Please install Virtualbox and re-run this script,"
echo "or run with -e qemu"
exit
else
echo "Virtualbox already installed!"
fi
fi
}
######################################################################
# This function outlines the different options available for bootstrap
######################################################################
usage()
{
echo "------------------------"
echo "|Redox bootstrap script|"
echo "------------------------"
echo "Usage: ./bootstrap.sh"
echo "OPTIONS:"
echo
echo " -h,--help Show this prompt"
echo " -u [branch] Update git repo and update rust"
echo " If blank defaults to master"
echo " -s Check the status of the current travis build"
echo " -e [emulator] Install specific emulator, virtualbox or qemu"
echo " -p [package Choose an Ubuntu package manager, apt-fast or"
echo " manager] aptitude"
echo " -d Only install the dependencies, skip boot step"
echo "EXAMPLES:"
echo
echo "./bootstrap.sh -b buddy -e qemu"
exit
}
####################################################################################
# This function takes care of everything associated to rust, and the version manager
# That controls it, it can install rustup and uninstall multirust as well as making
# sure that the correct version of rustc is selected by rustup
####################################################################################
rustInstall() {
# Check to see if multirust is installed, we don't want it messing with rustup
# In the future we can probably remove this but I believe it's good to have for now
if [ -e /usr/local/lib/rustlib/uninstall.sh ] ; then
echo "It appears that multirust is installed on your system."
echo "This tool has been deprecated by the maintainer, and will cause issues."
echo "This script can remove multirust from your system if you wish."
printf "Uninstall multirust (y/N):"
read multirust
if echo "$multirust" | grep -iq "^y" ;then
sudo /usr/local/lib/rustlib/uninstall.sh
else
echo "Please manually uninstall multirust and any other versions of rust, then re-run bootstrap."
exit
fi
else
echo "Old multirust not installed, you are good to go."
fi
# If rustup is not installed we should offer to install it for them
if [ -z "$(which rustup)" ]; then
echo "You do not have rustup installed."
echo "We HIGHLY reccomend using rustup."
echo "Would you like to install it now?"
echo "*WARNING* this involves a 'curl | sh' style command"
printf "(y/N): "
read rustup
if echo "$rustup" | grep -iq "^y" ;then
#install rustup
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly
# You have to add the rustup variables to the $PATH
echo "export PATH=\"\$HOME/.cargo/bin:\$PATH\"" >> ~/.bashrc
# source the variables so that we can execute rustup commands in the current shell
source ~/.cargo/env
rustup default nightly
else
echo "Rustup will not be installed!"
fi
fi
#
if [ -z "$(which rustc)" ]; then
echo "Rust is not installed"
echo "Please either run the script again, accepting rustup install"
echo "or install rustc nightly manually (not reccomended) via:"
echo "\#curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly"
exit
fi
# If the system has rustup installed then update rustc to the latest nightly
if hash 2>/dev/null rustup; then
rustup update nightly
rustup default nightly
fi
# Check to make sure that the default rustc is the nightly
if echo "$(rustc --version)" | grep -viq "nightly" ;then
echo "It appears that you have rust installed, but it"
echo "is not the nightly version, please either install"
echo "the nightly manually (not reccomended) or run this"
echo "script again, accepting the multirust install"
echo
else
echo "Your rust install looks good!"
echo
fi
}
####################################################################
# This function gets the current build status from travis and prints
# a message to the user
####################################################################
statusCheck() {
for i in $(echo "$(curl -sf https://api.travis-ci.org/repositories/redox-os/redox.json)" | tr "," "\n")
do
if echo "$i" | grep -iq "last_build_status" ;then
if echo "$i" | grep -iq "0" ;then
echo
echo "********************************************"
echo "Travis reports that the last build succeded!"
echo "Looks like you are good to go!"
echo "********************************************"
elif echo "$i" | grep -iq "null" ;then
echo
echo "******************************************************************"
echo "The Travis build did not finish, this is an error with its config."
echo "I cannot reliably determine whether the build is succeding or not."
echo "Consider checking for and maybe opening an issue on github"
echo "******************************************************************"
else
echo
echo "**************************************************"
echo "Travis reports that the last build *FAILED* :("
echo "Might want to check out the issues before building"
echo "**************************************************"
fi
fi
done
}
###########################################################################
# This function is the main logic for the bootstrap; it clones the git repo
# then it installs the rust version manager and the latest version of rustc
###########################################################################
boot()
{
echo "Cloning github repo..."
git clone https://github.com/redox-os/redox.git --origin upstream --recursive
rustInstall
echo "Cleaning up..."
rm bootstrap.sh
echo
echo "---------------------------------------"
echo "Well it looks like you are ready to go!"
echo "---------------------------------------"
statusCheck
echo "Run the following commands to build redox:"
echo "cd redox"
echo "make all"
echo "make virtualbox or qemu"
echo
echo " Good luck!"
exit
}
if [ "$1" == "-h" ]; then
usage
elif [ "$1" == "-u" ]; then
git pull upstream master
git submodule update --recursive --init
rustup update nightly
exit
elif [ "$1" == "-s" ]; then
statusCheck
exit
fi
emulator="qemu"
defpackman="apt-get"
dependenciesonly=false
while getopts ":e:p:d" opt
do
case "$opt" in
e) emulator="$OPTARG";;
p) defpackman="$OPTARG";;
d) dependenciesonly=true;;
\?) echo "I don't know what to do with that option, try -h for help"; exit;;
esac
done
banner
if [ "Darwin" == "$(uname -s)" ]; then
osx "$emulator"
else
# Here we will user package managers to determine which operating system the user is using
# Arch linux
if hash 2>/dev/null pacman; then
archLinux "$emulator"
fi
# Debian or any derivative of it
if hash 2>/dev/null apt-get; then
ubuntu "$emulator" "$defpackman"
fi
# Fedora
if hash 2>/dev/null dnf; then
fedora "$emulator"
fi
# Suse and derivatives
if hash 2>/dev/null zypper; then
suse "$emulator"
fi
# Gentoo
if hash 2>/dev/null emerge; then
gentoo "$emulator"
fi
# SolusOS
if hash 2>/dev/null eopkg; then
solus "$emulator"
fi
fi
if [ "$dependenciesonly" = false ]; then
boot
fi