1 Star 0 Fork 0

Cupnfish/redox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bootstrap.sh 17.36 KB
一键复制 编辑 原始数据 按行查看 历史
colinfruit 提交于 2019-11-10 18:25 . Update fedora build dependencies
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
#! /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 || true)
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 supported 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 Homebrew 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 "coreutils"
install_macports_pkg "findutils"
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"
install_macports_pkg "cmake"
}
###############################################################################
# This function takes care of installing all dependencies using Homebrew
# 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 "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 "coreutils"
install_brew_pkg "findutils"
install_brew_pkg "gcc49" "gcc-4.9"
install_brew_pkg "nasm"
install_brew_pkg "pkg-config"
install_brew_pkg "cmake"
install_brew_cask_pkg "osxfuse"
install_brew_pkg "redox-os/gcc_cross_compilers/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"
packages="cmake fuse git gperf perl-html-parser nasm wget texinfo bison flex"
if [ "$1" == "qemu" ]; then
packages="$packages qemu"
elif [ "$1" == "virtualbox" ]; then
packages="$packages virtualbox"
fi
# Scripts should not cause a system update in order to just install a couple
# of packages. If pacman -S --needed is going to fail, let it fail and the
# user will figure out the issues (without updating if required) and rerun
# the script.
#echo "Updating system..."
#sudo pacman -Syu
echo "Installing packages $packages..."
sudo pacman -S --needed $packages
}
###############################################################################
# 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 \
autoconf \
autopoint \
bison \
build-essential \
cmake \
curl \
file \
flex \
fuse \
genisoimage \
git \
gperf \
libc6-dev-i386 \
libfuse-dev \
libhtml-parser-perl \
libpng-dev \
libtool \
m4 \
nasm \
pkg-config \
syslinux-utils \
texinfo
if [ "$1" == "qemu" ]; then
if [ -z "$(which qemu-system-x86_64)" ]; 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-x86_64)" ]; 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 cmake texinfo gettext-devel bison flex perl-HTML-Parser; 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 SUSE Linux"
if [ -z "$(which git)" ]; then
echo "Installing git..."
zypper install git
fi
if [ "$1" == "qemu" ]; then
if [ -z "$(which qemu-system-x86_64)" ]; 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 fuse-devel cmake
}
##############################################################################
# This function takes care of installing all dependencies for building 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
if [ -z "$(which fusermount)" ]; then
echo "Installing fuse..."
sudo emerge sys-fs/fuse
fi
if [ "$2" == "qemu" ]; then
if [ -z "$(which qemu-system-x86_64)" ]; then
echo "Please install QEMU and re-run this script"
echo "Step1. Add QEMU_SOFTMMU_TARGETS=\"x86_64\" to /etc/portage/make.conf"
echo "Step2. Execute \"sudo emerge app-emulation/qemu\""
else
echo "QEMU already installed!"
fi
fi
if [ -z "$(which cmake)" ]; then
echo "Installing cmake..."
sudo emerge dev-util/cmake
fi
}
##############################################################################
# This function takes care of installing all dependencies for building redox on
# SolusOS
# @params: $1 the emulator to install, virtualbox or qemu
##############################################################################
solus()
{
echo "Detected SolusOS"
if [ "$1" == "qemu" ]; then
if [ -z "$(which qemu-system-x86_64)" ]; 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
echo "Installing necessary build tools..."
#if guards are not necessary with eopkg since it does nothing if latest version is already installed
sudo eopkg it fuse-devel git gcc g++ libgcc-32bit libstdc++-32bit nasm make cmake
}
######################################################################
# 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 -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 recommend 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 recommended) 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 recommended) or run this"
echo "script again, accepting the rustup 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 succeeded!"
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 succeeding or not."
echo "Consider checking for and maybe opening an issue on gitlab"
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 gitlab repo..."
git clone https://gitlab.redox-os.org/redox-os/redox.git --origin upstream --recursive
rustInstall
if [[ "`cargo install --list`" != *"xargo"* ]]; then
cargo install xargo
else
echo "You have xargo installed already!"
fi
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" ] || [ "$1" == "--help" ]; 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
update=false
while getopts ":e:p:udhs" opt
do
case "$opt" in
e) emulator="$OPTARG";;
p) defpackman="$OPTARG";;
d) dependenciesonly=true;;
u) update=true;;
h) usage;;
s) statusCheck && exit;;
\?) echo "I don't know what to do with that option, try -h for help"; exit;;
esac
done
if [ "$update" == "true" ]; then
git pull upstream master
git submodule update --recursive --init
rustup update nightly
exit
fi
banner
if [ "Darwin" == "$(uname -s)" ]; then
osx "$emulator"
else
# Here we will use package managers to determine which operating system the user is using.
# Suse and derivatives
if hash 2>/dev/null zypper; then
suse "$emulator"
# Debian or any derivative of it
elif hash 2>/dev/null apt-get; then
ubuntu "$emulator" "$defpackman"
# Fedora
elif hash 2>/dev/null dnf; then
fedora "$emulator"
# Gentoo
elif hash 2>/dev/null emerge; then
gentoo "$emulator"
# SolusOS
elif hash 2>/dev/null eopkg; then
solus "$emulator"
# Arch linux
elif hash 2>/dev/null pacman; then
archLinux "$emulator"
fi
fi
if [ "$dependenciesonly" = false ]; then
boot
fi
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/Cupnfish/redox.git
git@gitee.com:Cupnfish/redox.git
Cupnfish
redox
redox
master

搜索帮助