2018-09-16 00:36:22 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
### PROJECT SETUP ##############################################################
|
2018-09-16 00:36:22 -04:00
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
# 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.
|
2018-09-16 00:36:22 -04:00
|
|
|
|
2020-08-23 17:11:20 -04:00
|
|
|
provision-project() {
|
|
|
|
banner "Installing Appraisals"
|
|
|
|
bundle exec appraisal install
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
### DON'T MODIFY ANYTHING BELOW THIS LINE! #####################################
|
|
|
|
|
2020-12-01 20:35:25 -05:00
|
|
|
# This setup script was generated with setup_script_generator 0.3.1,
|
2020-06-14 01:27:00 -04:00
|
|
|
# available on RubyGems.
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
}
|
2018-09-16 00:36:22 -04:00
|
|
|
|
|
|
|
banner() {
|
2020-06-14 01:27:00 -04:00
|
|
|
print-with-color 34 "== $@ =="
|
2018-09-16 00:36:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
success() {
|
2020-06-14 01:27:00 -04:00
|
|
|
print-with-color 32 "$@"
|
2018-09-16 00:36:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
warning() {
|
2020-06-14 01:27:00 -04:00
|
|
|
print-with-color 33 "$@"
|
2018-09-16 00:36:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
error() {
|
2020-06-14 01:27:00 -04:00
|
|
|
print-with-color 31 "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
print-with-color() {
|
|
|
|
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
|
2018-09-16 00:36:22 -04:00
|
|
|
}
|
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
pad-from-existing-output() {
|
|
|
|
if [[ $something_already_printed -eq 1 ]]; then
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
print() {
|
|
|
|
pad-from-existing-output
|
|
|
|
echo "$@"
|
|
|
|
something_already_printed=1
|
2019-05-31 01:47:54 -04:00
|
|
|
}
|
|
|
|
|
2018-09-16 00:36:22 -04:00
|
|
|
has-executable() {
|
|
|
|
type "$1" &>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
is-running() {
|
|
|
|
pgrep "$1" >/dev/null
|
|
|
|
}
|
|
|
|
|
2019-05-31 01:47:54 -04:00
|
|
|
start() {
|
|
|
|
if has-executable brew; then
|
|
|
|
brew services start "$1"
|
|
|
|
else
|
|
|
|
sudo service "${2:-$1}" start
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-09-16 00:36:22 -04:00
|
|
|
install() {
|
|
|
|
local apt_package=""
|
|
|
|
local rpm_package=""
|
|
|
|
local brew_package=""
|
|
|
|
local default_package=""
|
|
|
|
local package=""
|
|
|
|
|
|
|
|
for arg in "$@"; do
|
|
|
|
case $arg in
|
|
|
|
apt=*)
|
2019-06-23 16:12:22 -04:00
|
|
|
apt_package="${arg#apt=}"
|
2018-09-16 00:36:22 -04:00
|
|
|
;;
|
|
|
|
rpm=*)
|
2019-06-23 16:12:22 -04:00
|
|
|
rpm_package="${arg#rpm=}"
|
2018-09-16 00:36:22 -04:00
|
|
|
;;
|
|
|
|
brew=*)
|
2019-06-23 16:12:22 -04:00
|
|
|
brew_package="${arg#brew=}"
|
2018-09-16 00:36:22 -04:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
default_package="$arg"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
if has-executable brew; then
|
|
|
|
package="${brew_package:-$default_package}"
|
|
|
|
|
|
|
|
if [[ -n $package ]]; then
|
|
|
|
brew install "$package"
|
|
|
|
fi
|
|
|
|
elif has-executable apt-get; then
|
|
|
|
package="${apt_package:-$default_package}"
|
|
|
|
|
|
|
|
if [[ -n $package ]]; then
|
|
|
|
sudo apt-get install -y "$package"
|
|
|
|
fi
|
|
|
|
elif has-executable yum; then
|
2020-04-02 15:37:56 -04:00
|
|
|
package="${rpm_package:-$default_package}"
|
2018-09-16 00:36:22 -04:00
|
|
|
|
|
|
|
if [[ -n $package ]]; then
|
|
|
|
sudo yum install -y "$package"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
error "Sorry, I'm not sure how to install $default_package."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
check-for-package-manager() {
|
|
|
|
local platform=$(determine-platform)
|
2019-05-31 01:47:54 -04:00
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
if [[ $platform == "linux" ]] && ! has-executable apt-get && ! has-executable yum; then
|
|
|
|
# TODO: Check if build-essential is installed on Debian?
|
|
|
|
# TODO: Check if 'Development Tools' group is installed on RedHat?
|
2018-09-16 00:36:22 -04:00
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
error "You don't seem to have a package manager installed."
|
|
|
|
print-wrapped "\
|
|
|
|
This setup script assumes you're using a flavor of Linux derived from Debian or
|
|
|
|
RedHat (i.e. something with Apt or Yum). If this is not the case, then we would
|
|
|
|
gladly take a PR fixing this!"
|
|
|
|
exit 1
|
|
|
|
elif [[ $platform == "mac" ]] && ! has-executable brew; then
|
2018-09-16 00:36:22 -04:00
|
|
|
# TODO: Check that OS X Command Line Tools are installed?
|
2020-06-14 01:27:00 -04:00
|
|
|
|
|
|
|
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
|
2018-09-16 00:36:22 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install-development-libraries() {
|
|
|
|
install rpm=zlib-devel
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
setup() {
|
|
|
|
cd "$(dirname "$(dirname "$0")")"
|
|
|
|
check-for-package-manager
|
|
|
|
install-development-libraries
|
|
|
|
run-provisions
|
|
|
|
if type provision-project &>/dev/null; then
|
|
|
|
provision-project
|
2018-09-16 00:36:22 -04:00
|
|
|
fi
|
2020-06-14 01:27:00 -04:00
|
|
|
success "Setup complete!"
|
|
|
|
}
|
|
|
|
|
|
|
|
# --- RUBY ---------------------------------------------------------------------
|
2018-09-16 00:36:22 -04:00
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
provision-ruby() {
|
|
|
|
if [[ -f .tool-versions ]]; then
|
2020-12-01 20:35:25 -05:00
|
|
|
REQUIRED_RUBY_VERSION=$(cat .tool-versions | grep '^ruby ' | head -n 1 | sed -Ee 's/^ruby (.+)$/\1/')
|
2020-06-14 01:27:00 -04:00
|
|
|
elif [[ -f .ruby-version ]]; then
|
2020-12-01 20:35:25 -05:00
|
|
|
REQUIRED_RUBY_VERSION=$(cat .ruby-version | head -n 1 | sed -Ee 's/^ruby-([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+)$/\1/')
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z $REQUIRED_RUBY_VERSION ]]; then
|
|
|
|
error "Could not determine required Ruby version for this project."
|
2020-06-14 01:27:00 -04:00
|
|
|
print-wrapped "\
|
2020-12-01 20:35:25 -05:00
|
|
|
Your project needs to include either a valid .tool-versions file with a 'ruby'
|
|
|
|
line or a valid .ruby-version file."
|
2020-06-14 01:27:00 -04:00
|
|
|
exit 1
|
2018-09-16 00:36:22 -04:00
|
|
|
fi
|
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
ensure-ruby-development-libraries-installed
|
|
|
|
ensure-ruby-installed
|
2020-12-01 20:35:25 -05:00
|
|
|
|
|
|
|
if [[ -f Gemfile ]]; then
|
|
|
|
ensure-project-ruby-dependencies-installed
|
|
|
|
fi
|
2020-06-14 01:27:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ensure-ruby-development-libraries-installed() {
|
|
|
|
local platform=$(determine-platform)
|
|
|
|
|
|
|
|
if [[ $platform == "linux" ]]; then
|
|
|
|
banner "Installing Ruby development libraries"
|
|
|
|
install apt=ruby-dev rpm=ruby-devel
|
2018-09-16 00:36:22 -04:00
|
|
|
fi
|
2020-06-14 01:27:00 -04:00
|
|
|
}
|
2018-09-16 00:36:22 -04:00
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
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"
|
2018-09-16 00:36:22 -04:00
|
|
|
fi
|
2019-06-23 15:53:36 -04:00
|
|
|
elif has-executable chruby-exec; then
|
2022-01-25 11:52:02 -05:00
|
|
|
if [ -f /usr/local/share/chruby/chruby.sh ]; then
|
|
|
|
CHRUBY_SH=/usr/local/share/chruby/chruby.sh
|
|
|
|
elif [ -f /opt/homebrew/share/chruby/chruby.sh ]; then
|
|
|
|
CHRUBY_SH=/opt/homebrew/share/chruby/chruby.sh
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$CHRUBY_SH" ]; then
|
|
|
|
error "chruby-exec detected, but could not find chruby.sh for loading"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
PREFIX='' source $CHRUBY_SH
|
2020-06-14 01:27:00 -04:00
|
|
|
if ! (chruby '' | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
|
2019-06-23 15:53:36 -04:00
|
|
|
if has-executable install-ruby; then
|
2020-06-14 01:27:00 -04:00
|
|
|
banner "Installing Ruby $REQUIRED_RUBY_VERSION with install-ruby"
|
|
|
|
install-ruby "$REQUIRED_RUBY_VERSION"
|
2019-06-23 15:53:36 -04:00
|
|
|
else
|
2020-06-14 01:27:00 -04:00
|
|
|
error "Please use chruby to install Ruby $REQUIRED_RUBY_VERSION!"
|
2019-06-23 15:53:36 -04:00
|
|
|
fi
|
|
|
|
fi
|
2021-03-05 17:30:17 -05:00
|
|
|
elif has-executable rvm; then
|
|
|
|
if ! (rvm list | grep $REQUIRED_RUBY_VERSION'\>' &>/dev/null); then
|
|
|
|
banner "Installing Ruby $REQUIRED_RUBY_VERSION with rvm"
|
|
|
|
rvm install $REQUIRED_RUBY_VERSION
|
|
|
|
fi
|
2018-09-16 00:36:22 -04:00
|
|
|
else
|
|
|
|
error "You don't seem to have a Ruby manager installed."
|
2020-06-14 01:27:00 -04:00
|
|
|
print-wrapped "\
|
|
|
|
We recommend using asdf. You can find instructions to install it here:
|
2019-05-31 01:47:54 -04:00
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
https://asdf-vm.com
|
2019-05-31 01:47:54 -04:00
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
When you're done, close and re-open this terminal tab and re-run this script."
|
2018-09-16 00:36:22 -04:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-06-14 01:27:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
has-bundler() {
|
|
|
|
has-executable bundle && bundle -v &>/dev/null
|
|
|
|
}
|
2018-09-16 00:36:22 -04:00
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
ensure-project-ruby-dependencies-installed() {
|
2018-09-16 00:36:22 -04:00
|
|
|
banner 'Installing Ruby dependencies'
|
2020-06-14 01:27:00 -04:00
|
|
|
|
2021-10-11 17:08:00 -04:00
|
|
|
gem install bundler
|
2020-06-14 01:27:00 -04:00
|
|
|
|
2018-09-16 00:36:22 -04:00
|
|
|
bundle check || bundle install
|
|
|
|
}
|
|
|
|
|
2020-06-14 01:27:00 -04:00
|
|
|
run-provisions() {
|
|
|
|
provision-ruby
|
|
|
|
}
|
|
|
|
|
|
|
|
# --- FIN ----------------------------------------------------------------------
|
|
|
|
|
|
|
|
setup
|