2017-12-01 17:17:25 +00:00
#!/usr/bin/env bash
2018-07-11 16:43:52 +00:00
_localPropertiesPath = ./android/local.properties
2018-09-13 09:44:33 +00:00
function downloadUrl( ) {
if program_exists "aria2c" ; then
aria2c --max-connection-per-server= 16 --split= 16 --dir= " $1 " -o " $2 " " $3 "
else
wget --show-progress --output-document= " $1 / $2 " " $3 "
fi
}
2018-11-05 09:40:11 +00:00
function install_nsis( ) {
# NSIS (Nullsoft Scriptable Install System) is a professional open source system to create Windows installers. It is designed to be as small and flexible as possible and is therefore very suitable for internet distribution.
linux_install nsis
}
2017-12-01 17:17:25 +00:00
function install_node( ) {
2019-01-15 15:34:52 +00:00
if ! nvm_installed && ! program_exists 'node' ; then
install_nvm
fi
2017-12-01 17:17:25 +00:00
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++
2019-01-26 15:36:12 +00:00
lib32ncurses5 # required for Android SDK
lib32stdc++6 # required for Android SDK
2017-12-01 17:17:25 +00:00
libssl-dev
libtool
make
2019-01-26 15:36:12 +00:00
pkg-config # required to e.g. build watchman
2017-12-01 17:17:25 +00:00
python-dev
2019-01-26 15:36:12 +00:00
rlwrap # required to use clj
2017-12-01 17:17:25 +00:00
wget
unzip
)
for package in " ${ buildtools [@] } " ; do
2018-02-07 19:40:24 +00:00
linux_install " $package "
2017-12-01 17:17:25 +00:00
done
fi
}
2018-07-30 19:44:44 +00:00
function install_wget( ) {
if is_macos; then
2019-01-10 18:32:30 +00:00
brew_install wget 1.19.4 0505e48743f82ac2e9f5d0c9d6d811949982262e
2018-07-30 19:44:44 +00:00
fi
2018-08-21 12:35:14 +00:00
# it's installed on ubuntu/debian by default
2018-07-30 19:44:44 +00:00
}
2017-12-01 17:17:25 +00:00
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
2019-01-18 14:09:23 +00:00
brew_install leiningen $( toolversion leiningen) f7e10afc6d04a13d28e825db71326d16c12e9724
2017-12-01 17:17:25 +00:00
elif is_linux; then
install_leiningen_linux
fi
}
function install_leiningen_linux( ) {
local destination = /usr/bin/lein
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion leiningen)
2019-01-10 18:32:30 +00:00
if ! program_version_exists "lein" " $required_version " ; then
2017-12-01 17:17:25 +00:00
cecho "@b@blue[[+ Installing lein...]]"
sudo su << EOF
curl --silent \
https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein \
-o $destination
chmod 755 $destination
2019-01-10 18:32:30 +00:00
cd $HOME && lein downgrade $required_version
2017-12-01 17:17:25 +00:00
EOF
else
already_installed "lein"
fi
}
2018-06-27 14:30:00 +00:00
function install_clojure_cli( ) {
if is_macos; then
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion clojure_cli)
2019-01-10 18:32:30 +00:00
brew_install clojure $required_version 90ea0cb4b194282b5906108dcec522c5a1ed7ce0
2018-06-27 14:30:00 +00:00
elif is_linux; then
install_clojure_cli_linux
fi
}
function install_clojure_cli_linux( ) {
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion clojure_cli)
2019-01-10 18:32:30 +00:00
if ! program_exists "clojure" || ! echo " $( clj -r <<< '(System/exit 0)' ) " | grep -q -o ${ required_version %.* } ; then
2018-06-27 14:30:00 +00:00
cecho "@b@blue[[+ Installing Clojure CLI...]]"
local current_dir = $( pwd )
sudo su << EOF
curl --silent \
2019-01-10 18:32:30 +00:00
https://download.clojure.org/install/linux-install-${ required_version } .sh \
2018-06-27 14:30:00 +00:00
-o /tmp/clojure
chmod +x /tmp/clojure
cd /tmp
./clojure
EOF
cd " $current_dir "
else
already_installed "Clojure CLI"
fi
}
2017-12-01 17:17:25 +00:00
function install_watchman( ) {
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion watchman)
2017-12-01 17:17:25 +00:00
if is_macos; then
2019-01-10 18:32:30 +00:00
brew_install watchman $required_version 1a41406af8db6bbc0c94811cf60043a7436be3c4
2017-12-01 17:17:25 +00:00
elif is_linux; then
2019-01-10 18:32:30 +00:00
if ! program_version_exists "watchman" " $required_version " ; then
2017-12-01 17:17:25 +00:00
local current_dir = $( pwd )
local clone_path = "/tmp/watchman"
2019-01-26 15:36:12 +00:00
rm -rf $clone_path
2017-12-01 17:17:25 +00:00
git clone https://github.com/facebook/watchman.git $clone_path
cd $clone_path
2019-01-10 18:32:30 +00:00
git checkout v$required_version
2017-12-01 17:17:25 +00:00
./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
}
2019-01-26 15:36:12 +00:00
function export_android_sdk_vars( ) {
local profile
local target_path
if is_macos; then
profile = $HOME /.bash_profile
elif is_linux; then
profile = $HOME /.bashrc
fi
[ -f $profile ] || touch $profile
if ! grep -Fq "export ANDROID_SDK_ROOT=" $profile ; then
echo " export ANDROID_HOME=\" $1 \" " >> $profile && \
echo " export ANDROID_SDK_ROOT=\" $1 \" " >> $profile && \
echo " export PATH=\" $1 /tools: $1 /tools/bin:\$PATH\" " >> $profile
fi
export ANDROID_HOME = " $1 " && \
export ANDROID_SDK_ROOT = " $1 " && \
export PATH = " $1 /tools: $1 /tools/bin: $PATH "
}
2017-12-01 17:17:25 +00:00
function install_android_sdk( ) {
if is_macos; then
brew_cask_install android-sdk
2019-01-26 15:36:12 +00:00
[ -z " $ANDROID_SDK_ROOT " ] && export_android_sdk_vars /usr/local/share/android-sdk
2017-12-01 17:17:25 +00:00
elif is_linux; then
install_android_sdk_linux
fi
2018-07-10 15:56:26 +00:00
use_android_sdk
2017-12-01 17:17:25 +00:00
}
function install_android_sdk_linux( ) {
2019-01-26 15:36:12 +00:00
if [ -z " $ANDROID_SDK_ROOT " ] ; then
if grep -Fq "sdk.dir" $_localPropertiesPath ; then
local _sdkParentDir = " $( awk -F'=' "/^sdk.dir=/{print \$2}" " $_localPropertiesPath " ) "
export_android_sdk_vars $_sdkParentDir
cecho "@green[[Android SDK already declared.]]"
else
local required_version = $( toolversion android-sdk)
local _sdkParentDir = $HOME /Android/Sdk
mkdir -p $_sdkParentDir
cecho "@cyan[[Downloading Android SDK.]]"
downloadUrl . sdk-tools-linux.zip https://dl.google.com/android/repository/sdk-tools-linux-${ required_version } .zip && \
cecho " @cyan[[Extracting Android SDK to $_sdkParentDir .]] " && \
unzip -q -o ./sdk-tools-linux.zip -d " $_sdkParentDir " && \
rm -f ./sdk-tools-linux.zip && \
_sdkTargetDir = " $_sdkParentDir " && \
echo " sdk.dir= $_sdkTargetDir " | tee -a $_localPropertiesPath && \
export_android_sdk_vars $_sdkParentDir && \
cecho " @blue[[Android SDK installation completed in $_sdkTargetDir .]] " || \
return 0
fi
else
if ! grep -Fq "sdk.dir" $_localPropertiesPath ; then
echo " sdk.dir= $ANDROID_SDK_ROOT " | tee -a $_localPropertiesPath
fi
cecho "@green[[Android SDK already declared.]]"
fi
2017-12-01 17:17:25 +00:00
return 1
}
function install_maven( ) {
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion maven)
2019-01-10 18:32:30 +00:00
brew_install maven $required_version 4c23c22dc71eadaeb7b25d6e6c10fd53bfc26976
2018-02-07 19:40:24 +00:00
linux_install maven
2017-12-01 17:17:25 +00:00
}
function install_react_native_cli( ) {
cd " $( repo_path) "
2019-01-10 18:32:30 +00:00
local npm_command = 'npm'
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion react_native_cli)
2017-12-01 17:17:25 +00:00
if is_linux && ! nvm_installed; then
# aptitude version of node requires sudo for global install
2019-01-10 18:32:30 +00:00
npm_command = " sudo $npm_command "
2017-12-01 17:17:25 +00:00
fi
2019-01-10 18:32:30 +00:00
if npm list -g "react-native-cli@{required_version}" & >/dev/null; then
already_installed "react-native-cli@{required_version}"
2017-12-01 17:17:25 +00:00
else
2019-01-10 18:32:30 +00:00
$npm_command install -g react-native-cli@${ required_version }
2017-12-01 17:17:25 +00:00
fi
}
2018-11-28 18:02:20 +00:00
function install_yarn( ) {
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion yarn)
2018-11-29 16:28:57 +00:00
if ! program_exists "yarn" ; then
2019-01-10 18:32:30 +00:00
npm install -g yarn@$required_version # Install the required yarn version
2018-11-28 18:02:20 +00:00
else
cecho "+ yarn already installed... skipping."
fi
2018-11-29 16:28:57 +00:00
if program_exists "yarn" ; then
local yarn_version = $( yarn -v)
2019-01-10 18:32:30 +00:00
if [ [ $yarn_version != " $required_version " ] ] ; then
cecho " @b@yellow[[+ yarn version $yarn_version is installed. Downloading yarn version $required_version in the local repo.]] "
yarn policies set-version $required_version
2018-11-29 16:28:57 +00:00
fi
2018-11-28 18:02:20 +00:00
fi
}
2019-01-15 15:34:52 +00:00
function install_nvm( ) {
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion nvm)
2019-01-15 15:34:52 +00:00
if ! program_version_exists 'nvm' " $required_version " ; then
cecho " @b@blue[[+ Installing nvm $required_version ]] "
2019-01-26 15:36:12 +00:00
# Ensure a profile file exists, otherwise NVM will not add its configuration anywhere
# and will therefore be inaccessible
[ -f "~/.bash_profile" ] || touch ~/.bash_profile
2019-01-15 15:34:52 +00:00
sudo apt install -y build-essential libssl-dev
source scripts/3rd-party/nvm/${ required_version } /install.sh
2019-01-26 15:36:12 +00:00
load_nvm_if_available
2019-01-15 15:34:52 +00:00
else
cecho "+ nvm already installed... skipping."
fi
}
2017-12-01 17:17:25 +00:00
function install_node_via_nvm( ) {
local nvmrc = " $( repo_path) /.nvmrc "
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion node)
2017-12-01 17:17:25 +00:00
cd " $( repo_path) "
2019-01-10 18:32:30 +00:00
if [ ! -e " $nvmrc " -o " $( nvm version v"" $required_version "" ) " = "N/A" ] ; then
cecho " @b@blue[[+ Installing Node $required_version ]] "
2017-12-01 17:17:25 +00:00
2019-01-10 18:32:30 +00:00
nvm install $required_version
nvm alias status-im $required_version
2018-06-27 14:30:00 +00:00
echo status-im > " $nvmrc "
2017-12-01 17:17:25 +00:00
2018-06-27 14:30:00 +00:00
nvm use status-im
2018-11-28 18:02:20 +00:00
2017-12-01 17:17:25 +00:00
else
2018-06-27 14:30:00 +00:00
local version_alias = $( cat " $nvmrc " )
2019-01-10 18:32:30 +00:00
if [ " $( nvm version status-im) " != " v $required_version " ] ; then
nvm alias status-im $required_version
fi
2018-06-27 14:30:00 +00:00
nvm use $version_alias
2017-12-01 17:17:25 +00:00
local version = $( node -v)
2018-06-27 14:30:00 +00:00
cecho " + Node already installed ( $version_alias $version via NVM)... skipping. "
2017-12-01 17:17:25 +00:00
fi
}
function install_node_via_package_manager( ) {
2019-01-18 14:09:23 +00:00
local required_version = $( toolversion node)
2019-01-10 18:32:30 +00:00
if ! program_version_exists "node" " v $required_version " ; then
2017-12-01 17:17:25 +00:00
if is_macos; then
2019-01-10 18:32:30 +00:00
brew_install node " $required_version " b801cc6b71e7c09448b4f823e493710665de68eb
2017-12-01 17:17:25 +00:00
elif is_linux; then
2019-01-10 18:32:30 +00:00
curl -sL https://deb.nodesource.com/setup_${ required_version %% \. * } .x | sudo -E bash -
2018-02-07 19:40:24 +00:00
linux_update
2017-12-01 17:17:25 +00:00
2018-02-07 19:40:24 +00:00
linux_install nodejs
2017-12-01 17:17:25 +00:00
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"
2018-06-27 14:30:00 +00:00
local version = $( required_pod_version)
2017-12-01 17:17:25 +00:00
if using_rvm; then
initialize_rvm
gem_command = "gem"
destination = " RVM ( $( rvm current) ) "
fi
if ! program_exists "pod" ; then
2018-06-27 14:30:00 +00:00
$gem_command install cocoapods -v " $version "
2017-12-01 17:17:25 +00:00
elif ! correct_pod_version_is_installed; then
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) "
2019-01-26 15:36:12 +00:00
eval " $@ " || ( cecho " @b@red[[Error running dependency install ' $@ ']] " && exit 1)
2017-12-01 17:17:25 +00:00
echo
echo " + done"
echo
}
2018-07-10 15:56:26 +00:00
function use_android_sdk( ) {
2018-07-30 19:44:44 +00:00
if [ -n " $ANDROID_SDK_ROOT " ] ; then
2018-07-10 15:56:26 +00:00
if ! grep -Fq "sdk.dir" $_localPropertiesPath ; then
2018-07-30 19:44:44 +00:00
echo " sdk.dir= $ANDROID_SDK_ROOT " | tee -a $_localPropertiesPath
2018-07-10 15:56:26 +00:00
fi
2019-01-10 18:32:30 +00:00
2019-01-26 15:36:12 +00:00
local ANDROID_BUILD_TOOLS_VERSION = $( toolversion android-sdk-build-tools)
local ANDROID_PLATFORM_VERSION = $( toolversion android-sdk-platform)
2019-01-10 18:32:30 +00:00
touch ~/.android/repositories.cfg
echo y | sdkmanager "platform-tools" " build-tools; $ANDROID_BUILD_TOOLS_VERSION " " platforms; $ANDROID_PLATFORM_VERSION "
2019-01-26 15:36:12 +00:00
yes | sdkmanager --licenses
2018-07-10 15:56:26 +00:00
else
2019-01-05 12:01:22 +00:00
local _docUrl = "https://status.im/build_status/"
2018-07-30 19:44:44 +00:00
cecho "@yellow[[ANDROID_SDK_ROOT environment variable not defined, please install the Android SDK.]]"
2018-07-10 15:56:26 +00:00
cecho " @yellow[[(see $_docUrl ).]] "
echo
exit 1
fi
2019-01-26 15:36:12 +00:00
scripts/generate-keystore.sh
2018-07-10 15:56:26 +00:00
}
function install_android_ndk( ) {
if grep -Fq "ndk.dir" $_localPropertiesPath ; then
2018-08-29 13:58:57 +00:00
cecho "@green[[Android NDK already declared.]]"
2018-07-10 15:56:26 +00:00
else
2019-01-26 15:36:12 +00:00
local ANDROID_NDK_VERSION = $( toolversion android-ndk)
2018-07-11 16:43:52 +00:00
local _ndkParentDir = ~/Android/Sdk
2018-07-10 15:56:26 +00:00
mkdir -p $_ndkParentDir
cecho "@cyan[[Downloading Android NDK.]]"
2018-09-13 10:30:59 +00:00
2019-01-26 15:36:12 +00:00
local PLATFORM = "linux"
if is_macos; then
2018-09-13 10:30:59 +00:00
PLATFORM = "darwin"
fi
2019-01-10 18:32:30 +00:00
downloadUrl . android-ndk.zip https://dl.google.com/android/repository/android-ndk-$ANDROID_NDK_VERSION -$PLATFORM -x86_64.zip && \
2018-07-10 15:56:26 +00:00
cecho " @cyan[[Extracting Android NDK to $_ndkParentDir .]] " && \
2018-09-13 09:44:33 +00:00
unzip -q -o ./android-ndk.zip -d " $_ndkParentDir " && \
rm -f ./android-ndk.zip && \
2018-11-21 12:14:43 +00:00
_ndkTargetDir = " $_ndkParentDir / $( ls $_ndkParentDir | grep ndk) " && \
2018-07-10 15:56:26 +00:00
echo " ndk.dir= $_ndkTargetDir " | tee -a $_localPropertiesPath && \
cecho " @blue[[Android NDK installation completed in $_ndkTargetDir .]] "
fi
2018-08-30 14:14:17 +00:00
}