Install all dependencies on Linux

This commit is contained in:
David Balatero 2017-12-01 09:17:25 -08:00 committed by Julien Eluard
parent 2256628c97
commit 2bd7652b5c
9 changed files with 345 additions and 166 deletions

View File

@ -5,11 +5,3 @@
./node_modules/.bin/rn-nodeify --install "assert,zlib,buffer,inherits,console,constants,crypto,dns,domain,events,http,https,os,path,process,punycode,querystring,fs,stream,string_decoder,timers,tty,url,util,net,vm" --hack;
npm install --save react@16.0.0-alpha.6;
npm install --save react-native-tcp@3.2.1;
ln -s ../node_modules/react-native-mapbox-gl/ios/Mapbox.framework ios;
# symlink for re-natal
if ! [ -f re-natal ]; then
ln -s ./node_modules/re-natal/index.js re-natal;
else
echo "re-natal exists"
fi

View File

@ -1,105 +0,0 @@
#!/usr/bin/env bash
function install_node() {
if nvm_installed; then
install_node_via_nvm
else
install_node_via_brew
fi
}
function install_react_native_cli() {
cd "$(repo_path)"
if npm list -g | grep -q react-native-cli; then
already_installed "react-native-cli"
else
npm install -g react-native-cli
fi
}
function install_node_via_nvm() {
local nvmrc="$(repo_path)/.nvmrc"
cd "$(repo_path)"
if [ ! -e "$nvmrc" ]; then
cecho "@b@blue[[+ Installing latest stable Node version]]"
nvm install stable
echo stable > "$nvmrc"
nvm use
else
nvm use >/dev/null
local version=$(node -v)
cecho "+ Node already installed ($version via NVM)... skipping."
fi
}
function install_node_via_brew() {
if ! program_exists "node"; then
brew install node
else
cecho "+ Node already installed ($(node -v) via Homebrew)... skipping."
fi
}
function required_pod_version() {
cat "$(repo_path)/ios/Podfile.lock" | grep "COCOAPODS: " | awk '{ print $2 }'
}
function correct_pod_version_is_installed() {
! program_exists "pod" && return 1
[[ "$(required_pod_version)" == "$(pod --version)" ]]
}
function initialize_rvm() {
cd "$(repo_path)"
if [ ! -e "$(repo_path)/.ruby-version" ]; then
rvm use --default > /dev/null
echo "$(rvm current)" > .ruby-version
fi
rvm use . >/dev/null
}
function install_cocoapods() {
local gem_command="sudo gem"
local destination="system Ruby"
if program_exists "rvm"; then
initialize_rvm
gem_command="gem"
destination="RVM ($(rvm current))"
fi
if ! program_exists "pod"; then
$gem_command install cocoapods
elif ! correct_pod_version_is_installed; then
local version=$(required_pod_version)
cecho "@b@blue[[+ Updating to cocoapods $version]]"
$gem_command uninstall cocoapods --ignore-dependencies --silent
$gem_command install cocoapods -v "$version"
else
cecho "+ cocoapods already installed to $destination... skipping."
fi
}
function dependency_setup() {
cecho "@b@blue[[\$ $@]]"
echo
cd "$(repo_path)"
eval "$@"
echo
echo " + done"
echo
}

View File

@ -1,18 +0,0 @@
#!/usr/bin/env bash
OS=$(uname -s)
function is_macos() {
[[ "$OS" =~ Darwin ]]
}
function exit_unless_mac() {
if ! is_macos; then
cecho "@red[[This install script currently supports Mac OS X only. To
manually install, please visit the wiki for more information:]]
@blue[[https://wiki.status.im/Building_Status]]"
echo
fi
}

263
scripts/lib/setup/installers.sh Executable file
View File

@ -0,0 +1,263 @@
#!/usr/bin/env bash
function install_node() {
if nvm_installed; then
install_node_via_nvm
else
install_node_via_package_manager
fi
}
function install_and_setup_package_manager() {
if is_macos; then
install_homebrew_if_needed
brew_tap "caskroom/cask"
elif is_linux; then
# Linux
buildtools=(
autoconf
automake
build-essential
cmake
curl
g++
libssl-dev
libtool
make
python-dev
wget
unzip
)
for package in "${buildtools[@]}"; do
apt_install "$package"
done
fi
}
function needs_java8_linux() {
! program_exists "java" || !(java -version 2>&1 | grep -q "1.8.0")
}
function install_java8() {
if is_macos; then
brew_cask_install "caskroom/versions/java8"
elif is_linux; then
if needs_java8_linux; then
sudo su << EOF
add-apt-repository ppa:webupd8team/java -y
apt update
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections
apt install -y oracle-java8-installer
EOF
else
already_installed "java8"
fi
fi
}
function install_leiningen() {
if is_macos; then
brew_install leiningen
elif is_linux; then
install_leiningen_linux
fi
}
function install_leiningen_linux() {
local destination=/usr/bin/lein
if ! program_exists "lein"; then
cecho "@b@blue[[+ Installing lein...]]"
sudo su << EOF
curl --silent \
https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein \
-o $destination
chmod 755 $destination
cd $HOME && lein upgrade
EOF
else
already_installed "lein"
fi
}
function install_watchman() {
if is_macos; then
brew_install watchman
elif is_linux; then
if ! program_exists "watchman"; then
local current_dir=$(pwd)
local clone_path="/tmp/watchman"
git clone https://github.com/facebook/watchman.git $clone_path
cd $clone_path
git checkout v4.9.0
./autogen.sh && \
./configure && \
make && \
sudo make install
cd "$current_dir"
else
already_installed "watchman"
fi
fi
}
function install_homebrew_if_needed() {
! is_macos && return 1
if test ! $(which brew); then
cecho "@b@blue[[+ Installing homebrew]]"
ruby -e "$(curl -fsSL \
https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
else
already_installed "Homebrew"
fi
}
function install_android_sdk() {
if is_macos; then
brew_cask_install android-sdk
elif is_linux; then
install_android_sdk_linux
fi
}
function install_android_sdk_linux() {
cecho "@b@yellow[[+ Skipping Android SDK setup, not implemented on Linux]]"
return 1
}
function install_maven() {
brew_install maven
apt_install maven
}
function install_react_native_cli() {
cd "$(repo_path)"
local npm_command="npm"
if is_linux && ! nvm_installed; then
# aptitude version of node requires sudo for global install
npm_command="sudo npm"
fi
if npm list -g | grep -q react-native-cli; then
already_installed "react-native-cli"
else
$npm_command install -g react-native-cli
fi
}
function install_node_via_nvm() {
local nvmrc="$(repo_path)/.nvmrc"
cd "$(repo_path)"
if [ ! -e "$nvmrc" ]; then
cecho "@b@blue[[+ Installing latest stable Node version]]"
nvm install stable
echo stable > "$nvmrc"
nvm use
else
nvm use >/dev/null
local version=$(node -v)
cecho "+ Node already installed ($version via NVM)... skipping."
fi
}
function install_node_via_package_manager() {
if ! program_exists "node"; then
if is_macos; then
brew_install node
elif is_linux; then
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
apt_update
apt_install nodejs
fi
else
cecho \
"+ Node already installed ($(node -v) via package manager)... skipping."
fi
}
function required_pod_version() {
cat "$(repo_path)/ios/Podfile.lock" | grep "COCOAPODS: " | awk '{ print $2 }'
}
function correct_pod_version_is_installed() {
! program_exists "pod" && return 1
[[ "$(required_pod_version)" == "$(pod --version)" ]]
}
function using_rvm() {
program_exists "rvm"
}
function initialize_rvm() {
cd "$(repo_path)"
if [ ! -e "$(repo_path)/.ruby-version" ]; then
rvm use --default > /dev/null
echo "$(rvm current)" > .ruby-version
fi
rvm use . >/dev/null
}
function using_cocoapods() {
is_macos
}
function install_cocoapods() {
! using_cocoapods && return 1
local gem_command="sudo gem"
local destination="system Ruby"
if using_rvm; then
initialize_rvm
gem_command="gem"
destination="RVM ($(rvm current))"
fi
if ! program_exists "pod"; then
$gem_command install cocoapods
elif ! correct_pod_version_is_installed; then
local version=$(required_pod_version)
cecho "@b@blue[[+ Updating to cocoapods $version]]"
$gem_command uninstall cocoapods --ignore-dependencies --silent
$gem_command install cocoapods -v "$version"
else
cecho "+ cocoapods already installed to $destination... skipping."
fi
}
function dependency_setup() {
cecho "@b@blue[[\$ $@]]"
echo
cd "$(repo_path)"
eval "$@" || (cecho "@b@red[[Error running dependency install]]" && exit 1)
echo
echo " + done"
echo
}

View File

@ -13,26 +13,11 @@ function program_exists() {
# Homebrew
########
function install_homebrew_if_needed() {
! is_macos && return 0
if test ! $(which brew); then
cecho "@b@blue[[+ Installing homebrew]]"
ruby -e "$(curl -fsSL \
https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
else
already_installed "Homebrew"
fi
}
function brew_install() {
local package=$1
if ! is_macos; then
return 0
return 1
fi
if brew list "$package" > /dev/null 2>&1; then
@ -46,7 +31,7 @@ function brew_cask_install() {
local package=$1
if ! is_macos; then
return 0
return 1
fi
if brew cask list | grep -q "$package"; then
@ -60,7 +45,7 @@ function brew_tap() {
local cask=$1
if ! is_macos; then
return 0
return 1
fi
if ! brew tap | grep -q "$cask"; then
@ -68,6 +53,37 @@ function brew_tap() {
fi
}
###############
# Aptitude
###############
function apt_update() {
! is_linux && return 1
sudo apt update
}
function apt_is_installed() {
! is_linux && return 1
local package=$1
dpkg -s "$package" >/dev/null 2>&1
}
function apt_install() {
! is_linux && return 1
local package=$1
if apt_is_installed "$package"; then
cecho "+ $package already installed... skipping."
else
sudo apt install -y "$package"
fi
}
###############
# RVM
###############

29
scripts/lib/setup/platform.sh Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
OS=$(uname -s)
function is_macos() {
[[ "$OS" =~ Darwin ]]
}
function is_linux() {
[[ "$OS" =~ Linux ]]
}
function is_ubuntu() {
! is_linux && return 1
(lsb_release -a 2>/dev/null | grep -q Ubuntu) && (command -v apt >/dev/null)
}
function exit_unless_os_supported() {
if ! is_macos && ! is_ubuntu; then
cecho "@red[[This install script currently supports Mac OS X and Ubuntu \
via apt. To manually install, please visit the wiki for more information:]]
@blue[[https://wiki.status.im/Building_Status]]"
echo
exit 1
fi
}

View File

@ -1,21 +1,21 @@
#!/usr/bin/env bash
########################################################################
# This install script will setup your development dependencies on OS X.
# Windows/Linux support is welcome!
# This install script will setup your development dependencies on OS X
# or Ubuntu. Ubuntu 16.04 is the only tested version.
#
# Usage: scripts/setup-osx.sh
# Usage: scripts/setup
########################################################################
_current_dir=$(cd "${BASH_SOURCE%/*}" && pwd)
source "$_current_dir/lib/setup-osx/path-support.sh"
source "$_current_dir/lib/setup/path-support.sh"
source_lib "output.sh"
source_lib "packages.sh"
source_lib "platform.sh"
source_lib "installers.sh"
exit_unless_mac
exit_unless_os_supported
load_nvm_if_available
load_rvm_if_available
@ -23,19 +23,14 @@ load_rvm_if_available
####
setup_header "Installing requirements..."
install_homebrew_if_needed
brew_tap "caskroom/cask"
brew_cask_install "caskroom/versions/java8"
brew_install leiningen
install_and_setup_package_manager
install_java8
install_leiningen
install_node
brew_install watchman
install_watchman
install_react_native_cli
brew_cask_install android-sdk
brew_install maven
install_android_sdk
install_maven
install_cocoapods
####
@ -43,12 +38,19 @@ echo && setup_header "Installing dependencies..."
dependency_setup lein deps
dependency_setup npm install
mapbox_path="$(repo_path)/node_modules/react-native-mapbox-gl/ios/Mapbox.framework"
dependency_setup "ln -sf '$mapbox_path' '$(repo_path)/ios'"
dependency_setup \
"ln -sf '$(repo_path)/node_modules/re-natal/index.js' '$(repo_path)/re-natal'"
dependency_setup ./re-natal deps
dependency_setup ./re-natal enable-source-maps
dependency_setup \
"mvn -f modules/react-native-status/ios/RCTStatus dependency:unpack"
dependency_setup "cd ios && pod install && cd .."
using_cocoapods && dependency_setup "cd ios && pod install && cd .."
setup_complete