Update setup script using latest setup_script_generator
Particularly, the setup script now not only works with asdf but also prefers it over rbenv for installing Ruby. [ci skip]
This commit is contained in:
parent
4b7244ac2d
commit
540e7dfee7
236
bin/setup
236
bin/setup
|
@ -2,37 +2,78 @@
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
RUBY_VERSION=$(script/supported_ruby_versions | xargs -n 1 echo | sort -V | tail -n 1)
|
### PROJECT SETUP ##############################################################
|
||||||
required_ruby_version=$(cat .ruby-version)
|
|
||||||
|
|
||||||
cd "$(dirname "$(dirname "$0")")"
|
# Feel free to add whatever functions or variables you want to add in this
|
||||||
|
# section. You may also delete this section altogether if your project doesn't
|
||||||
|
# need a custom setup.
|
||||||
|
|
||||||
uname=$(uname)
|
USE_BUNDLER_1=1
|
||||||
|
|
||||||
if [[ $uname == 'Darwin' ]]; then
|
### DON'T MODIFY ANYTHING BELOW THIS LINE! #####################################
|
||||||
platform='mac'
|
|
||||||
else
|
# This setup script was generated with setup_script_generator 0.2.3,
|
||||||
platform='linux'
|
# available on RubyGems.
|
||||||
fi
|
#
|
||||||
|
# To regenerate this section, install the gem and run:
|
||||||
|
#
|
||||||
|
# generate-setup -p ruby
|
||||||
|
#
|
||||||
|
|
||||||
|
# --- SETUP --------------------------------------------------------------------
|
||||||
|
|
||||||
|
something_already_printed=0
|
||||||
|
|
||||||
|
determine-platform() {
|
||||||
|
local uname=$(uname)
|
||||||
|
|
||||||
|
if [[ $uname == 'Darwin' ]]; then
|
||||||
|
echo 'mac'
|
||||||
|
else
|
||||||
|
echo 'linux'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
banner() {
|
banner() {
|
||||||
echo -e "\033[34m== $@ ==\033[0m"
|
print-with-color 34 "== $@ =="
|
||||||
}
|
}
|
||||||
|
|
||||||
success() {
|
success() {
|
||||||
echo -e "\033[32m$@\033[0m"
|
print-with-color 32 "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
warning() {
|
warning() {
|
||||||
echo -e "\033[33m$@\033[0m"
|
print-with-color 33 "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
error() {
|
error() {
|
||||||
echo -e "\033[31m$@\033[0m"
|
print-with-color 31 "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
echo-wrapped() {
|
print-with-color() {
|
||||||
echo "$@" | fmt -w 80 | cat
|
pad-from-existing-output
|
||||||
|
echo -ne "\033[${1}m"
|
||||||
|
echo -n "${@:2}"
|
||||||
|
echo -e "\033[0m"
|
||||||
|
something_already_printed=1
|
||||||
|
}
|
||||||
|
|
||||||
|
print-wrapped() {
|
||||||
|
pad-from-existing-output
|
||||||
|
echo -n "$@" | fmt -w 80 | cat
|
||||||
|
something_already_printed=1
|
||||||
|
}
|
||||||
|
|
||||||
|
pad-from-existing-output() {
|
||||||
|
if [[ $something_already_printed -eq 1 ]]; then
|
||||||
|
echo
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
print() {
|
||||||
|
pad-from-existing-output
|
||||||
|
echo "$@"
|
||||||
|
something_already_printed=1
|
||||||
}
|
}
|
||||||
|
|
||||||
has-executable() {
|
has-executable() {
|
||||||
|
@ -99,74 +140,93 @@ install() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check-for-build-tools() {
|
check-for-package-manager() {
|
||||||
if [[ $platform == "linux" ]]; then
|
local platform=$(determine-platform)
|
||||||
if has-executable apt-get; then
|
|
||||||
# TODO: Check if build-essential is installed on Debian?
|
if [[ $platform == "linux" ]] && ! has-executable apt-get && ! has-executable yum; then
|
||||||
true
|
# TODO: Check if build-essential is installed on Debian?
|
||||||
elif has-executable yum; then
|
# TODO: Check if 'Development Tools' group is installed on RedHat?
|
||||||
# TODO: Check if 'Development Tools' group is installed on RedHat?
|
|
||||||
true
|
error "You don't seem to have a package manager installed."
|
||||||
else
|
print-wrapped "\
|
||||||
error "You don't seem to have a package manager installed."
|
This setup script assumes you're using a flavor of Linux derived from Debian or
|
||||||
echo-wrapped "\
|
RedHat (i.e. something with Apt or Yum). If this is not the case, then we would
|
||||||
The setup script assumes you're using Debian, RedHat or a derived flavor of
|
|
||||||
Linux (i.e. something with Apt or Yum). If this is not the case, then we would
|
|
||||||
gladly take a PR fixing this!"
|
gladly take a PR fixing this!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
elif [[ $platform == "mac" ]] && ! has-executable brew; then
|
||||||
else
|
|
||||||
if ! has-executable brew; then
|
|
||||||
error "You don't seem to have Homebrew installed."
|
|
||||||
echo-wrapped "\
|
|
||||||
Follow the instructions here to do this:
|
|
||||||
|
|
||||||
http://brew.sh
|
|
||||||
|
|
||||||
Then re-run this script."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO: Check that OS X Command Line Tools are installed?
|
# TODO: Check that OS X Command Line Tools are installed?
|
||||||
|
|
||||||
|
error "You don't seem to have Homebrew installed."
|
||||||
|
print-wrapped "\
|
||||||
|
Visit <https://brew.sh> and follow the instructions there, then re-run this
|
||||||
|
script."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
install-development-libraries() {
|
install-development-libraries() {
|
||||||
install apt=ruby-dev rpm=ruby-devel
|
|
||||||
install rpm=zlib-devel
|
install rpm=zlib-devel
|
||||||
}
|
}
|
||||||
|
|
||||||
install-dependencies() {
|
setup() {
|
||||||
if ! has-executable sqlite3; then
|
cd "$(dirname "$(dirname "$0")")"
|
||||||
banner 'Installing SQLite 3'
|
check-for-package-manager
|
||||||
install sqlite3
|
install-development-libraries
|
||||||
install apt=libsqlite3-dev rpm=sqlite-devel
|
run-provisions
|
||||||
|
if type provision-project &>/dev/null; then
|
||||||
|
provision-project
|
||||||
|
fi
|
||||||
|
success "Setup complete!"
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- RUBY ---------------------------------------------------------------------
|
||||||
|
|
||||||
|
provision-ruby() {
|
||||||
|
if [[ -f .tool-versions ]]; then
|
||||||
|
REQUIRED_RUBY_VERSION=$(cat .tool-versions | grep '^ruby ' | sed -Ee 's/^ruby (.+)$/\1/')
|
||||||
|
elif [[ -f .ruby-version ]]; then
|
||||||
|
REQUIRED_RUBY_VERSION=$(cat .ruby-version)
|
||||||
|
else
|
||||||
|
error "You don't seem to have a Ruby version set in your project."
|
||||||
|
print-wrapped "\
|
||||||
|
You'll need to create either a .tool-versions file or .ruby-version file in your
|
||||||
|
project before you can run this script."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! has-executable psql; then
|
ensure-ruby-development-libraries-installed
|
||||||
banner 'Installing PostgreSQL'
|
ensure-ruby-installed
|
||||||
install postgresql
|
ensure-project-ruby-dependencies-installed
|
||||||
install apt=libpq-dev rpm=postgresql-devel
|
}
|
||||||
fi
|
|
||||||
|
|
||||||
if ! is-running postgres; then
|
ensure-ruby-development-libraries-installed() {
|
||||||
banner 'Starting PostgreSQL'
|
local platform=$(determine-platform)
|
||||||
start postgresql
|
|
||||||
fi
|
|
||||||
|
|
||||||
if has-executable rbenv; then
|
if [[ $platform == "linux" ]]; then
|
||||||
if ! (rbenv versions | grep $RUBY_VERSION'\>' &>/dev/null); then
|
banner "Installing Ruby development libraries"
|
||||||
banner "Installing Ruby $RUBY_VERSION with rbenv"
|
install apt=ruby-dev rpm=ruby-devel
|
||||||
rbenv install --skip-existing "$RUBY_VERSION"
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure-ruby-installed() {
|
||||||
|
if has-executable asdf; then
|
||||||
|
if ! (asdf current ruby | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
|
||||||
|
banner "Installing Ruby $REQUIRED_RUBY_VERSION with asdf"
|
||||||
|
asdf install ruby $REQUIRED_RUBY_VERSION
|
||||||
|
fi
|
||||||
|
elif has-executable rbenv; then
|
||||||
|
if ! (rbenv versions | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
|
||||||
|
banner "Installing Ruby $REQUIRED_RUBY_VERSION with rbenv"
|
||||||
|
rbenv install --skip-existing "$REQUIRED_RUBY_VERSION"
|
||||||
fi
|
fi
|
||||||
elif has-executable chruby-exec; then
|
elif has-executable chruby-exec; then
|
||||||
PREFIX='' source /usr/local/share/chruby/chruby.sh
|
PREFIX='' source /usr/local/share/chruby/chruby.sh
|
||||||
if ! (chruby '' | grep $RUBY_VERSION'\>' &>/dev/null); then
|
if ! (chruby '' | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
|
||||||
if has-executable install-ruby; then
|
if has-executable install-ruby; then
|
||||||
banner "Installing Ruby $RUBY_VERSION with install-ruby"
|
banner "Installing Ruby $REQUIRED_RUBY_VERSION with install-ruby"
|
||||||
install-ruby "$RUBY_VERSION"
|
install-ruby "$REQUIRED_RUBY_VERSION"
|
||||||
else
|
else
|
||||||
error "Please install Ruby $RUBY_VERSION"
|
error "Please use chruby to install Ruby $REQUIRED_RUBY_VERSION!"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif has-executable rvm; then
|
elif has-executable rvm; then
|
||||||
|
@ -177,24 +237,40 @@ install-dependencies() {
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
error "You don't seem to have a Ruby manager installed."
|
error "You don't seem to have a Ruby manager installed."
|
||||||
echo-wrapped "\
|
print-wrapped "\
|
||||||
We recommend using rbenv. You can find instructions to install it here:
|
We recommend using asdf. You can find instructions to install it here:
|
||||||
|
|
||||||
https://github.com/rbenv/rbenv#installation
|
https://asdf-vm.com
|
||||||
|
|
||||||
Make sure to follow the instructions to configure your shell so that rbenv is
|
When you're done, close and re-open this terminal tab and re-run this script."
|
||||||
automatically loaded.
|
|
||||||
|
|
||||||
When you're done, open up a new terminal tab and re-run this script."
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
banner 'Installing Ruby dependencies'
|
|
||||||
gem install bundler -v '~> 1.0' --conservative
|
|
||||||
bundle check || bundle install
|
|
||||||
bundle exec appraisal install
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check-for-build-tools
|
has-bundler() {
|
||||||
install-development-libraries
|
has-executable bundle && bundle -v &>/dev/null
|
||||||
install-dependencies
|
}
|
||||||
|
|
||||||
|
ensure-project-ruby-dependencies-installed() {
|
||||||
|
banner 'Installing Ruby dependencies'
|
||||||
|
|
||||||
|
if [[ $USE_BUNDLER_1 -eq 1 ]] && (! has-bundler || [[ $(bundle -v) =~ '^1\.' ]]); then
|
||||||
|
gem install bundler -v '~> 1.0'
|
||||||
|
elif ! has-bundler; then
|
||||||
|
gem install bundler
|
||||||
|
fi
|
||||||
|
|
||||||
|
bundle check || bundle install
|
||||||
|
}
|
||||||
|
|
||||||
|
run-provisions() {
|
||||||
|
provision-ruby
|
||||||
|
|
||||||
|
if type provision-project &>/dev/null; then
|
||||||
|
provision-project
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# --- FIN ----------------------------------------------------------------------
|
||||||
|
|
||||||
|
setup
|
||||||
|
|
Loading…
Reference in New Issue