File: setup

package info (click to toggle)
ruby-shoulda-context 2.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 476 kB
  • sloc: ruby: 1,712; sh: 200; makefile: 4
file content (190 lines) | stat: -rwxr-xr-x 4,194 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env bash

set -euo pipefail

RUBY_VERSION=$(bin/supported_ruby_versions | xargs -n 1 echo | sort -V | tail -n 1)

cd "$(dirname "$(dirname "$0")")"

uname=$(uname)

if [[ $uname == 'Darwin' ]]; then
  platform='mac'
else
  platform='linux'
fi

banner() {
  echo -e "\033[34m== $@ ==\033[0m"
}

success() {
  echo -e "\033[32m$@\033[0m"
}

warning() {
  echo -e "\033[33m$@\033[0m"
}

error() {
  echo -e "\033[31m$@\033[0m"
}

has-executable() {
  type "$1" &>/dev/null
}

is-running() {
  pgrep "$1" >/dev/null
}

install() {
  local apt_package=""
  local rpm_package=""
  local brew_package=""
  local default_package=""
  local package=""

  for arg in "$@"; do
    case $arg in
      apt=*)
        apt_package="$arg"
        ;;
      rpm=*)
        rpm_package="$arg"
        ;;
      brew=*)
        brew_package="$arg"
        ;;
      *)
        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
    package="${yum_package:-$default_package}"

    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
}

check-for-build-tools() {
  if [[ $platform == "linux" ]]; then
    if ! has-executable apt-get; then
      error "You don't seem to have a package manager installed."
      echo "The setup script assumes you're using Debian or a Debian-derived flavor of Linux"
      echo "(i.e. something with Apt). If this is not the case, then we would gladly take a"
      echo "PR fixing this!"
      exit 1
    fi

    # TODO: Check if build-essential is installed on Debian?
  else
    if ! has-executable brew; then
      error "You don't seem to have Homebrew installed."
      echo
      echo "Follow the instructions here to do this:"
      echo
      echo "http://brew.sh"
      exit 1
    fi

    # TODO: Check that OS X Command Line Tools are installed?
  fi
}

install-development-libraries() {
  install apt=ruby-dev rpm=ruby-devel
  install rpm=zlib-devel
}

install-dependencies() {
  if ! has-executable sqlite3; then
    banner 'Installing SQLite 3'
    install sqlite3
    install apt=libsqlite3-dev rpm=sqlite-devel
  fi

  if ! has-executable psql; then
    banner 'Installing PostgreSQL'
    install postgresql
    install apt=libpq-dev rpm=postgresql-devel
  fi

  if ! is-running postgres; then
    banner 'Starting PostgreSQL'
    start postgresql
  fi

  if ! has-executable heroku; then
    banner 'Installing Heroku'
    install heroku/brew/heroku heroku
  fi

  if has-executable rbenv; then
    if ! (rbenv versions | grep $RUBY_VERSION'\>' &>/dev/null); then
      banner "Installing Ruby $RUBY_VERSION with rbenv"
      rbenv install --skip-existing "$RUBY_VERSION"
    fi
  elif has-executable rvm; then
    if ! (rvm ls | grep $RUBY_VERSION'\>' &>/dev/null); then
      banner "Installing Ruby $RUBY_VERSION with rvm"
      error "You don't seem to have Ruby $RUBY_VERSION installed."
      echo
      echo "Use RVM to do so, and then re-run this command."
      echo
    fi
  else
    error "You don't seem to have a Ruby manager installed."
    echo
    echo 'We recommend using rbenv. You can find installation instructions here:'
    echo
    echo 'http://github.com/rbenv/rbenv'
    echo
    echo "When you're done, simply re-run this script!"
    exit 1
  fi

  banner 'Installing Ruby dependencies'
  gem install bundler -v '~> 1.0' --conservative
  bundle check || bundle install
  bundle exec appraisal install

  if ! has-executable node; then
    banner 'Installing Node'

    if [[ $platform == 'linux' ]]; then
      curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -

      install nodejs

      if ! has-executable npm; then
        install npm
      fi
    else
      install nodejs
    fi
  fi
}

check-for-build-tools
install-development-libraries
install-dependencies